public void AddUserPermission(int MenuId, string UserName) { string RoleId = (string)System.Web.HttpContext.Current.Session["RoleUId"]; RolesMenu Rm = new RolesMenu(); Rm.RoleId = RoleId; Rm.CreatedBy = UserName; Rm.CreatedDate = DateTime.Now; Rm.DivisionId = (int)System.Web.HttpContext.Current.Session["UserPermissionDivisionId"]; Rm.SiteId = (int)System.Web.HttpContext.Current.Session["UserPermissionSiteId"]; Rm.ModifiedBy = UserName; Rm.ModifiedDate = DateTime.Now; Rm.MenuId = MenuId; Rm.ObjectState = Model.ObjectState.Added; int AssignedActionsCount = _rolesMenuService.GetPermittedActionsCountForMenuId(MenuId, RoleId); if (AssignedActionsCount <= 0) { Rm.FullHeaderPermission = true; } int AssignedChildActionCount = _rolesMenuService.GetChildPermittedActionsCountForMenuId(MenuId, RoleId); if (AssignedChildActionCount <= 0) { Rm.FullLinePermission = true; } _rolesMenuService.Create(Rm); _unitOfWork.Save(); }
public void CopyPermission(CopyRolesViewModel vm, string UserName) { var RolesSites = _rolesSiteService.GetRolesSiteList(vm.FromRoleId); var ExistingRolesSites = _rolesSiteService.GetRolesSiteList(vm.ToRoleId); var PendingToUpdate = from p in RolesSites join t in ExistingRolesSites on p.RolesSiteId equals t.RolesSiteId into table from left in table.DefaultIfEmpty() where left == null select p; foreach (var item in PendingToUpdate) { RolesSite site = new RolesSite(); site.CreatedBy = UserName; site.CreatedDate = DateTime.Now; site.ModifiedBy = UserName; site.ModifiedDate = DateTime.Now; site.RoleId = vm.ToRoleId; site.SiteId = item.SiteId; site.ObjectState = Model.ObjectState.Added; _rolesSiteService.Create(site); } var RolesDivisions = _rolesDivisionService.GetRolesDivisionList(vm.FromRoleId); var ExistingRolesDivisions = _rolesDivisionService.GetRolesDivisionList(vm.ToRoleId); var PendingDivisionsToUpdate = from p in RolesDivisions join t in ExistingRolesDivisions on p.RolesDivisionId equals t.RolesDivisionId into table from left in table.DefaultIfEmpty() where left == null select p; foreach (var item in PendingDivisionsToUpdate) { RolesDivision division = new RolesDivision(); division.CreatedBy = UserName; division.CreatedDate = DateTime.Now; division.DivisionId = item.DivisionId; division.ModifiedBy = UserName; division.ModifiedDate = DateTime.Now; division.RoleId = vm.ToRoleId; division.ObjectState = Model.ObjectState.Added; _rolesDivisionService.Create(division); } var RolesMenus = _rolesMenuService.GetRolesMenuList(vm.FromRoleId); var ExistingRolesMenus = _rolesMenuService.GetRolesMenuList(vm.ToRoleId); var PendingMenusToUpDate = from p in RolesMenus join t in ExistingRolesMenus on p.RolesMenuId equals t.RolesMenuId into table from left in table.DefaultIfEmpty() where left == null select p; foreach (var item in PendingMenusToUpDate) { RolesMenu menu = new RolesMenu(); menu.CreatedBy = UserName; menu.CreatedDate = DateTime.Now; menu.FullHeaderPermission = item.FullHeaderPermission; menu.FullLinePermission = item.FullLinePermission; menu.MenuId = item.MenuId; menu.SiteId = item.SiteId; menu.DivisionId = item.DivisionId; menu.ModifiedBy = UserName; menu.ModifiedDate = DateTime.Now; menu.RoleId = vm.ToRoleId; menu.ObjectState = Model.ObjectState.Added; _rolesMenuService.Create(menu); } var RolesActions = _rolesControllerActionService.GetRolesControllerActionList(vm.FromRoleId); var ExistingRolesActions = _rolesControllerActionService.GetRolesControllerActionList(vm.ToRoleId); var PendingRolesActionsToUpdate = from p in RolesActions join t in ExistingRolesActions on p.RolesControllerActionId equals t.RolesControllerActionId into table from left in table.DefaultIfEmpty() where left == null select p; foreach (var item in PendingRolesActionsToUpdate) { RolesControllerAction Actions = new RolesControllerAction(); Actions.ControllerActionId = item.ControllerActionId; Actions.CreatedBy = UserName; Actions.CreatedDate = DateTime.Now; Actions.ModifiedBy = UserName; Actions.ModifiedDate = DateTime.Now; Actions.RoleId = vm.ToRoleId; Actions.ObjectState = Model.ObjectState.Added; _rolesControllerActionService.Create(Actions); } _unitOfWork.Save(); }