public async Task <Customer> UpsertAsync(Customer customer) { var current = await _db.Customers.FirstOrDefaultAsync(_customer => _customer.Id == customer.Id); if (null == current) { _db.Customers.Add(customer); } else { _db.Entry(current).CurrentValues.SetValues(customer); } await _db.SaveChangesAsync(); return(customer); }
public async Task <Teacher> UpsertAsync(Teacher teacher) { var current = await _db.Teachers.FirstOrDefaultAsync(_teacher => _teacher.Id == teacher.Id); if (null == current) { await _db.Teachers.AddAsync(teacher); } else { _db.Entry(current).CurrentValues.SetValues(teacher); } await _db.SaveChangesAsync(); return(current); }
public async Task <Order> UpsertAsync(Order order) { var existing = await _db.Orders.FirstOrDefaultAsync(x => x.Id == order.Id); if (null == existing) { order.InvoiceNumber = _db.Orders.Max(x => x.InvoiceNumber) + 1; _db.Orders.Add(order); } else { _db.Entry(existing).CurrentValues.SetValues(order); } await _db.SaveChangesAsync(); return(order); }
public async Task<Group> DeleteAsync(Guid groupId) { var current = await _db.Groups.FirstOrDefaultAsync(_group => _group.Id == groupId); if (null != current) { var teachers = await _db.Groups.Where(_group => _group.Id == groupId).ToListAsync(); _db.Groups.RemoveRange(current); _db.Groups.Remove(current); await _db.SaveChangesAsync(); } return current; }
public async Task <User> DeleteAsync(Guid userId) { var user = await _db.Users.FirstOrDefaultAsync(_user => _user.Id == userId); if (null != user) { var teachers = await _db.Teachers.Where(_user => _user.Id == userId).ToListAsync(); _db.Users.RemoveRange(user); _db.Users.Remove(user); await _db.SaveChangesAsync(); } return(user); }
public async Task <Position> DeleteAsync(Guid positionId) { var current = await _db.Positions.FirstOrDefaultAsync(_pos => _pos.Id == positionId); if (null != current) { var teachers = await _db.Disciplines.Where(_pos => _pos.Id == positionId).ToListAsync(); _db.Positions.RemoveRange(current); _db.Positions.Remove(current); await _db.SaveChangesAsync(); } return(current); }
public async Task <Discipline> DeleteAsync(Guid disciplineId) { var current = await _db.Disciplines.FirstOrDefaultAsync(_disc => _disc.Id == disciplineId); if (null != current) { var teachers = await _db.Disciplines.Where(_discipline => _discipline.Id == disciplineId).ToListAsync(); _db.Disciplines.RemoveRange(current); _db.Disciplines.Remove(current); await _db.SaveChangesAsync(); } return(current); }