public JsonResult SaveSecurables(string role, List <SecurableViewModel> securableViewModel) { JsonResult result = new JsonResult(); List <RoleRight> roleRightsList = new List <RoleRight>(); foreach (var item in securableViewModel) { RoleRight roleRights = null; roleRights = RoleRightService.GetRoleRights <RoleRight>(rr => rr.SecurableID == item.Id && rr.RoleCode.ToLower() == role.ToLower() && rr.AccessRight > 0).FirstOrDefault(); if (item.IsChecked) { if (roleRights == null) { roleRights = new RoleRight(); } roleRights.CompanyId = USER_OBJECT.CompanyId; roleRights.RoleCode = role; roleRights.SecurableID = item.Id; roleRights.AccessRight = Convert.ToInt16(item.Access); roleRightsList.Add(roleRights); } } RoleRightService.SaveRoleRights(roleRightsList); return(result); }
// GET: Account/RoleRights public JsonResult GetRoles() { JsonResult result = new JsonResult(); List <Role> Roles = RoleRightService.GetRole <Role>().ToList(); result = Json(new { sucess = true, Roles = Roles }, JsonRequestBehavior.AllowGet); return(result); }
public ActionResult LogOn(User user) { JsonResult result = null; if (user != null) { try { if (!string.IsNullOrWhiteSpace(user.UserName) && !string.IsNullOrWhiteSpace(user.Password)) { User _user = LogInLogOutService.GetUser <User>(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault(); var securables = RoleRightService.GetRoleRights <RoleRight>(x => x.CompanyId == _user.Branch.CompanyId && x.RoleCode == _user.RoleCode) .Select(x => new SecurableViewModel() { securableitem = x.Securable.SecurableID, OperationID = x.Securable.OperationID, AccessRight = x.AccessRight }).ToList(); //EmployeeHeader employeeHeader = EmployeeProfileService.GetEmployeeProfileList<EmployeeHeader>(u => u.UserId == _user.Id).FirstOrDefault(); SessionObject sessionObject = new SessionObject() { Id = _user.Id, UserID = _user.UserID, UserName = _user.UserName, Email = _user.Email, RoleCode = _user.RoleCode, BranchId = _user.BranchId, BranchName = _user.Branch.BranchName, CompanyId = _user.Branch.CompanyId, CountryCode = _user.Branch.Address.CountryCode, //EmployeeId = employeeHeader != null ? employeeHeader.Id : 0, //Employeename = employeeHeader != null ? employeeHeader.FirstName : string.Empty }; USER_OBJECT = sessionObject; result = Json(new { success = true, SessionObject = USER_OBJECT, securables = securables }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { result = Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet); } } return(result); }
public JsonResult SaveEmployeeRoles(Role role) { JsonResult result = new JsonResult(); if (role != null) { try { Role _role = null; if (role.Id > 0) { _role = RoleRightService.GetRole <Role>(r => r.Id == role.Id).FirstOrDefault(); _role.ModifiedBy = USER_OBJECT.UserName; _role.ModifiedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now); } else { _role = new Role(); _role.CreatedBy = USER_OBJECT.UserName; _role.CreatedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now); } _role.RoleCode = role.RoleCode; _role.RoleDescription = role.RoleDescription; _role.IsActive = role.IsActive; RoleRightService.Save(_role); result = Json(new { sucess = true, message = "Saved successfully" }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { return(Json(new { success = false, message = ex.InnerException.Message }, JsonRequestBehavior.DenyGet)); } } } else { result = Json(new { sucess = false, message = "No Data Found" }, JsonRequestBehavior.AllowGet); } return(result); }
public JsonResult GetSecurablebyId(string role) { JsonResult Result = new JsonResult(); var rightsList = RoleRightService.GetRoleRights <RoleRight>().Where(x => x.RoleCode == role && x.CompanyId == USER_OBJECT.CompanyId).AsEnumerable(); var securables = SecurableServices.GetSecurable <Securable>() .GroupBy(a => new { a.RegistrationType_LookUpId }).ToList() .Select(r => new { id = r.Select(x => x.SecurableID), registrationType = r.Key.RegistrationType_LookUpId, RegistrationTypeName = r.Select(x => x.RegistrationType.LookUpDescription).Distinct().FirstOrDefault(), IsChecked = false, pageList = r.GroupBy(b => new { b.PageID }) .Select(p => new { id = p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.SecurableID).FirstOrDefault(), pageID = p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.PageID).FirstOrDefault(), PageName = p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.PageDescription).FirstOrDefault(), // && rr.AccessRight !=0 IsChecked = rightsList.Where(rr => rr.SecurableID == (p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.SecurableID).FirstOrDefault())).Count() > 0, Access = rightsList.Where(rr => rr.SecurableID == (p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.SecurableID).FirstOrDefault())).Count() > 0 ? rightsList.Where(rr => rr.SecurableID == (p.Where(x => x.PageID == p.Key.PageID && x.Type == 1).Select(x => x.SecurableID).FirstOrDefault())).FirstOrDefault().AccessRight : 0, operationList = r.Where(x => x.PageID == p.Key.PageID && x.Type == 2) //r.GroupBy(c=>new { c.PageID }) .Select(o => new { id = o.SecurableID, OperationID = o.OperationID, OperationName = o.OperationDescription, IsChecked = rightsList.Where(rr => rr.SecurableID == (o.SecurableID)).Count() > 0, }) .ToList() }).ToList() }).ToList(); Result = Json(new { sucess = true, Securable = securables }, JsonRequestBehavior.AllowGet); return(Result); }
public IQueryable <T> IsChecked <T>(Expression <Func <T, bool> > predicate = null) where T : RoleRight { var rightsList = RoleRightService.GetRoleRights <RoleRight>().Where(x => x.CompanyId == USER_OBJECT.CompanyId).OfType <T>(); return(rightsList.Where(predicate)); }
/// <summary> /// 删除此角色所有的权限 /// </summary> /// <param name="roleId"></param> /// <returns></returns> public static int delRoleRightByRoleId(int roleId) { return(RoleRightService.delRoleRightByRoleId(roleId)); }
public static int AddRight(int roleId, int nodeId) { return(RoleRightService.AddRight(roleId, nodeId)); }
/// <summary> /// 根据RoleId查找对象集合 /// </summary> /// <param name="roleId"></param> /// <returns></returns> public static IList <RoleRight> GetRoleRightByRoleId(int roleId) { return(RoleRightService.GetRoleRightByRoleId(roleId)); }