예제 #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);
 }
예제 #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();
            }
        }
예제 #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);
        }
예제 #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();
        }
예제 #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);
        }
예제 #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);
        }
예제 #7
0
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }