// Copyright (c) 2018 Nikolay Zahariev <zahasoft.com>. Licensed under the MIT License.

namespace Zahasoft.Feedex.Endpoint.Controllers
{
    using Context;
    using Factories;
    using System.Web.Http;

    public abstract class BaseController : ApiController
    {
        protected readonly FeedexContext db = new FeedexContext();

        protected void SaveError(string error, string username = "")
        {
            db.Errors.Add(ErrorFactory.ConstructError(error, username));
            db.SaveChanges();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && db != null)
            {
                db.Dispose();
            }

            base.Dispose(disposing);
        }
    }
}
