public ActionResult GroupEdit(AdminEditGroupViewModel model) { if (!IsAuthorized()) return new HttpStatusCodeResult(HttpStatusCode.Forbidden); if (ModelState.IsValid) { Group g = um.FindGroup(model.Id); g.Name = model.Name; g.Users.Clear(); g.Users.Add(um.GetDefaultUser()); foreach (var item in model.Users) { if (item.IsSelected) { FooBox.User u = um.FindUser(item.Id); if (u != null) g.Users.Add(u); } } g.Description = model.Description; try { um.Context.SaveChanges(); } catch { DisplayErrorMessage(); return View(model); } DisplaySuccessMessage("Group edited"); return RedirectToAction("Index"); } DisplayErrorMessage(); return View(model); }
// GET: Group/GroupEdit/5 public ActionResult GroupEdit(long? id) { if (!IsAuthorized()) return new HttpStatusCodeResult(HttpStatusCode.Forbidden); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Group grp = um.FindGroup(id.Value); if (grp == null) { return HttpNotFound(); } List<EntitySelectedViewModel> users = new List<EntitySelectedViewModel>(); var mod = new AdminEditGroupViewModel(); mod.Id = grp.Id; mod.Name = grp.Name; mod.Description = grp.Description; var userList = um.Context.Users.ToList(); foreach (User u in userList) { if (u.Name.Equals("__DEFAULT__") || u.State == ObjectState.Deleted) { continue; } var a = new EntitySelectedViewModel(); a.Id = u.Id; a.IsSelected = grp.Users.Contains(u); a.Name = u.Name; users.Add(a); } mod.Users = users; return View(mod); }