public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ActionDescriptor oActionDescriptor = filterContext.ActionDescriptor;

            if (CookieManager.GetCookie(CookieManager.CookieName) != null)
            {
                string          strActionName     = oActionDescriptor.ActionName;
                string          strControllerName = oActionDescriptor.ControllerDescriptor.ControllerName;
                RoleAccessModel oRoleAccessModel  = new RoleAccessModel()
                {
                    Rleid    = CookieManager.GetCookie(CookieManager.CookieName).logindetail.RoleId,
                    ViewType = "0"
                };
                List <RoleAccessDetails> lstRoleAccessDetails = oMasterManager.GetRoleAccess(oRoleAccessModel, CookieManager.GetCookie(CookieManager.CookieName).logindetail.EmpID);
                bool bIsError = true;
                foreach (var item in lstRoleAccessDetails)
                {
                    if (item.Controller.ToLower() == strControllerName.ToLower() && item.Action.ToLower() == strActionName.ToLower() && item.View == "1")
                    {
                        bIsError = false;
                    }
                }
                if (bIsError)
                {
                    filterContext.HttpContext.Response.Redirect("~/Login/Message");
                }
            }
            else
            {
                filterContext.HttpContext.Response.Redirect("~/Login/TimeOut");
            }

            base.OnActionExecuting(filterContext);
        }
Example #2
0
        public IHttpActionResult GetAccess(int RoleId, Modules?Module = null)
        {
            var role = db.Role.Where(r => r.Id == RoleId).FirstOrDefault();

            if (role == null)
            {
                return(NotFound());
            }

            var model = new RoleAccessModel();

            model.RoleName = role.Name;

            var accesses = db.RoleAccess.Where(r => r.RoleId == RoleId && (Module == null || r.Access.Module == Module)).Select(s => new UserAccessModel {
                UserAccess = s.UserAccess, IsCheck = true
            }).ToList();

            model.UserAccesses = accesses;

            var access = db.Access.Where(a => Module == null || a.Module == Module).Select(s => s.UserAccess).ToList();

            foreach (UserAccess type in access)
            {
                if (!model.UserAccesses.Any(a => a.UserAccess == type))
                {
                    model.UserAccesses.Add(new UserAccessModel {
                        UserAccess = type, IsCheck = false
                    });
                }
            }

            return(Ok(model));
        }
Example #3
0
        public static List <RoleAccessModel> RoleAccessDbToRoleAccessModelList(List <RoleAccess> roles)
        {
            var roleAccessModelList = new List <RoleAccessModel>();

            foreach (var item in roles)
            {
                var roleAccessModel = new RoleAccessModel
                {
                    RoleAccessId = item.Id,
                    AllowAdd     = item.AllowAdd,
                    AllowDelete  = item.AllowDelete,
                    AllowEdit    = item.AllowEdit,
                    AllowView    = item.AllowView,
                    Menu         = new MenuModel
                    {
                        Name = item.Menu.Name
                    },
                    Role = new RolesModel
                    {
                        Name = item.Role.Name
                    }
                };

                roleAccessModelList.Add(roleAccessModel);
            }

            return(roleAccessModelList);
        }
Example #4
0
        public static RoleAccessModel RoleAccessDbToRoleAccessModel(RoleAccess role)
        {
            var roleAccessModel = new RoleAccessModel
            {
                RoleAccessId = role.Id,
                AllowAdd     = role.AllowAdd,
                AllowDelete  = role.AllowDelete,
                AllowEdit    = role.AllowEdit,
                AllowView    = role.AllowView,
                RoleId       = role.RoleId,
                MenuId       = role.MenuId
            };

            return(roleAccessModel);
        }
Example #5
0
        public static RoleAccess RoleAccessModelToRoleDb(RoleAccessModel model)
        {
            var roleAccess = new RoleAccess
            {
                Id          = model.RoleAccessId,
                AllowAdd    = model.AllowAdd,
                AllowDelete = model.AllowDelete,
                AllowEdit   = model.AllowEdit,
                AllowView   = model.AllowView,
                RoleId      = model.RoleId,
                MenuId      = model.MenuId
            };

            return(roleAccess);
        }
