public async Task <Customer> UpdateAsync(Customer updatedCustomer) { using (WaterContext waterContext = new WaterContext()) { waterContext.Entry(updatedCustomer).State = EntityState.Modified; await waterContext.SaveChangesAsync(); } return(updatedCustomer); }
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(); } }
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); }
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(); }
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); }
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); }
public async Task SaveAsync() { await _context.SaveChangesAsync(); }