Beispiel #1
0
        /////////////////////////////////////////////////////////////////
        ///// Customers operations
        ////////////////////////////////////////////////////////////////

        /// <summary>
        /// Creates the customer.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public CustomerResponse CreateCustomer(CustomerRequest request)
        {
            AbstractRestRequestStrategy <CustomerRequest, Customer, SdkError> requestStrategy =
                new CreateCustomerStrategy(request);

            requestStrategy.SendRequest();

            CustomerResponse response = new CustomerResponse();

            response.Customer = requestStrategy.RestResponse.Data;
            response.Error    = requestStrategy.RestResponse.Error;

            return((CustomerResponse)PrepareComposeResponse(response));
        }
Beispiel #2
0
        public ICommandResult Handle(CreateCustomerCommand command)
        {
            var address = new Address(
                command.HomeType,
                command.PublicPlaceType,
                command.PublicPlaceName,
                command.HomeNumber,
                command.CEP,
                command.Neighborhood,
                command.City,
                command.State,
                command.Country,
                command.Complement,
                command.AddressLabel
                );

            var customer = new Customer(
                command.UserId,
                command.Name,
                command.LastName,
                command.Gender,
                command.CPF,
                StringToDateTime.Convert(command.BirthDate, "yyyy-MM-dd"),
                command.Phone,
                command.Email,
                command.Active,
                new List <Address> {
                address
            }
                );

            var strategy       = new CreateCustomerStrategy();
            var strategyResult = (GenericCommandResult)strategy.Execute(customer, _repository);

            if (!strategyResult.Success)
            {
                return(strategyResult);
            }

            _repository.CreateCustomer(customer);
            _repository.SaveChanges();
            return(new GenericCommandResult(true, "Sucesso no registro do cliente", customer));
        }