Example #6
0
 public static RoleAccessDTOs ConvertAccessModelFromDTO(RoleAccessModel roleAccess)
 {
     Mapper.CreateMap <RoleAccessModel, RoleAccessDTOs>().ConvertUsing(
         m =>
     {
         return(new RoleAccessDTOs
         {
             AllowAdd = m.AllowAdd,
             AllowDelete = m.AllowDelete,
             AllowEdit = m.AllowEdit,
             AllowView = m.AllowView,
             AssignId = m.AssignId
         });
     });
     return(Mapper.Map <RoleAccessModel, RoleAccessDTOs>(roleAccess));
 }
Example #7
0
        //public string GetLoginInfo(string ForecController=null)
        //    {
        //        string controllerName = null;
        //        if (ForecController == null)

        //            controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
        //        else
        //            controllerName = ForecController;
        //        int parentId = _moduleService.GetParentId(controllerName);
        //        var empcode = ViewBag.Empcode;
        //        var roleId = ViewBag.EmpRoleId;
        //        int role = roleId != null ? Convert.ToInt32(roleId) : 0;
        //        int emcode = empcode !=null ? Convert.ToInt32(empcode):0;

        //        var roleInformation = _userRoleAccessService.GetRoleAccessData(role).ToList();
        //        try
        //        {
        //           List<ModuleDTOs> mdl = new List<ModuleDTOs>();
        //            ModuleModules md = new ModuleModules();
        //            List<RoleAccessDTOs> acc = new List<RoleAccessDTOs>();
        //            RoleAccessModel accModel = new RoleAccessModel();
        //            List<ParentModuleModels> parent = new List<ParentModuleModels>();
        //            List<ParentModule> parentModelDatas = new List<ParentModule>();
        //            List<ModuleDTOsForparent> pmt = new List<ModuleDTOsForparent>();
        //            if (roleInformation.Count >= 1)
        //            {
        //                foreach (var item in roleInformation)
        //                {
        //                    var moduleaccess1 = _moduleService.GetModuleParents(item.ModuleData.ModuleId).ToList();
        //                    var moduleaccess = moduleaccess1.Where(x => x.ModuleParentId == parentId).ToList();
        //                    if (moduleaccess != null && moduleaccess.Count >= 1)
        //                    {
        //                        foreach (var item1 in moduleaccess)
        //                        {
        //                            md.MduleLink = item1.MduleLink;
        //                            md.ModuleCssClass = item1.ModuleCssClass;
        //                            md.ModuleId = item1.ModuleId;
        //                            md.MOduleName = item1.MOduleName;
        //                            md.ModuleParentId = item1.ModuleParentId;
        //                        }
        //                        var da = formatter.ConvertModuleDataFromDTO(md);
        //                        mdl.Add(da);
        //                    }
        //                }
        //                ViewBag.TopMenuList = _moduleService.GetTopLevelModules(role);
        //                ViewBag.SideBar = mdl;
        //                int id = ViewBag.EmpCode != null ? ViewBag.EmpCode : 0;
        //                ViewBag.res = _notifications.Notificationlist(id);
        //            }
        //            else
        //            {
        //                var getRoleId = _unitOfWork.RoleRepository.Get(x => x.RoleId == role).SingleOrDefault();
        //                if (getRoleId != null)
        //                {
        //                    pmt = _moduleService.GetDefaultParentMenu();
        //                    foreach (var item in pmt)
        //                    {
        //                        var moduleaccess = _moduleService.GetDefaultMenu(item.ModuleParentId).ToList();
        //                        foreach (var item1 in moduleaccess)
        //                        {
        //                            md.MduleLink = item1.MduleLink;
        //                            md.ModuleCssClass = item1.ModuleCssClass;
        //                            md.ModuleId = item1.ModuleId;
        //                            md.MOduleName = item1.MOduleName;
        //                            md.ModuleParentId = item1.ModuleParentId;
        //                            var da = formatter.ConvertModuleDataFromDTO(md);
        //                            mdl.Add(da);
        //                        }
        //                    }
        //                }
        //                ViewBag.TopMenuList = _moduleService.GetTopLevelModules(role);
        //                ViewBag.SideBar = mdl;
        //                int id = ViewBag.EmpCode != null ? ViewBag.EmpCode : 0;
        //                ViewBag.res = _notifications.Notificationlist(id);
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            throw ex ;
        //        }
        //        return null ;
        //    }
        public string GetLoginInfo(string ForecController = null)
        {
            string controllerName = null;

            if (ForecController == null)
            {
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            }
            else
            {
                controllerName = ForecController;
            }
            int parentId = _moduleService.GetParentId(controllerName);
            var empcode  = ViewBag.Empcode;
            var roleId   = ViewBag.EmpRoleId;
            int role     = roleId != null?Convert.ToInt32(roleId) : 0;

            int emcode = empcode != null?Convert.ToInt32(empcode) : 0;

            var roleInformation = _userRoleAccessService.GetRoleAccessData(role).ToList();

            try
            {
                List <ModuleDTOs> mdl = new List <ModuleDTOs>();
                Module            mod = _moduleService.GetModuleByController(parentId);

                ModuleModules         md       = new ModuleModules();
                List <RoleAccessDTOs> acc      = new List <RoleAccessDTOs>();
                RoleAccessModel       accModel = new RoleAccessModel();
                //List<ParentModuleModels> parent = new List<ParentModuleModels>();
                //List<ParentModule> parentModelDatas = new List<ParentModule>();
                List <ModuleDTOsForparent> pmt = new List <ModuleDTOsForparent>();
                if (roleInformation.Count >= 1)
                {
                    foreach (var item in roleInformation)
                    {
                        var moduleaccess1 = _moduleService.GetModuleParents(item.ModuleData.ModuleId).ToList();
                        var moduleaccess  = moduleaccess1.Where(x => x.ModuleParentId == parentId).OrderBy(x => x.Order).ToList();
                        if (moduleaccess != null && moduleaccess.Count >= 1)
                        {
                            foreach (var item1 in moduleaccess)
                            {
                                md.MduleLink      = item1.MduleLink;
                                md.ModuleCssClass = item1.ModuleCssClass;
                                md.ModuleId       = item1.ModuleId;
                                md.MOduleName     = item1.MOduleName;
                                md.ModuleParentId = item1.ModuleParentId;
                            }
                            var da = formatter.ConvertModuleDataFromDTO(md);
                            mdl.Add(da);
                        }
                    }
                    if (mod.IsDefault)
                    {
                        var moduleaccess2 = _moduleService.GetDefaultMenu();

                        if (moduleaccess2 != null)
                        {
                            foreach (var item1 in moduleaccess2)
                            {
                                md.MduleLink      = item1.MduleLink;
                                md.ModuleCssClass = item1.ModuleCssClass;
                                md.ModuleId       = item1.ModuleId;
                                md.MOduleName     = item1.MOduleName;
                                md.ModuleParentId = item1.ModuleParentId;
                                var da = formatter.ConvertModuleDataFromDTO(md);
                                mdl.Add(da);
                            }
                        }
                    }
                    else
                    {
                    }



                    ViewBag.TopMenuList = _moduleService.GetTopLevelModules(role);
                    ViewBag.SideBar     = mdl;
                    int id = ViewBag.EmpCode != null ? ViewBag.EmpCode : 0;
                    ViewBag.res = _notifications.Notificationlist(id);
                }
                else
                {
                    var getRoleId = _unitOfWork.RoleRepository.Get(x => x.RoleId == role).SingleOrDefault();
                    if (getRoleId != null)
                    {
                        var moduleaccess2 = _moduleService.GetDefaultMenu();

                        if (moduleaccess2 != null)
                        {
                            foreach (var item1 in moduleaccess2)
                            {
                                md.MduleLink      = item1.MduleLink;
                                md.ModuleCssClass = item1.ModuleCssClass;
                                md.ModuleId       = item1.ModuleId;
                                md.MOduleName     = item1.MOduleName;
                                md.ModuleParentId = item1.ModuleParentId;
                                var da = formatter.ConvertModuleDataFromDTO(md);
                                mdl.Add(da);
                            }
                        }
                    }
                    ViewBag.TopMenuList = _moduleService.GetTopLevelModules(role);
                    ViewBag.SideBar     = mdl;
                    int id = ViewBag.EmpCode != null ? ViewBag.EmpCode : 0;
                    ViewBag.res = _notifications.Notificationlist(id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }