예제 #1
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));
        }
예제 #2
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));
        }
예제 #3
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));
        }