protected void GetAllSecurables() { var securablesAll = new NetStock.BusinessFactory.RoleRightsBO() .GetSecurableItemsList(); Application["AppSecurables"] = securablesAll; }
public ActionResult SaveRights(List <RoleRightsMenu> right) { try { var lstRoleRights = new List <NetStock.Contract.RoleRights>(); right.Where(r => r.hasRight == true) .ToList() .ForEach(r => lstRoleRights.Add(new Contract.RoleRights { RoleCode = r.RoleCode, SecurableItem = r.SecurableItem })); var result = new NetStock.BusinessFactory.RoleRightsBO().SaveRoleRights(lstRoleRights); } catch (Exception ex) { ModelState.AddModelError("Error", ex.Message); } return(RedirectToAction("RoleRights")); }
public ActionResult RoleRights(string Role = "") { List <LayoutMenuRights> lstMenu = new List <LayoutMenuRights>(); if (!string.IsNullOrWhiteSpace(Role)) { var lstUsers = new NetStock.BusinessFactory.UsersBO().GetList(); var roleRights = new NetStock.BusinessFactory.RoleRightsBO() .GetList(Role); var securablesAll = (List <NetStock.Contract.Securables>)System.Web.HttpContext.Current.Application["AppSecurables"]; var securables = securablesAll.Join(roleRights, sec => sec.SecurableItem, rig => rig.SecurableItem, (sec, rig) => new { a = sec, b = rig }) .Select(x => new NetStock.Contract.Securables() { SecurableItem = x.a.SecurableItem, GroupID = x.a.GroupID, Description = x.a.Description, ActionType = x.a.ActionType, Link = x.a.Link, Icon = x.a.Icon, Sequence = x.a.Sequence, ParentSequence = x.a.ParentSequence }) .ToList <NetStock.Contract.Securables>(); var menuItems = securablesAll.Where(x => x.ActionType == "TopMenu") .Select(x => new { securableItem = x.SecurableItem, Icon = x.Icon, GroupId = x.GroupID }).Distinct().ToList(); for (var i = 0; i < menuItems.Count; i++) { LayoutMenuRights item = new LayoutMenuRights(); item.MenuName = menuItems[i].securableItem; item.Icon = menuItems[i].Icon; item.securablesLst = securablesAll.Where(x => x.GroupID == menuItems[i].securableItem && (x.ActionType == "Menu")) .Select(x => new SecurablesRights { SecurableItem = x.SecurableItem, GroupID = x.GroupID, Description = x.Description, ActionType = x.ActionType, Link = x.Link, Icon = x.Icon, hasRight = (securables.Where(j => j.SecurableItem == x.SecurableItem).Count() > 0), Sequence = x.Sequence, ParentSequence = x.ParentSequence, ActionMenus = securablesAll.Where(y => y.GroupID == menuItems[i].securableItem && (y.ActionType == "Action") && y.ParentSequence == x.Sequence) .Select(y => new SecurablesRights { SecurableItem = y.SecurableItem, GroupID = y.GroupID, Description = y.Description, ActionType = y.ActionType, Link = y.Link, Icon = y.Icon, hasRight = (securables.Where(jk => jk.SecurableItem == y.SecurableItem).Count() > 0), Sequence = y.Sequence, ParentSequence = y.ParentSequence }).ToList <SecurablesRights>() }).OrderBy(x => x.ParentSequence).ToList <SecurablesRights>(); if (item.securablesLst.Count > 0) { lstMenu.Add(item); } } ViewBag.RoleCode = Role; } return(View("RoleRights", lstMenu)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!string.IsNullOrEmpty(Request.QueryString["companyCode"])) { var companyCode = Request.QueryString["companyCode"]; Session["CompanyCode"] = companyCode; var branchList = new NetStock.BusinessFactory.BranchBO().GetList().Where(x => x.CompanyCode == companyCode).ToList(); model.BranchList = new SelectList(branchList, "BranchID", "BranchName"); var compist = new NetStock.BusinessFactory.CompanyBO().GetList(); model.CompaniesList = new SelectList(compist, "CompanyCode", "CompanyName"); return(View("Login", model)); } if (!ModelState.IsValid) { return(RedirectToAction("Login")); } var lstUsers = new NetStock.BusinessFactory.UsersBO().GetList(); var result = true; var currentUser = lstUsers.Where(ur => ur.UserID.ToLower() == model.Email.ToLower() && ur.Password.ToLower() == model.Password.ToLower()).FirstOrDefault(); if (currentUser == null) { result = false; } if (currentUser != null) { FormsAuthentication.SetAuthCookie(currentUser.UserID, false); //Utility.DEFAULTUSER = currentUser.UserID; //Utility.DEFAULTUSERNAME = currentUser.UserName; //Utility.SsnBranch = model.BranchID; Session["DEFAULTUSER"] = currentUser.UserID; Session["DEFAULTUSERNAME"] = currentUser.UserName; Session["BranchId"] = model.BranchID; Session["BranchText"] = Request.Form["hdnBranchSelected"]; var roleCode = currentUser.RoleCode; Session["UserRoleCode"] = currentUser.RoleCode; var roleRights = new NetStock.BusinessFactory.RoleRightsBO() .GetList(roleCode); var securablesAll = (List <NetStock.Contract.Securables>)System.Web.HttpContext.Current.Application["AppSecurables"]; var securables = securablesAll.Join(roleRights, sec => sec.SecurableItem, rig => rig.SecurableItem, (sec, rig) => new { a = sec, b = rig }) .Select(x => new NetStock.Contract.Securables() { SecurableItem = x.a.SecurableItem, GroupID = x.a.GroupID, Description = x.a.Description, ActionType = x.a.ActionType, Link = x.a.Link, Icon = x.a.Icon }).ToList <NetStock.Contract.Securables>(); Session["SsnSecurables"] = securables; if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); } }