Exemple #1
0
        // GET: Home
        public ActionResult Index()
        {
            if (this.User.Identity.IsAuthenticated && Session["MenuMaster"] == null)
            {
                var criteria = new MenuRoleMapCriteria {
                    RoleId = new Guid("eb05d6ba-edf8-4fda-97e7-1409c4b14ea1"), IsActive = true
                };
                var specification = new MenuRoleMapSpecification(criteria);
                var menus         = _menuRoleMapRepository.Find(specification).OrderBy(x => x.Menu.Order).ToList();

                List <MenuVM> listOfMenu = new List <MenuVM>();

                foreach (var menu in menus)
                {
                    if (menu.Menu.IsParent)
                    {
                        var submenus = menus.Where(x => x.Menu.MainMenu != null && x.Menu.MainMenu.Id.Equals(menu.Menu.Id)).Select(x => x.Menu).ToList();
                        if (submenus.Count() != 0)
                        {
                            var mainMenuVM = MenuVM.GetDTO(menu.Menu);
                            foreach (var submenu in submenus)
                            {
                                mainMenuVM.SubMenuList.Add(MenuVM.GetDTO(submenu));
                            }
                            listOfMenu.Add(mainMenuVM);
                        }
                    }
                    else if (!menu.Menu.IsParent && menu.Menu.MainMenu == null)
                    {
                        listOfMenu.Add(MenuVM.GetDTO(menu.Menu));
                    }
                    else
                    {
                        continue;
                    }
                }
                Session["MenuMaster"] = listOfMenu;
            }

            return(View());
        }
Exemple #2
0
        public ActionResult UpdateAccess(Guid?roleId = null)
        {
            var role = _roleRepository.GetById(roleId ?? Guid.Empty);

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

            AccessMenuVM vm = new AccessMenuVM();

            vm.Role = RoleVM.GetDTO(role);

            var criteria = new MenuRoleMapCriteria {
                RoleId = role.Id
            };
            var specification = new MenuRoleMapSpecification(criteria);
            var menuMapList   = _menuRoleMapRepository.Find(specification).OrderBy(x => x.Menu.Order).ToList();

            vm.Menus = menuMapList.Select(x => MenuRoleMapVM.GetDTO(x)).ToList();

            return(PartialView("_AccessMenuView", vm));
        }
Exemple #3
0
        public ActionResult Login(LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                var employeeCriteria = new EmployeeCriteria {
                    EmailId = loginVM.Username, Password = loginVM.Password
                };
                var employeeSpecification = new EmployeeSpecification(employeeCriteria);
                var employee = _employeeRepository.Find(employeeSpecification).FirstOrDefault();

                if (employee == null)
                {
                    ModelState.AddModelError("", "Invalid Username and Password");
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(loginVM.Username, loginVM.RememberMe);
                    if (loginVM.RememberMe)
                    {
                        Response.Cookies["Username"].Value   = loginVM.Username;
                        Response.Cookies["Password"].Value   = loginVM.Password;
                        Response.Cookies["Username"].Expires = DateTime.UtcNow.AddMonths(12);
                        Response.Cookies["Password"].Expires = DateTime.UtcNow.AddMonths(12);
                    }
                    else
                    {
                        Response.Cookies["Username"].Expires = DateTime.UtcNow.AddMinutes(-1);
                        Response.Cookies["Password"].Expires = DateTime.UtcNow.AddMinutes(-1);
                    }

                    var criteria = new MenuRoleMapCriteria {
                        RoleId = employee.Role.Id, IsActive = true
                    };
                    var specification = new MenuRoleMapSpecification(criteria);
                    var menus         = _menuRoleMapRepository.Find(specification).OrderBy(x => x.Menu.Order).ToList();

                    List <MenuVM> listOfMenu = new List <MenuVM>();

                    foreach (var menu in menus)
                    {
                        if (menu.Menu.IsParent)
                        {
                            var submenus = menus.Where(x => x.Menu.MainMenu != null && x.Menu.MainMenu.Id.Equals(menu.Menu.Id)).Select(x => x.Menu).ToList();
                            if (submenus.Count() != 0)
                            {
                                var mainMenuVM = MenuVM.GetDTO(menu.Menu);
                                foreach (var submenu in submenus)
                                {
                                    mainMenuVM.SubMenuList.Add(MenuVM.GetDTO(submenu));
                                }
                                listOfMenu.Add(mainMenuVM);
                            }
                        }
                        else if (!menu.Menu.IsParent && menu.Menu.MainMenu == null)
                        {
                            listOfMenu.Add(MenuVM.GetDTO(menu.Menu));
                        }
                        else
                        {
                            continue;
                        }
                    }
                    Session["MenuMaster"] = listOfMenu;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(loginVM));
        }
