示例#1
0
        public async Task <IActionResult> CreateCustomer([FromBody] CreateCustomerRequest request)
        {
            var nameResult = CustomerName.Craete(request.Title,
                                                 request.FirstName,
                                                 request.LastName);

            if (nameResult.Status == OpStatus.Error)
            {
                return(BadRequest(new
                {
                    CustomerId = string.Empty,
                    nameResult.Errors
                }));
            }

            var addressResult = CustomerAddress.Create(request.HouseNoOrName,
                                                       request.Street,
                                                       request.City,
                                                       request.County,
                                                       request.PostCode
                                                       );

            if (addressResult.Status == OpStatus.Error)
            {
                return(BadRequest(new
                {
                    CustomerId = string.Empty,
                    addressResult.Errors
                }));
            }

            var contactResult = CustomerContact.Create(request.Mobile,
                                                       request.Email);

            if (contactResult.Status == OpStatus.Error)
            {
                return(BadRequest(new
                {
                    CustomerId = string.Empty,
                    contactResult.Errors
                }));
            }

            var customer = new Customer(new Id <Customer>(Guid.NewGuid()),
                                        nameResult.Value,
                                        addressResult.Value,
                                        contactResult.Value);

            var commandResult = await _mediator.Send(new CreateCustomerCommand(customer));

            _logger.LogInformation($"Successfully created a customer {commandResult.Value}");

            return(Ok(new
            {
                CustomerId = commandResult.Value,
                Errors = new string[] {}
            }));
        }
示例#2
0
 public string CreateCustomerAddress(int customerId, CustomerAddress customerAddress)
 {
     try
     {
         return(CustomerAddress.Create(_connection.Url, _connection.SessionId, customerId, customerAddress));
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
        /// <summary>
        /// 新增客户地址
        /// </summary>
        /// <param name="customerId">客户Id</param>
        /// <param name="linkname">联系人</param>
        /// <param name="mobile">手机号</param>
        /// <param name="address">地址</param>
        /// <param name="isDefault">是否默认</param>
        /// <param name="creator">创建人</param>
        public void Add(string customerId, string linkname, string mobile, string address, string isDefault, string creator)
        {
            using (DbConnection conn = DbHelper.CreateConnection())
            {
                DbTransaction trans = null;
                try
                {
                    conn.Open();
                    trans = conn.BeginTransaction();
                    if (trans == null)
                    {
                        throw new ArgumentNullException("DbTransaction");
                    }
                    CustomerAddress entity = new CustomerAddress();
                    entity.Create(customerId, address, mobile, linkname, isDefault, creator);
                    if (entity.IsDefaultAddress())
                    {
                        CustomerAddress defaultEntity = this.customerAddressRepository.GetDefaultAddres(trans, customerId);
                        if (defaultEntity != null)
                        {
                            defaultEntity.CancelDefault(creator);
                            this.customerAddressRepository.Update(trans, defaultEntity);
                        }
                    }
                    this.customerAddressRepository.Insert(trans, entity);

                    trans.Commit();
                }
                catch
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw;
                }
            }
        }