public async Task <Category> Get(int id)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            Category entity = await context.Categories.FirstOrDefaultAsync((e) => e.Id == id);

            return(entity);
        }
Exemple #2
0
        public async Task <Booking> Get(Category category)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            Booking entity = await context.Bookings.FirstOrDefaultAsync((c) => c.Category == category);

            return(entity);
        }
Exemple #3
0
        public async Task <Booking> Get(int id)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            Booking entity = await context.Bookings.FirstOrDefaultAsync((e) => e.Id == id);

            return(entity);
        }
        public async Task <Category> Get(string description)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            Category entity = await context.Categories.FirstOrDefaultAsync((e) => e.Name == description);

            return(entity);
        }
        public async Task <T> Get(int id)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id);

            return(entity);
        }
Exemple #6
0
 public ProductsController(
     HouseholdDbContext dataBase,
     IMapper mapper,
     ProductsImportHandler importHandler) : base(dataBase)
 {
     this.dataBase      = dataBase;
     this.mapper        = mapper;
     this.importHandler = importHandler;
 }
Exemple #7
0
        public async Task <T> Create(T entity)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity);

            await context.SaveChangesAsync();

            return(createdResult.Entity);
        }
Exemple #8
0
        public async Task <T> Update(int id, T entity)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            entity.Id = id;

            context.Set <T>().Update(entity);
            await context.SaveChangesAsync();

            return(entity);
        }
Exemple #9
0
        public async Task <T> Delete(int id)
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.Id == id);

            EntityEntry <T> deletedResult = context.Set <T>().Remove(entity);
            await context.SaveChangesAsync();

            return(deletedResult.Entity);
        }
Exemple #10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _host.Start();

            HouseholdDbContextFactory contextFactory = _host.Services.GetRequiredService <HouseholdDbContextFactory>();

            using (HouseholdDbContext context = contextFactory.CreateDbContext())
            {
                context.Database.Migrate();
            }

            Window window = _host.Services.GetRequiredService <MainWindow>();

            window.Show();

            base.OnStartup(e);
        }
        public async Task <List <T> > GetAll()
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            return(await context.Set <T>().ToListAsync());
        }
Exemple #12
0
 public UserRoleController(HouseholdDbContext dataBase) : base(dataBase)
 {
 }
Exemple #13
0
 public MenusController(HouseholdDbContext dataBase, IMapper mapper) : base(dataBase)
 {
     this.dataBase = dataBase;
     this.mapper   = mapper;
 }
        public async Task <List <Category> > GetAll()
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            return(await context.Categories.ToListAsync());
        }
Exemple #15
0
        public async Task <List <Booking> > GetAll()
        {
            using HouseholdDbContext context = contextFactory.CreateDbContext();

            return(await context.Bookings.Include(c => c.Category).Include(b => b.BankAccount).ToListAsync());
        }
Exemple #16
0
 protected HouseholdControllerBase(HouseholdDbContext dataBase)
 {
     this.dataBase = dataBase;
 }
Exemple #17
0
 public async Task <List <Booking> > GetAll(int month, int year)
 {
     using HouseholdDbContext context = contextFactory.CreateDbContext();
     return(await context.Bookings.Where(x => x.Date.Year == year && x.Date.Month == month).Include(c => c.Category).Include(b => b.BankAccount).ToListAsync());
 }