// 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 { HtmlModulViewModel htmlModulViewModel = new HtmlModulViewModel() { ModuleId = module.ModuleId, ModuleTitle = module.ModuleTitle, IsActive = module.IsActive, PositionId = module.PositionId, DisplayOrder = module.DisplayOrder, HtmlText = module.HtmlModule.HtmlText, }; ViewBag.PositionId = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle"); return(View(htmlModulViewModel)); } }
// GET: Admin/HtmlModules/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Module module = await _moduleService.GetHtmlModuleById(id); if (module == null) { return(NotFound()); } HtmlModulViewModel htmlModulViewModel = new HtmlModulViewModel() { ModuleId = module.ModuleId, ModuleTitle = module.ModuleTitle, IsActive = module.IsActive, PositionId = module.PositionId, DisplayOrder = module.DisplayOrder, HtmlText = module.HtmlModule.HtmlText, }; ViewData["PositionId"] = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle"); return(View(htmlModulViewModel)); }
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")); }
public ActionResult Create(HtmlModulViewModel htmlModulViewModel) { if (ModelState.IsValid) { Module module = new Module() { ModuleTitle = htmlModulViewModel.ModuleTitle, PositionId = (int)htmlModulViewModel.PositionId, IsActive = htmlModulViewModel.IsActive, Accisibility = htmlModulViewModel.Accisibility, ComponentId = Convert.ToInt32(Request.Form["componentid"]) }; //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 HtmlModule inserting module.HtmlModule = new HtmlModule() { HtmlText = htmlModulViewModel.HtmlText, }; //Add the Module _moduleService.Add(module); } else { ModelState.AddModelError(string.Empty, "خطایی وجود دارد"); ViewBag.PositionId = new SelectList(_moduleService.Positions(), "PositionId", "PositionTitle"); return(View()); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(HtmlModulViewModel htmlModulViewModel) { if (ModelState.IsValid) { Module module = new Module() { ModuleTitle = htmlModulViewModel.ModuleTitle, PositionId = (int)htmlModulViewModel.PositionId, IsActive = htmlModulViewModel.IsActive, Accisibility = htmlModulViewModel.Accisibility, ComponentId = int.Parse(Request.Form["componentId"]) }; //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 HtmlModule inserting module.HtmlModule = new HtmlModule() { HtmlText = htmlModulViewModel.HtmlText, }; //Add the Module await _moduleService.Add(module); return(RedirectToAction(nameof(Index))); } ViewData["PositionId"] = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle"); return(View(htmlModulViewModel)); }
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)); }