コード例 #1
0
        public ActionResult Menu()
        {
            var menus = _menuRepository.Get().OrderBy(x => x.Order).ToList();

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

            foreach (var menu in menus)
            {
                var singleVM = MenuVM.GetDTO(menu);
                if (menu.MainMenu != null)
                {
                    singleVM.MainMenuVM = MenuVM.GetDTO(menu.MainMenu);
                }
                listOfMenuVM.Add(singleVM);
            }
            return(View(listOfMenuVM));
        }
コード例 #2
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());
        }
コード例 #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));
        }