/// <summary> /// 保存人员数据 /// </summary> /// <param name="perVM"></param> /// <returns></returns> public async Task <IActionResult> Save([Bind("ID,IsNew,Name,Email,FixedTelephone,Description,SortCode")] PersonVM perVM) { var hasDuplicateNamePerson = await _PersonExtension.HasInstanceAsyn(x => x.Name == perVM.Name); if (hasDuplicateNamePerson && perVM.IsNew) //判断是否已存在该人员 { ModelState.AddModelError("", "人员名重复,无法添加"); //添加指定的错误信息 return(View("../../Views/BusinessOrganization/Person/CreateOrEdit", perVM)); } var bo = new Person(); if (!perVM.IsNew) { bo = await _PersonRepository.GetSingleAsyn(perVM.ID); } perVM.MapToBo(bo); var saveStatus = await _PersonRepository.AddOrEditAndSaveAsyn(bo); if (saveStatus) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "数据保存出现异常,无法处理,请联系开发部人员。"); return(View("../../Views/BusinessOrganization/Person/CreateOrEdit", perVM)); } }
/// <summary> /// 保存人员数据 /// </summary> /// <param name="perVM"></param> /// <returns></returns> public async Task <IActionResult> Save([Bind("ID,IsNew,UserName,Name,Description,MobileNumber,QQ,UserAddress,School")] ApplicationUserVM userVM) { var hasDuplicateNamePerson = await _userExtension.HasInstanceAsyn(x => x.Name == userVM.Name); if (hasDuplicateNamePerson && userVM.IsNew) //判断是否已存在该人员 { ModelState.AddModelError("", "人员名重复,无法添加"); //添加指定的错误信息 return(View("~/Views/BusinessOrganization/Person/CreateOrEdit.cshtml", userVM)); } var user = new ApplicationUser(); if (!userVM.IsNew) { user = await _userExtension.GetSingleAsyn(x => x.Id == userVM.ID.ToString()); } userVM.MapToOm(user); if (userVM.IsNew) { _userExtension.AddAndSave(user); } else { _userExtension.EditAndSave(user); } return(RedirectToAction("Index")); }