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

                    if (multiPictureModuleViewModel.ModuleImage != module.MultiPictureModule.Image && module.MultiPictureModule.Image != "no-photo.jpg")
                    {
                        if (System.IO.File.Exists(Server.MapPath("/Content/Modules/Images/" + module.MultiPictureModule.Image)))
                        {
                            System.IO.File.Delete(Server.MapPath("/Content/Modules/Images/" + module.MultiPictureModule.Image));
                        }
                        if (System.IO.File.Exists(Server.MapPath("/Content/Modules/Images/thumbnail/" + module.MultiPictureModule.Image)))
                        {
                            System.IO.File.Delete(Server.MapPath("/Content/Modules/Images/thumbnail/" + module.MultiPictureModule.Image));
                        }
                    }

                    //editing HtmlModule
                    MultiPictureModule multiPictureModule = _multiPictureModuleService.GetByModuleId(multiPictureModuleViewModel.ModuleId);
                    if (multiPictureModule != null)
                    {
                        multiPictureModule.Title       = multiPictureModuleViewModel.Title;
                        multiPictureModule.TitleBold   = multiPictureModuleViewModel.TitleBold;
                        multiPictureModule.Description = multiPictureModuleViewModel.Description;
                        multiPictureModule.Cover       = multiPictureModuleViewModel.Cover;
                        multiPictureModule.Link        = multiPictureModuleViewModel.Link;
                        multiPictureModule.LinkMore    = multiPictureModuleViewModel.LinkMore;
                        multiPictureModule.Image       = multiPictureModuleViewModel.ModuleImage;
                        _multiPictureModuleService.Edit(multiPictureModule);
                    }

                    //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"));
        }
Esempio n. 2
0
 public ActionResult SliderShowModule(int id)
 {
     return(PartialView(_multiPictureModuleService.GetByModuleId(id)));
 }