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

                    //editing HtmlModule
                    ContactModule contactModule = _contactModuleService.GetByModuleId(contactModuleViewModel.ModuleId);
                    if (contactModule != null)
                    {
                        contactModule.Email       = contactModuleViewModel.Email;
                        contactModule.PostCode    = contactModuleViewModel.PostCode;
                        contactModule.PhoneNum    = contactModuleViewModel.PhoneNum;
                        contactModule.MobileNum   = contactModuleViewModel.MobileNum;
                        contactModule.Description = contactModuleViewModel.Description;
                        contactModule.Address     = contactModuleViewModel.Address;
                        _contactModuleService.Edit(contactModule);
                    }

                    //for Users Editing contactModule updating
                    List <ContactPerson> contactPeopleAddList    = new List <ContactPerson>();
                    List <ContactPerson> contactPeopleRemoveList = new List <ContactPerson>();
                    foreach (var item in _userService.GetAllAdmin())
                    {
                        if (Request.Form["User[" + item.UserId.ToString() + "]"] != null && !(_contactPersonService.ExistContactPerson(contactModuleViewModel.ModuleId, item.UserId)))
                        {
                            ContactPerson contactPerson = new ContactPerson()
                            {
                                UserId          = item.UserId,
                                ContactModuleId = contactModuleViewModel.ModuleId,
                            };
                            contactPeopleAddList.Add(contactPerson);
                        }
                        else if (Request.Form["User[" + item.UserId.ToString() + "]"] == null && _contactPersonService.ExistContactPerson(contactModuleViewModel.ModuleId, item.UserId))
                        {
                            ContactPerson contactRemove = _contactPersonService.GetByModuleUser(contactModuleViewModel.ModuleId, item.UserId);
                            contactPeopleRemoveList.Add(contactRemove);
                        }
                    }
                    _contactPersonService.Add(contactPeopleAddList);
                    _contactPersonService.Delete(contactPeopleRemoveList);


                    //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 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"));
        }