public ActionResult Create(RolePrivilegeViewModel model) { if (ModelState.IsValid) { var request = model.MapTo <SaveRolePrivilegeRequest>(); request.UserId = this.UserProfile().UserId; if (_roleService.SaveRolePrivilege(request).IsSuccess) { return(RedirectToAction("Index")); } } ViewBag.RoleGroups = _roleGroupService.GetRoleGroups(new Services.Requests.RoleGroup.GetRoleGroupsRequest { Take = -1, SortingDictionary = new Dictionary <string, SortOrder> { { "Name", SortOrder.Ascending } } }) .RoleGroups.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = model.RoleGroup_Id == x.Id }).ToList(); return(View(model)); }
public ActionResult Create(int RoleId) { var model = new RolePrivilegeViewModel(); ViewBag.RoleGroups = _roleGroupService.GetRoleGroups(new Services.Requests.RoleGroup.GetRoleGroupsRequest { Take = -1, SortingDictionary = new Dictionary <string, SortOrder> { { "Name", SortOrder.Ascending } } }) .RoleGroups.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = RoleId == x.Id }).ToList(); model.RoleGroup_Id = RoleId; var roles = _roleService.GetMenuRolePrivileges(new GetPrivilegeByRolePrivilegeRequest { RoleId = RoleId }); if (roles.IsSuccess) { model.MenuRolePrivileges = roles.MenuRolePrivileges.ToList().MapTo <RolePrivilegeViewModel.MenuRolePrivilege>(); } return(View(model)); }
public ActionResult AddPrivilege(RolePrivilegeViewModel model) { if (ModelState.IsValid) { var request = model.MapTo <SaveRolePrivilegeRequest>(); request.UserId = this.UserProfile().UserId; var result = _rolePrivilegeService.SaveRolePrivilege(request); return(Json(result)); } else { var errorList = (from item in ModelState where item.Value.Errors.Any() select item.Value.Errors[0].ErrorMessage).ToList(); return(Json(new { IsSuccess = false, Message = errorList })); } //ViewBag.RoleGroups = _roleGroupService.GetRoleGroups(new Services.Requests.RoleGroup.GetRoleGroupsRequest //{ // Take = -1, // SortingDictionary = new Dictionary<string, SortOrder> { { "Name", SortOrder.Ascending } } //}) // .RoleGroups.Select(x => new SelectListItem // { // Text = x.Name, // Value = x.Id.ToString(), // Selected = model.RoleGroup_Id == x.Id // }).ToList(); //return View(model); }
public ActionResult Edit(int Id) { int RoleId = this.UserProfile().RoleId; var result = _roleService.GetRolePrivilege(new GetPrivilegeRequest { Id = Id }); var model = new RolePrivilegeViewModel(); model = result.MapTo <RolePrivilegeViewModel>(); if (model != null) { RoleId = model.RoleGroup_Id > 0 ? model.RoleGroup_Id : this.UserProfile().RoleId; } var privilege = _roleService.GetMenuRolePrivileges(new GetPrivilegeByRolePrivilegeRequest { RoleId = RoleId, RolePrivilegeId = Id }); model.MenuRolePrivileges = privilege.MenuRolePrivileges.ToList().MapTo <RolePrivilegeViewModel.MenuRolePrivilege>(); ViewBag.RoleGroups = _roleGroupService.GetRoleGroups(new Services.Requests.RoleGroup.GetRoleGroupsRequest { Take = -1, SortingDictionary = new Dictionary <string, SortOrder> { { "Name", SortOrder.Ascending } } }) .RoleGroups.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = RoleId == x.Id }).ToList(); return(View(model)); }
public ActionResult Edit(RolePrivilegeViewModel model) { ViewBag.RoleGroups = _roleGroupService.GetRoleGroups(new Services.Requests.RoleGroup.GetRoleGroupsRequest { Take = -1, SortingDictionary = new Dictionary <string, SortOrder> { { "Name", SortOrder.Ascending } } }).RoleGroups.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = model.RoleGroup_Id == x.Id }).ToList(); if (ModelState.IsValid) { return(RedirectToAction("Index")); } return(View(model)); }