예제 #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"));
        }
예제 #4
0
        public async Task <IActionResult> Edit(ContactModuleViewModel contactModuleViewModel, int pastDisOrder, int pastPosition)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Module module = await _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 await _menuService.Menus())
                        {
                            if (Request.Form["Page[" + item.MenuId.ToString() + "]"].Any() && !await _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() + "]"].Any() && await _modulePageService.ExistModulePage(contactModuleViewModel.ModuleId, item.MenuId))
                            {
                                ModulePage PageRemove = await _modulePageService.GetByMenuModule(contactModuleViewModel.ModuleId, item.MenuId);

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

                        await _modulePageService.Remove(modulePageRemoveList);

                        //editing HtmlModule
                        ContactModule contactModule = await _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;
                            await _contactModuleService.Edit(contactModule);
                        }

                        //for Users Editing contactModule updating
                        List <ContactPerson> contactPeopleAddList    = new List <ContactPerson>();
                        List <ContactPerson> contactPeopleRemoveList = new List <ContactPerson>();
                        foreach (var item in await _userService.GetAllAdmin())
                        {
                            if (Request.Form["User[" + item.UserId.ToString() + "]"].Any() && !await _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() + "]"].Any() && await _contactPersonService.ExistContactPerson(contactModuleViewModel.ModuleId, item.UserId))
                            {
                                ContactPerson contactRemove = await _contactPersonService.GetByModuleUser(contactModuleViewModel.ModuleId, item.UserId);

                                contactPeopleRemoveList.Add(contactRemove);
                            }
                        }
                        await _contactPersonService.Add(contactPeopleAddList);

                        await _contactPersonService.Remove(contactPeopleRemoveList);


                        //Editing the Module
                        await _moduleService.Edit(module, pastPosition, pastDisOrder);
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(NotFound());
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PositionId"] = new SelectList(await _positionService.GetAll(), "PositionId", "PositionTitle");
            return(View(contactModuleViewModel));
        }
예제 #5
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));
        }
예제 #6
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));
        }