Exemplo n.º 1
0
        // GET: Admin/MenuModules/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            //GetById included MenuModule
            Module module = await _moduleService.GetMenuModuleById(id);

            if (module == null)
            {
                return(NotFound());
            }
            MenuModulViewModel menuModulViewModel = new MenuModulViewModel
            {
                ModuleId     = module.ModuleId,
                ModuleTitle  = module.ModuleTitle,
                IsActive     = module.IsActive,
                PositionId   = module.PositionId,
                MenuGroupId  = module.MenuModule.MenuGroupId,
                DisplayOrder = module.DisplayOrder
            };

            ViewData["MenuGroupId"] = new SelectList(await _menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");
            ViewData["PositionId"]  = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle");
            return(View(menuModulViewModel));
        }
Exemplo n.º 2
0
        // GET: Admin/MenuModule/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Module module = _moduleService.GetById(id);

            if (module == null)
            {
                return(HttpNotFound());
            }
            else
            {
                MenuModulViewModel menuModulViewModel = new MenuModulViewModel()
                {
                    ModuleId     = module.ModuleId,
                    ModuleTitle  = module.ModuleTitle,
                    IsActive     = module.IsActive,
                    PositionId   = module.PositionId,
                    MenuGroupId  = module.MenuModule.MenuGroupId,
                    DisplayOrder = module.DisplayOrder
                };
                ViewBag.PositionId  = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle");
                ViewBag.MenuGroupId = new SelectList(_menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");

                return(View(menuModulViewModel));
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(MenuModulViewModel menuModulViewModel, int pastDisOrder, int pastPosition)
        {
            if (ModelState.IsValid)
            {
                Module module = _moduleService.GetById(menuModulViewModel.ModuleId);
                if (module != null)
                {
                    module.ModuleTitle  = menuModulViewModel.ModuleTitle;
                    module.PositionId   = (int)menuModulViewModel.PositionId;
                    module.IsActive     = menuModulViewModel.IsActive;
                    module.Accisibility = menuModulViewModel.Accisibility;
                    module.DisplayOrder = menuModulViewModel.DisplayOrder;


                    //Method for selecting menus for modules
                    List <ModulePage> modulePageAddList    = new List <ModulePage>();
                    List <ModulePage> modulePageRemoveList = new List <ModulePage>();
                    foreach (var item in _menuService.menus())
                    {
                        if (Request.Form["Page[" + item.MenuId.ToString() + "]"] != null && !(_modulePageService.ExistModulePage(menuModulViewModel.ModuleId, item.MenuId)))
                        {
                            ModulePage modulePage = new ModulePage()
                            {
                                MenuId   = item.MenuId,
                                ModuleId = menuModulViewModel.ModuleId,
                            };
                            modulePageAddList.Add(modulePage);
                        }
                        else if (Request.Form["Page[" + item.MenuId.ToString() + "]"] == null && _modulePageService.ExistModulePage(menuModulViewModel.ModuleId, item.MenuId))
                        {
                            ModulePage PageRemove = _modulePageService.GetByMenuModule(menuModulViewModel.ModuleId, item.MenuId);
                            modulePageRemoveList.Add(PageRemove);
                        }
                    }
                    _modulePageService.Add(modulePageAddList);
                    _modulePageService.Delete(modulePageRemoveList);

                    //editing MenuModule GroupId if it's changed
                    var EditMenuModule = _menuModuleService.GetByModuleId(menuModulViewModel.ModuleId);
                    if (EditMenuModule.MenuGroupId != menuModulViewModel.MenuGroupId)
                    {
                        EditMenuModule.MenuGroupId = menuModulViewModel.MenuGroupId;
                        _menuModuleService.Edit(EditMenuModule);
                    }

                    //Editing the Module
                    _moduleService.Edit(module, pastPosition, pastDisOrder);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "خطایی وجود دارد");
                ViewBag.PositionId  = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle");
                ViewBag.MenuGroupId = new SelectList(_menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");
                return(View());
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Create(MenuModulViewModel menuModulViewModel)
        {
            if (ModelState.IsValid)
            {
                Module module = new Module()
                {
                    ModuleTitle  = menuModulViewModel.ModuleTitle,
                    PositionId   = (int)menuModulViewModel.PositionId,
                    IsActive     = menuModulViewModel.IsActive,
                    Accisibility = menuModulViewModel.Accisibility,
                    ComponentId  = 1,
                };


                //Method for selecting menus for modules
                foreach (var item in _menuService.menus())
                {
                    if (Request.Form["Page[" + item.MenuId.ToString() + "]"] != null)
                    {
                        ModulePage modulePage = new ModulePage()
                        {
                            MenuId = item.MenuId,
                        };
                        module.ModulePage.Add(modulePage);
                    }
                }

                //for menuModule inserting
                module.MenuModule = new MenuModule()
                {
                    MenuGroupId = menuModulViewModel.MenuGroupId,
                };

                //Add the Module
                _moduleService.Add(module);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "خطایی وجود دارد");
                ViewBag.PositionId  = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle");
                ViewBag.MenuGroupId = new SelectList(_menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");
                return(View());
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(MenuModulViewModel menuModulViewModel)
        {
            if (ModelState.IsValid)
            {
                Module module = new Module()
                {
                    ModuleTitle  = menuModulViewModel.ModuleTitle,
                    PositionId   = (int)menuModulViewModel.PositionId,
                    IsActive     = menuModulViewModel.IsActive,
                    Accisibility = menuModulViewModel.Accisibility,
                    ComponentId  = 1,
                };


                //Method for selecting menus for modules
                foreach (var item in await _menuService.Menus())
                {
                    if (Request.Form["Page[" + item.MenuId.ToString() + "]"].Any())
                    {
                        ModulePage modulePage = new ModulePage()
                        {
                            MenuId = item.MenuId,
                        };
                        module.ModulePage.Add(modulePage);
                    }
                }

                //for menuModule inserting
                module.MenuModule = new MenuModule()
                {
                    MenuGroupId = menuModulViewModel.MenuGroupId,
                };

                //Add the Module
                await _moduleService.Add(module);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MenuGroupId"] = new SelectList(await _menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");
            ViewData["PositionId"]  = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle");
            return(View(menuModulViewModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(MenuModulViewModel menuModulViewModel, int pastDisOrder, int pastPosition)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Module module = await _moduleService.GetById(menuModulViewModel.ModuleId);

                    if (module != null)
                    {
                        module.ModuleTitle  = menuModulViewModel.ModuleTitle;
                        module.PositionId   = (int)menuModulViewModel.PositionId;
                        module.IsActive     = menuModulViewModel.IsActive;
                        module.Accisibility = menuModulViewModel.Accisibility;
                        module.DisplayOrder = menuModulViewModel.DisplayOrder;


                        //Method for selecting menus for modules
                        List <ModulePage> modulePageAddList    = new List <ModulePage>();
                        List <ModulePage> modulePageRemoveList = new List <ModulePage>();
                        foreach (var item in await _menuService.Menus())
                        {
                            //add menues that wasnt added before
                            if (Request.Form["Page[" + item.MenuId.ToString() + "]"].Any() && !await _modulePageService.ExistModulePage(menuModulViewModel.ModuleId, item.MenuId))
                            {
                                ModulePage modulePage = new ModulePage()
                                {
                                    MenuId   = item.MenuId,
                                    ModuleId = menuModulViewModel.ModuleId,
                                };
                                modulePageAddList.Add(modulePage);
                            }
                            //remove menues that was added before
                            else if (!Request.Form["Page[" + item.MenuId.ToString() + "]"].Any() && await _modulePageService.ExistModulePage(menuModulViewModel.ModuleId, item.MenuId))
                            {
                                ModulePage PageRemove = await _modulePageService.GetByMenuModule(menuModulViewModel.ModuleId, item.MenuId);

                                modulePageRemoveList.Add(PageRemove);
                            }
                        }
                        await _modulePageService.Add(modulePageAddList);

                        await _modulePageService.Remove(modulePageRemoveList);

                        //editing MenuModule GroupId if it's changed
                        var EditMenuModule = await _menuModuleService.GetByModuleId(menuModulViewModel.ModuleId);

                        if (EditMenuModule.MenuGroupId != menuModulViewModel.MenuGroupId)
                        {
                            EditMenuModule.MenuGroupId = menuModulViewModel.MenuGroupId;
                            await _menuModuleService.Edit(EditMenuModule);
                        }

                        //Editing the Module
                        await _moduleService.Edit(module, pastPosition, pastDisOrder);
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MenuGroupId"] = new SelectList(await _menuGroupService.MenuGroup(), "MenuGroupId", "MenuTitile");
            ViewData["PositionId"]  = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle");
            return(View(menuModulViewModel));
        }