public Shift UpdateShift(Shift shift) { _context.Attach(shift).State = EntityState.Modified; _context.Entry(shift).Reference(s => s.User).IsModified = true; _context.Entry(shift).Reference(s => s.Route).IsModified = true; _context.Entry(shift).Reference(s => s.PShift).IsModified = true; _context.SaveChanges(); return(shift); }
public User UpdateUser(UserDTO userDTO) { byte[] newPassHash, newPassSalt; _auth.CreatePasswordHash(userDTO.Password, out newPassHash, out newPassSalt); User user = new User { Id = userDTO.Id, Name = userDTO.Name, Email = userDTO.Email, IsAdmin = userDTO.IsAdmin, PasswordHash = newPassHash, PasswordSalt = newPassSalt, Group = userDTO.Group, ProfilePicture = userDTO.ProfilePicture, PShifts = userDTO.PShifts, Role = userDTO.Role, Shifts = userDTO.Shifts }; if (user.PShifts != null) { var newPShiftList = new List <UserPendingShift>(user.PShifts); } _context.Attach(user).State = EntityState.Modified; _context.Entry(user).Reference(u => u.Group).IsModified = true; if (user.Shifts != null) { _context.Entry(user).Collection(u => u.Shifts).IsModified = true; var shifts = _context.Shifts.Where(s => s.User.Id == user.Id && !user.Shifts.Exists(us => us.Id == s.Id)); foreach (var shift in shifts) { shift.User = null; _context.Entry(shift).Reference(s => s.User).IsModified = true; } } if (user.PShifts != null) { _context.UserPendingShifts.RemoveRange( _context.UserPendingShifts.Where(usp => usp.UserId == user.Id)); } _context.SaveChanges(); return(user); }
public Group UpdateGroup(Group group) { _context.Attach(group).State = EntityState.Modified; _context.Entry(group).Collection(g => g.Users).IsModified = true; var users = _context.Users.Where(u => u.Group.Id == group.Id && !group.Users.Exists(ul => ul.Id == u.Id)); foreach (var user in users) { user.Group = null; _context.Entry(user).Reference(u => u.Group).IsModified = true; } _context.SaveChanges(); return(group); }
public PendingShift UpdatePendingShift(PendingShift pendingShift) { var newUserList = new List <UserPendingShift>(pendingShift.Users); _context.Attach(pendingShift).State = EntityState.Modified; _context.Entry(pendingShift).Reference(ps => ps.Shift).IsModified = true; _context.UserPendingShifts.RemoveRange( _context.UserPendingShifts.Where(ups => ups.PendingShiftId == pendingShift.Id)); _context.SaveChanges(); return(pendingShift); }