コード例 #1
0
        public ActionResult Edit(HtmlModulViewModel htmlModulViewModel, int pastDisOrder, int pastPosition)
        {
            if (ModelState.IsValid)
            {
                Module module = _moduleService.GetById(htmlModulViewModel.ModuleId);
                if (module != null)
                {
                    module.ModuleTitle  = htmlModulViewModel.ModuleTitle;
                    module.PositionId   = (int)htmlModulViewModel.PositionId;
                    module.IsActive     = htmlModulViewModel.IsActive;
                    module.Accisibility = htmlModulViewModel.Accisibility;
                    module.DisplayOrder = htmlModulViewModel.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(htmlModulViewModel.ModuleId, item.MenuId)))
                        {
                            ModulePage modulePage = new ModulePage()
                            {
                                MenuId   = item.MenuId,
                                ModuleId = htmlModulViewModel.ModuleId,
                            };
                            modulePageAddList.Add(modulePage);
                        }
                        else if (Request.Form["Page[" + item.MenuId.ToString() + "]"] == null && _modulePageService.ExistModulePage(htmlModulViewModel.ModuleId, item.MenuId))
                        {
                            ModulePage PageRemove = _modulePageService.GetByMenuModule(htmlModulViewModel.ModuleId, item.MenuId);
                            modulePageRemoveList.Add(PageRemove);
                        }
                    }
                    _modulePageService.Add(modulePageAddList);
                    _modulePageService.Delete(modulePageRemoveList);

                    //editing HtmlModule
                    HtmlModule htmlModule = _htmlModuleService.GetByModuleId(htmlModulViewModel.ModuleId);
                    if (htmlModule != null)
                    {
                        htmlModule.HtmlText = htmlModulViewModel.HtmlText;
                        _htmlModuleService.Edit(htmlModule);
                    }

                    //Editing the Module
                    _moduleService.Edit(module, pastPosition, pastDisOrder);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "خطایی وجود دارد");
                ViewBag.PositionId = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle");
                return(View());
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(HtmlModulViewModel htmlModulViewModel, int pastDisOrder, int pastPosition)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Module module = await _moduleService.GetById(htmlModulViewModel.ModuleId);

                    if (module != null)
                    {
                        module.ModuleTitle  = htmlModulViewModel.ModuleTitle;
                        module.PositionId   = (int)htmlModulViewModel.PositionId;
                        module.IsActive     = htmlModulViewModel.IsActive;
                        module.Accisibility = htmlModulViewModel.Accisibility;
                        module.DisplayOrder = htmlModulViewModel.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())
                        {
                            if (Request.Form["Page[" + item.MenuId.ToString() + "]"].Any() && !await _modulePageService.ExistModulePage(htmlModulViewModel.ModuleId, item.MenuId))
                            {
                                ModulePage modulePage = new ModulePage()
                                {
                                    MenuId   = item.MenuId,
                                    ModuleId = htmlModulViewModel.ModuleId,
                                };
                                modulePageAddList.Add(modulePage);
                            }
                            else if (!Request.Form["Page[" + item.MenuId.ToString() + "]"].Any() && await _modulePageService.ExistModulePage(htmlModulViewModel.ModuleId, item.MenuId))
                            {
                                ModulePage PageRemove = await _modulePageService.GetByMenuModule(htmlModulViewModel.ModuleId, item.MenuId);

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

                        await _modulePageService.Remove(modulePageRemoveList);

                        //editing HtmlModule
                        HtmlModule htmlModule = await _htmlModuleService.GetByModuleId(htmlModulViewModel.ModuleId);

                        if (htmlModule != null)
                        {
                            htmlModule.HtmlText = htmlModulViewModel.HtmlText;
                            await _htmlModuleService.Edit(htmlModule);
                        }

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