/// <summary> /// 编辑UserInfo信息 /// </summary> /// <param name="dtos">要更新的UserInfoEditDto信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> EditUserInfos(params UserInfoEditDto[] dtos) { dtos.CheckNotNull("dtos"); OperationResult result = await Task.Run(() => UserInfoRepo.Update(dtos)); return(result); }
/// <summary> /// 编辑UserInfo信息 /// </summary> /// <param name="dtos">要更新的UserInfoEditDto信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> EditUserInfos(params UserInfoEditDto[] dtos) { dtos.CheckNotNull("dtos"); var result = UserInfoRepo.Update(dtos, updateFunc: (dto, userInfo) => { var sysUser = userInfo.SysUser; sysUser.NickName = dto.NickName; return(userInfo); }); return(await Task.FromResult(result)); }
/// <summary> /// 保存UserInfo信息(新增/更新) /// </summary> /// <param name="updateForeignKey">更新时是否更新外键信息</param> /// <param name="dtos">要保存的UserInfoDto信息</param> /// <returns>业务操作集合</returns> public async Task <OperationResult> SaveUserInfos(bool updateForeignKey = false, params UserInfoDto[] dtos) { try { dtos.CheckNotNull("dtos"); var addDtos = dtos.Where(p => p.Id == 0).ToArray(); var updateDtos = dtos.Where(p => p.Id != 0).ToArray(); UserInfoRepo.UnitOfWork.TransactionEnabled = true; Action <UserInfoDto> checkAction = dto => { if (UserInfoRepo.CheckExists(p => p.PhoneNo == dto.PhoneNo, dto.Id)) { throw new Exception("“{0}”已被使用".FormatWith("手机号")); } }; Func <UserInfoDto, UserInfo, UserInfo> updateFunc = (dto, entity) => { if (dto.Id == 0 || updateForeignKey) { entity.SysUser = SysUserRepo.GetByKey(dto.SysUserId); } return(entity); }; if (addDtos.Length > 0) { UserInfoRepo.Insert(addDtos, checkAction, updateFunc); } if (updateDtos.Length > 0) { UserInfoRepo.Update(updateDtos, checkAction, updateFunc); } await UserInfoRepo.UnitOfWork.SaveChangesAsync(); return(new OperationResult(OperationResultType.Success, "保存成功")); } catch (Exception e) { return(new OperationResult(OperationResultType.Error, e.Message)); } }