public ActionResult Update(int id) { var group = _groupService.GetByKey(id); var lstRoles = new List <RolesModelDetail>(); var lstRoleGroupOfGroup = _roleService.GetRolesByGroupId(id); foreach (var item in _roleService.GetAll()) { var roleMd = new RolesModelDetail(); roleMd.Id = item.Id; roleMd.Descreption = item.Descreption; roleMd.IsCheck = false; var flag = lstRoleGroupOfGroup.Any(n => n.RoleId == item.Id); if (flag) { roleMd.IsCheck = true; } lstRoles.Add(roleMd); } var model = new GroupModelDetail(); model.Group = group; model.Roles = lstRoles; return(View(model)); }
public ActionResult CreateNew(GroupModelDetail model) { if (!model.Roles.Any(n => n.IsCheck == true)) { AlertWarning("Hãy chọn các quyền mà nhóm người dùng này được phép hoạt động."); return(View(model)); } if (ModelState.IsValid) { _groupService.BeginTran(); try { var check = _groupService.CheckContain(model.Group.Name); if (check) { AlertWarning(InfoString.Instance.SetContainString("Tên nhóm")); return(View(model)); } var group = new Group(); group.Name = model.Group.Name; group.Descreption = model.Group.Descreption; group.CreateBy = CurrentInstance.Instance.CurrentUser.UserName; group.CreateDate = DateTime.Now; group.Status = model.Group.Status; _groupService.CreateNew(group); _groupService.CommitChanges(); //add roles to group foreach (var role in model.Roles) { if (role.IsCheck) { _roleService.AddRoleToGroup(role.Id, group.Id); } } _roleService.CommitChanges(); _groupService.CommitTran(); } catch (Exception ex) { LogError(ex); _groupService.RollbackTran(); AlertError(InfoString.ERROR_SYSTEM); } AlertSuccess(InfoString.CREATE_SUCCESSFULL); return(RedirectToAction("Index")); } AlertWarning(InfoString.INVALID_INFO); return(View(model)); }
public ActionResult CreateNew() { var model = new GroupModelDetail(); var lstRoles = new List <RolesModelDetail>(); foreach (var item in _roleService.GetAll()) { lstRoles.Add(new RolesModelDetail { Id = item.Id, Descreption = item.Descreption, IsCheck = false }); } model.Group = new Group(); model.Group.Status = true; model.Roles = lstRoles; return(View(model)); }