Beispiel #1
0
        public async Task <ResponseMessage> JoinCustomer(UserInfo user, [FromBody] CustomerPoolJoinRequest customerPoolJoinRequest)
        {
            Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})将客户移到公客池(JoinCustomer):\r\n请求参数为:\r\n" + (customerPoolJoinRequest != null ? JsonHelper.ToJson(customerPoolJoinRequest) : ""));

            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})将客户移到公客池(JoinCustomer)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (customerPoolJoinRequest != null ? JsonHelper.ToJson(customerPoolJoinRequest) : ""));
                return(response);
            }
            try
            {
                await _customerPoolManager.JoinCustomer(user, customerPoolJoinRequest, HttpContext.RequestAborted);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})将客户移到公客池(JoinCustomer)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n" + (customerPoolJoinRequest != null ? JsonHelper.ToJson(customerPoolJoinRequest) : ""));
            }
            return(response);
        }
Beispiel #2
0
        public async Task JoinCustomerAsync(UserInfo user, CustomerPoolJoinRequest customerPoolJoinRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var customerInfos = Context.CustomerInfos.Where(a => customerPoolJoinRequest.CustomerIds.Contains(a.Id)).ToList();

            foreach (var item in customerInfos)
            {
                item.UserId       = "";
                item.DepartmentId = customerPoolJoinRequest.DepartmentId;
                var pool = new CustomerPool()
                {
                    CreateTime   = DateTime.Now,
                    CreateUser   = user.Id,
                    CustomerId   = item.Id,
                    IsDeleted    = false,
                    JoinDate     = DateTime.Now,
                    DepartmentId = customerPoolJoinRequest.DepartmentId
                };
                Context.Update(item);
                Context.Add(pool);
            }
            try
            {
                await Context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
 /// <summary>
 /// 加入公客池
 /// </summary>
 /// <param name="customerPoolJoinRequest"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async Task JoinCustomer(UserInfo userInfo, CustomerPoolJoinRequest customerPoolJoinRequest, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (customerPoolJoinRequest == null)
     {
         throw new ArgumentNullException(nameof(CustomerPoolJoinRequest));
     }
     await Store.JoinCustomerAsync(userInfo, customerPoolJoinRequest, cancellationToken);
 }