public IActionResult NewContactPerson(int bankId, int?contactPersonID)
        {
            if (contactPersonID != null)
            {
                if (_contactPersonService.Set().SingleOrDefault(s => s.BankID == bankId && s.ID == contactPersonID) == null)
                {
                    return(NotFound("Contact Person not found!"));
                }
                _contactPersonService.Remove(_contactPersonService.Set().Single(s => s.ID == contactPersonID));
                _contactPersonService.Commit();
                return(RedirectToAction("NewContactPerson", new { bankId }));
            }
            BankSaveModel bankSaveModel = new BankSaveModel();

            bankSaveModel.ContactPersonModels = _contactPersonService.Set().Where(w => w.BankID == bankId && w.PositionID != _positionService.Set().Single(s => s.Name.Equals("General Director")).ID).Select(s => (ContactPersonModel)s).ToList();
            bankSaveModel.BankModel           = (BankModel)_bankService.Set().Single(s => s.ID == bankId);
            bankSaveModel.Positions           = _positionService.Set().Select(s => (PositionModel)s).ToList();

            return(View(bankSaveModel));
        }
示例#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));
        }