public async Task <ResponseMessage> PutBeltLook(UserInfo user, [FromBody] BeltLookRequest beltLookRequest) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})发起请求修改带看信息(PutBeltLook):\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); var response = new ResponseMessage(); if (!ModelState.IsValid) { var error = ""; var errors = ModelState.Values.ToList(); foreach (var item in errors) { foreach (var e in item.Errors) { error += e.ErrorMessage + " "; } } response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = error; Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改带看信息(PutBeltLook)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); return(response); } try { var dictionaryGroup = await _beltLookManager.FindByIdAsync(beltLookRequest.Id, HttpContext.RequestAborted); if (dictionaryGroup == null) { await _beltLookManager.CreateAsync(user, beltLookRequest, HttpContext.RequestAborted); } await _beltLookManager.UpdateAsync(user.Id, beltLookRequest, HttpContext.RequestAborted); response.Code = ResponseCodeDefines.SuccessCode; response.Message = "修改成功"; } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.ToString(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})修改带看信息(PutBeltLook)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); } return(response); }
/// <summary> /// 修改单个带看信息 /// </summary> /// <param name="id">请求者Id</param> /// <param name="beltLookRequest">请求数据</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public virtual async Task UpdateAsync(string userId, BeltLookRequest beltLookRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (beltLookRequest == null) { throw new ArgumentNullException(nameof(beltLookRequest)); } var beltLook = await _ibeltLookStore.GetAsync(a => a.Where(b => b.Id == beltLookRequest.Id && !b.IsDeleted)); if (beltLook == null) { return; } var newbeltLook = _mapper.Map <BeltLook>(beltLookRequest); //带看基本信息 newbeltLook.IsDeleted = beltLook.IsDeleted; newbeltLook.CreateTime = beltLook.CreateTime; newbeltLook.CreateUser = beltLook.CreateUser; newbeltLook.UpdateTime = DateTime.Now; newbeltLook.UpdateUser = userId; await _ibeltLookStore.UpdateAsync(newbeltLook, cancellationToken); }
/// <summary> /// 新增带看信息 /// </summary> /// <param name="userId">创建者</param> /// <param name="customerInfoCreateResponse">请求实体</param> /// <param name="cancellationToken">验证</param> /// <returns></returns> public virtual async Task <BeltLookResponse> CreateAsync(UserInfo user, BeltLookRequest beltLookRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (beltLookRequest == null) { throw new ArgumentNullException(nameof(beltLookRequest)); } var beltLook = _mapper.Map <BeltLook>(beltLookRequest); //带看基本信息 beltLook.Id = Guid.NewGuid().ToString(); beltLook.CreateUser = user.Id; beltLook.CreateTime = DateTime.Now; beltLook.UserId = user.Id; beltLook.DepartmentId = user.OrganizationId; //beltLook.BeltState = BeltLookState.WaitLook; var report = await _icustomerreportstore.GetAsync(a => a.Where(b => b.BuildingId == beltLook.BeltHouse && !b.IsDeleted && b.CustomerId == beltLook.CustomerId), cancellationToken); if (report != null) { await _ibeltLookStore.CreateAsync(beltLook, cancellationToken); //report.ReportStatus = ReportStatus.; await _icustomerreportstore.UpdateAsync(report, cancellationToken); } else { return(null); } return(_mapper.Map <BeltLookResponse>(beltLook)); }
public async Task <ResponseMessage <BeltLookResponse> > PostBeltLook(UserInfo user, [FromBody] BeltLookRequest beltLookRequest) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})发起请求新增带看(PostBeltLook):\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); var response = new ResponseMessage <BeltLookResponse>(); if (!ModelState.IsValid) { var error = ""; var errors = ModelState.Values.ToList(); foreach (var item in errors) { foreach (var e in item.Errors) { error += e.ErrorMessage + " "; } } response.Code = ResponseCodeDefines.ModelStateInvalid; response.Message = error; Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增带看(PostBeltLook)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); return(response); } try { response.Extension = await _beltLookManager.CreateAsync(user, beltLookRequest, HttpContext.RequestAborted); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.ToString(); Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增带看(PostBeltLook)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (beltLookRequest != null ? JsonHelper.ToJson(beltLookRequest) : "")); } return(response); }