Exemplo n.º 1
0
 public async Task <Customer> UpdateAsync(Customer updatedCustomer)
 {
     using (WaterContext waterContext = new WaterContext())
     {
         waterContext.Entry(updatedCustomer).State = EntityState.Modified;
         await waterContext.SaveChangesAsync();
     }
     return(updatedCustomer);
 }
Exemplo n.º 2
0
        public async Task DeleteAsync(int id)
        {
            using (WaterContext waterContext = new WaterContext())
            {
                var removableCustomer = await waterContext.Customers.FindAsync(id);

                waterContext.Entry(removableCustomer).State = EntityState.Deleted;
                await waterContext.SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        public async Task <Customer> AddAsync(Customer addedCustomer)
        {
            Customer newCustomer = null;

            using (WaterContext waterContext = new WaterContext()) // Вопрос: можем ли мы не использовать using? он нужен для безопасного выхода из подключения?
            {
                newCustomer = waterContext.Customers.Add(addedCustomer);
                await waterContext.SaveChangesAsync();
            }
            return(newCustomer);
        }
Exemplo n.º 4
0
        public async Task UpsertUserWater(UserWaterEntity entity, DateTime date)
        {
            var userWater =
                await waterContext.UserWater.FirstOrDefaultAsync(e =>
                                                                 e.UserId == entity.UserId && e.Created.Date == date.Date);

            if (userWater == null)
            {
                entity.Created = date;
                entity.Updated = null;
                waterContext.UserWater.Add(entity);
            }
            else
            {
                userWater.Updated = date;
                userWater.Amount  = entity.Amount;
            }

            await waterContext.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task <Water> AddAsync(Water addedWater)
        {
            Water newWater = null;

            using (WaterContext waterContext = new WaterContext())
            {
                newWater = waterContext.Waters.Add(addedWater);
                await waterContext.SaveChangesAsync();
            }
            return(newWater);
        }
Exemplo n.º 6
0
        public async Task <Customer> GetAsync(int id)
        {
            Customer someCustomer = null;

            using (WaterContext waterContext = new WaterContext())
            {
                someCustomer = await waterContext.Customers.FindAsync(id);

                // someCustomer = await waterContext.Customers.FirstOrDefaultAsync(f=>f.Id == id) ???
                await waterContext.SaveChangesAsync();
            }
            return(someCustomer);
        }
Exemplo n.º 7
0
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }