public async Task <IActionResult> Create(ContactPersonCreateViewModel personVM) { try { if (ModelState.IsValid) { var person = Mapper.Map <MS_PIC>(personVM); var row = await ContPersonService.Add(person); if (row == 0) { return(Json(JsonResponse.Success("No data created", null, MessageInfoType.Info))); } else { return(Json(JsonResponse.Success("The contact person was successfully created", null, MessageInfoType.Success))); } } return(Json(JsonResponse.Error("Insufficient data", null, MessageInfoType.Error))); } catch (Exception ex) { return(Json(JsonResponse.Error(ex.Message, null, MessageInfoType.Error))); } }
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 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)); }