//[Authorize(Roles = "Admin, CanEditGroup")] public ActionResult GroupAddUsers(int id, string userName, string email) { var group = db.Groups.Find(id); string _MaTTP = ""; _MaTTP = User.Identity.Name.ToUpper() == "ADMIN" ? "" : db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name).MA_TINHTP; var model = new SelectUsersOutGroupViewModel(group, _MaTTP); if (!string.IsNullOrEmpty(userName)) { model.UserOutGroup = model.UserOutGroup.Where(s => s.UserName != null && s.UserName.ToUpper().Contains(userName.ToUpper())).ToList(); } if (!string.IsNullOrEmpty(email)) { model.UserOutGroup = model.UserOutGroup.Where(s => s.Email != null && s.Email.ToUpper().Contains(email.ToUpper())).ToList(); } DTINHTP _TTP = (new FDB.DataAccessLayer.FDBContext()).DTINHTP.FirstOrDefault(m => m.MA_TINHTP == _MaTTP); if (_TTP != null) { ViewBag.TenTTP = _TTP.TEN_TINHTP; } return(View(model)); }
public ActionResult GroupAddUsers(SelectUsersOutGroupViewModel model) { if (ModelState.IsValid) { var idManager = new IdentityManager(); var groupOutSelectedIds = model.GroupOutSelectedIds(); foreach (var userId in groupOutSelectedIds) { idManager.AddUserToGroup(userId, model.GroupId); } return(RedirectToAction("index")); } return(View()); }