Ejemplo n.º 1
0
        /// <summary>
        /// 新增成交信息
        /// </summary>
        /// <param name="user">创建者</param>
        /// <param name="transactionsFollowUpRequest">请求实体</param>
        /// <param name="cancellationToken">验证</param>
        /// <returns></returns>
        public virtual async Task <ResponseMessage <TransactionsFollowUpResponse> > CreateAsync(UserInfo user, TransactionsFollowUpRequest transactionsFollowUpRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (transactionsFollowUpRequest == null)
            {
                throw new ArgumentNullException(nameof(transactionsFollowUpRequest));
            }

            var respons = new ResponseMessage <TransactionsFollowUpResponse>();

            var tsfollowUp = _mapper.Map <CustomerTransactionsFollowUp>(transactionsFollowUpRequest);

            tsfollowUp.Id         = Guid.NewGuid().ToString();
            tsfollowUp.UserId     = user.Id;
            tsfollowUp.CreateTime = DateTime.Now;
            tsfollowUp.CreateUser = user.Id;
            try
            {
                await _icustomerTransactionsFollowUpStore.CreateAsync(tsfollowUp, cancellationToken);

                respons.Code      = ResponseCodeDefines.SuccessCode;
                respons.Message   = "创建成功";
                respons.Extension = _mapper.Map <TransactionsFollowUpResponse>(tsfollowUp);
            }
            catch (Exception e)
            {
                respons.Code    = ResponseCodeDefines.ServiceError;
                respons.Message = "服务器错误:" + e.ToString();
            }

            return(respons);
        }
        public async Task <ResponseMessage <TransactionsFollowUpResponse> > PostCustomerFollowUp(UserInfo user, [FromBody] TransactionsFollowUpRequest transactionsFollowUpRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增成交信息(PostCustomerFollowUp):\r\n请求参数为:\r\n" + (transactionsFollowUpRequest != null ? JsonHelper.ToJson(transactionsFollowUpRequest) : ""));

            var response = new ResponseMessage <TransactionsFollowUpResponse>();

            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 ?? ""})新增成交信息(PostCustomerFollowUp)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (transactionsFollowUpRequest != null ? JsonHelper.ToJson(transactionsFollowUpRequest) : ""));
                return(response);
            }
            try
            {
                response = await _customerTransactionsFollowUpManager.CreateAsync(user, transactionsFollowUpRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})新增成交信息(PostCustomerFollowUp)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (transactionsFollowUpRequest != null ? JsonHelper.ToJson(transactionsFollowUpRequest) : ""));
            }
            return(response);
        }