public async void Delete(int divisionId) { using (var context = new MVVMDemoDBEntities()) { context.Divisions.Remove(await context.Divisions.FirstOrDefaultAsync(x => x.DivisionId == divisionId)); await context.SaveChangesAsync(); } }
public async void Update(Division division) { using (var context = new MVVMDemoDBEntities()) { var divisionToUpdate = await context.Divisions.FirstOrDefaultAsync(x => x.DivisionId == division.DivisionId); divisionToUpdate.Name = division.Name; await context.SaveChangesAsync(); } }
public async void Add(User user) { using (var context = new MVVMDemoDBEntities()) { context.Users.Add(new User { FirstName = user.FirstName, LastName = user.LastName }); await context.SaveChangesAsync(); } }
public async void Update(User user) { using (var context = new MVVMDemoDBEntities()) { User userToUpdate = await context.Users.FirstOrDefaultAsync(x => x.UserId == user.UserId); userToUpdate.FirstName = user.FirstName; userToUpdate.LastName = user.LastName; userToUpdate.Division = user.Division; await context.SaveChangesAsync(); } }
public async void Add(string name) { using (var context = new MVVMDemoDBEntities()) { if (!context.Divisions.Any(x => x.Name == name)) { context.Divisions.Add(new Division { Name = name }); await context.SaveChangesAsync(); } else { throw new Exception("En avdelning med det namnet finns redan"); } } }