private void UpdateGroupUsers(int[] SelectedUsers, DominoesGroup dominoesGroup) { if (SelectedUsers == null) { dominoesGroup.Users = new List <UserProfileInfo>(); } var SelectedUsersHS = new HashSet <int>(SelectedUsers); var GroupUsersHS = new HashSet <int>(dominoesGroup.Users.Select(i => i.UserProfileInfoID)); foreach (var user in db.UserProfileInfo) { if (SelectedUsersHS.Contains(user.UserProfileInfoID)) { if (!GroupUsersHS.Contains(user.UserProfileInfoID)) { dominoesGroup.Users.Add(user); } } else { if (GroupUsersHS.Contains(user.UserProfileInfoID)) { dominoesGroup.Users.Remove(user); } } } }
// GET: DominoesGroups/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DominoesGroup dominoesGroup = db.DominoesGroup.Find(id); var model = new UserViewModel(); var AllUsers = db.UserProfileInfo.Select( u => new { UserID = u.UserProfileInfoID, Name = u.FirstName }).ToList(); model.DominoesGroupID = id.Value; model.UsersSelect = new MultiSelectList(AllUsers, "UserID", "Name"); model.UserIDs = dominoesGroup.Users.Select(u => u.UserProfileInfoID).ToArray(); if (dominoesGroup == null) { return(HttpNotFound()); } return(View(model)); }
public ActionResult DeleteConfirmed(int id) { DominoesGroup dominoesGroup = db.DominoesGroup.Find(id); db.DominoesGroup.Remove(dominoesGroup); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: DominoesGroups/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DominoesGroup dominoesGroup = db.DominoesGroup.Find(id); if (dominoesGroup == null) { return(HttpNotFound()); } return(View(dominoesGroup)); }