using System.Data.Entity;

namespace Rainbow.Data
{
    public class UnitOfWork : IUnitOfWork
    {
        public void Dispose()
        {
            _context.SaveChanges();
        }

        public void SaveChanges()
        {
            _context.SaveChanges();
        }

        public ICustomersRepository Customers
        {
            get { return _customers ?? (_customers = new CustomersRepository(_context)); }
        }

        public IDomainsRepository Domains
        {
            get { return _domains ?? (_domains = new DomainsRepository(_context)); }
        }

        public IRegistrarsRepository Registrars
        {
            get { return _registrars ?? (_registrars = new RegistrarsRepository(_context)); }
        }

        public IServersRepository Servers
        {
            get { return _servers ?? (_servers = new ServersRepository(_context)); }
        }

        public IProjectsRepository Projects
        {
            get { return _projects ?? (_projects = new ProjectsRepository(_context)); }
        }

        public ITimeSheetEntriesRepository TimeSheetEntries
        {
            get { return _timeSheetEntries ?? (_timeSheetEntries = new TimeSheetEntriesRepository(_context)); }
        }

        public ITicketsRepository Tickets
        {
            get { return _tickets ?? (_tickets = new TicketsRepository(_context)); }
        }

        public ITicketResponsesRepository TicketResponses
        {
            get { return _ticketResponses ?? (_ticketResponses = new TicketResponsesRepository(_context)); }
        }

        public IDbSet<Models.ApplicationUser> Users
        {
            get { return _context.Users; }
        }

        private readonly RainbowContext _context = new RainbowContext();
        private ICustomersRepository _customers;
        private IDomainsRepository _domains;
        private IRegistrarsRepository _registrars;
        private IServersRepository _servers;
        private IProjectsRepository _projects;
        private ITimeSheetEntriesRepository _timeSheetEntries;
        private ITicketsRepository _tickets;
        private ITicketResponsesRepository _ticketResponses;
    }
}