Exemple #4
0
        public ActionResult UpdateMenus()
        {
            MenuVM v1 = new MenuVM()
            {
                MenuName = "Home", Controller = "Home", Action = "Index", Order = 1, IsParent = false
            };
            MenuVM v2 = new MenuVM()
            {
                MenuName = "Role", Controller = "Tech", Action = "Role", Order = 2, IsParent = false
            };
            MenuVM v3 = new MenuVM()
            {
                MenuName = "Menu", Controller = "", Action = "", Order = 3, IsParent = true
            };
            MenuVM v4 = new MenuVM()
            {
                MenuName = "View", Controller = "Tech", Action = "Menu", Order = 4, IsParent = false
            };

            v4.MainMenuVM = v3;
            MenuVM v5 = new MenuVM()
            {
                MenuName = "Manage Menu", Controller = "Tech", Action = "ManageMenu", Order = 5, IsParent = false
            };

            v5.MainMenuVM = v3;
            MenuVM v6 = new MenuVM()
            {
                MenuName = "Employees", Controller = "Employee", Action = "Index", Order = 6, IsParent = false
            };

            List <MenuVM> menus = new List <MenuVM>()
            {
                v1, v2, v3, v4, v5, v6
            };

            foreach (var menu in menus)
            {
                var newMenu = GetSearchedMenu(menu);
                if (newMenu == null)
                {
                    newMenu = new Menu(menu.MenuName, menu.Controller, menu.Action, menu.Order);
                    _menuRepository.Add(newMenu);
                    _menuRepository.Save();
                }

                if (menu.MainMenuVM != null)
                {
                    var mainMenu = GetSearchedMenu(menu.MainMenuVM);
                    if (mainMenu == null)
                    {
                        mainMenu = new Menu(menu.MainMenuVM.MenuName, menu.MainMenuVM.Controller, menu.MainMenuVM.Action, menu.MainMenuVM.Order);
                        _menuRepository.Add(mainMenu);
                        _menuRepository.Save();
                    }
                    newMenu.MainMenu = mainMenu;
                    _menuRepository.Save();
                }
                newMenu.Order    = menu.Order;
                newMenu.IsParent = menu.IsParent;
                _menuRepository.Save();
            }

            var roleList = _roleRepository.Get().ToList();
            var menuList = _menuRepository.Get().ToList();

            foreach (var role in roleList)
            {
                foreach (var menu in menuList)
                {
                    var criteria = new MenuRoleMapCriteria {
                        RoleId = role.Id, MenuId = menu.Id
                    };
                    var specification = new MenuRoleMapSpecification(criteria);
                    var menuRoleMap   = _menuRoleMapRepository.Find(specification).FirstOrDefault();

                    if (menuRoleMap == null)
                    {
                        menuRoleMap      = new MenuRoleMap();
                        menuRoleMap.Role = role;
                        menuRoleMap.Menu = menu;
                        _menuRoleMapRepository.Add(menuRoleMap);
                        _menuRoleMapRepository.Save();
                    }
                }
            }

            return(RedirectToAction("Menu"));
        }