Beispiel #1
0
 public static CustomerChangeCommand ToCommand(this CustomerAddOrChangeRequest request, string ip, string userId, int version)
 {
     if (request == null)
     {
         return(null);
     }
     return(new CustomerChangeCommand(SystemDefine.DefaultVersion)
     {
         Gender = request.Gender,
         LastIpAddress = ip,
         PhoneNumber = request.PhoneNumber,
         Birthday = request.BirthdayValue,
         CreatedUid = userId,
         FullName = request.FullName,
         TwoFactorEnabled = request.TwoFactorEnabled,
         Status = request.Status,
         Type = request.Type,
         IsTaxExempt = request.IsTaxExempt,
         AdminComment = request.AdminComment,
         BillingAddressId = request.BillingAddressId,
         CreatedDateUtc = Extensions.GetCurrentDateUtc(),
         Email = request.Email,
         Password = request.Password,
         ShippingAddressId = request.ShippingAddressId,
         Id = request.Id,
         Version = version,
         LanguageId = request.LanguageId,
     });
 }
 public async Task <IActionResult> Add([FromBody] CustomerAddOrChangeRequest request)
 {
     try
     {
         CustomerAddOrChangeResponse response = new CustomerAddOrChangeResponse();
         ValidationResult            validate = CustomerAddRequestValidator.ValidateModel(request);
         if (validate.IsValid)
         {
             response = await _customerAppService.AddOrChange(request);
         }
         else
         {
             response.SetFail(validate.Errors.Select(p => p.ToString()));
         }
         return(Json(response));
     }
     catch (Exception e)
     {
         _logger.LogError(e, Common.Common.GetMethodName(), request);
         throw;
     }
 }
Beispiel #3
0
        public async Task <CustomerAddOrChangeResponse> AddOrChange(CustomerAddOrChangeRequest request)
        {
            CustomerAddOrChangeResponse response = new CustomerAddOrChangeResponse();

            try
            {
                var userLogin = await _context.GetCurrentCustomer();

                CommandResult result;
                if (string.IsNullOrEmpty(request.Id))
                {
                    long systemIdentity = await _commonService.GetNextId(typeof(Customer));

                    string code    = Common.Common.GenerateCodeFromId(systemIdentity, 3);
                    var    command = request.ToCommand(_context.Ip, userLogin.Id, code);
                    result = await _customerService.SendCommand(command);
                }
                else
                {
                    var command = request.ToCommand(_context.Ip, userLogin.Id, request.Version);
                    result = await _customerService.SendCommand(command);
                }
                if (result.IsSucess)
                {
                    response.SetSucess();
                }
                else
                {
                    response.SetFail(result.Message);
                }
            }
            catch (Exception e)
            {
                response.SetFail(e);
                _logger.LogError(e, e.Message, request);
            }
            return(response);
        }