示例#1
0
        public void ConvertToEntity_InputNotNull_ReturnSamePicture()
        {
            CreateCustomerInput input = MockCreateCustomerInput();

            Customer customer = input.ConvertToEntity();

            Assert.Equal(input.Picture, customer.Picture);
        }
示例#2
0
        public void ConvertToEntity_InputNotNull_ReturnEmplyId()
        {
            CreateCustomerInput input = MockCreateCustomerInput();

            Customer customer = input.ConvertToEntity();

            Assert.Equal(Guid.Empty, customer.Id);
        }
示例#3
0
        public void ConvertToEntity_InputNotNull_ReturnSameEmail()
        {
            CreateCustomerInput input = MockCreateCustomerInput();

            Customer customer = input.ConvertToEntity();

            Assert.Equal(input.Email, customer.Email);
        }
 public static Customer ConvertToEntity(this CreateCustomerInput source)
 {
     return(new()
     {
         Name = source.Name,
         LastName = source.LastName,
         Email = source.Email,
         Picture = source.Picture
     });
 }
        public async Task <ActionResult <Customer> > Create(CreateCustomerInput input)
        {
            Customer customer = new ()
            {
                Name = input.Name
            };

            _repository.Create(customer);

            await _createdMessagePublisher.Value.Send(customer);

            return(customer);
        }
示例#6
0
        public async Task <quanjianAjaxResponse> Create([FromBody] CreateCustomerInput input)
        {
            try
            {
                await _customerAppService.CreateCustomer(input);

                return(new quanjianAjaxResponse(true, "成功添加"));
            }
            catch (Exception e)
            {
                return(new quanjianAjaxResponse(false, "添加失败"));
            }
        }
        public async Task <OperationResult <CustomerDto> > CreateCustomerAsync(CreateCustomerInput input)
        {
            var validationResult = await _customerValidator.ValidateCreateCustomer(input);

            if (validationResult.IsSuccess)
            {
                var entity = input.ConvertToEntity();

                entity = await _customerRepository.CreateAsync(entity);

                return(OperationResult <CustomerDto> .Success(entity.ConvertToDto()));
            }

            return(OperationResult <CustomerDto> .Fail(validationResult));
        }
示例#8
0
        public int CreateCustomer(CreateCustomerInput input)
        {
            Logger.Info("Creating a Customer for input:" + input);
            var customer = new Customer
            {
                Address      = input.Address,
                Telephone    = input.Telephone,
                State        = input.State,
                CreationTime = Clock.Now,
                Bh           = input.Bh,
                Namesimple   = input.Namesimple
            };

            return(_customerRepository.InsertAndGetId(customer));
        }
        public async Task <Customer> CreateCustomer(CreateCustomerInput createCustomerInput)
        {
            try
            {
                Customer _customer = await _customersService.AddCustomer(createCustomerInput);

                return(_customer);
            }
            catch (Exception ex)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage(ex.Message)
                          .SetCode("CREATE_ERROR")
                          .Build());
            }
        }
示例#10
0
        //Add new customer record
        public async Task <Customer> AddCustomer(CreateCustomerInput createCustomerInput)
        {
            Customer _customer = new Customer
            {
                CustomerName    = createCustomerInput.CustomerName,
                PhysicalAddress = createCustomerInput.PhysicalAddress,
                Town            = createCustomerInput.Town,
                PostalCode      = createCustomerInput.PostalCode,
                Province        = createCustomerInput.Province,
                Telephone       = createCustomerInput.Telephone,
                Mobile          = createCustomerInput.Mobile,
                Email           = createCustomerInput.Email
            };
            await db.Customers.AddAsync(_customer);

            await db.SaveChangesAsync();

            return(_customer);
        }
        public async Task <ValidationResult> ValidateCreateCustomer(CreateCustomerInput input)
        {
            ValidationResult validationResult = new();

            if (string.IsNullOrWhiteSpace(input.Name))
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Name), "Debe ingresar un nombre."));
            }
            if (string.IsNullOrWhiteSpace(input.LastName))
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Name), "Debe ingresar un apellido."));
            }
            if (string.IsNullOrWhiteSpace(input.Email))
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "Debe ingresar un email."));
            }
            else if (!input.Email.IsEmail())
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "Debe ingresar un email valido."));
            }

            if (input.Picture is null)
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Picture), "Debe ingresar una foto de perfil."));
            }

            if (!string.IsNullOrWhiteSpace(input.Email) && input.Email.IsEmail())
            {
                Customer customer = await _customerRepository.GetCustomer(input.Email);

                if (customer is not null)
                {
                    validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "ya existe un cliente con el mismo email."));
                }
            }

            return(validationResult);
        }
        public async Task CreateCustomer(CreateCustomerInput input)
        {
            // var streetAddress = this.streetAddressRepository.
            var streetAddress = this.streetAddressRepository.GetAll().Where(sa => sa.Name.Contains(input.StreetAddressName));

            var customer = input.MapTo <Customer>();

            if (streetAddress.Count() == 0)
            {
                //var streetAddress = new StreetAddress() { Name = input.StreetAddressName };
                //var streetAddressMap = streetAddress.MapTo<StreetAddress>();
                customer.StreetAddressId = this.streetAddressRepository.InsertAndGetId(new StreetAddress()
                {
                    Name = input.StreetAddressName
                });
            }
            else
            {
                customer.StreetAddressId = streetAddress.FirstOrDefault().Id;
            }

            await this.customerRepository.InsertAsync(customer);
        }
示例#13
0
        public async Task <IActionResult> Create(CreateCustomerInput input)
        {
            var result = await _service.CreateCustomerAsync(input);

            return(new OperationActionResult(result));
        }
示例#14
0
        public async Task <Customer> CreateCustomer([Service] CustomerRepository repository, CreateCustomerInput input)
        {
            var customer = new Customer
            {
                Firstname = input.Firstname,
                Lastname  = input.Lastname
            };
            var result = await repository.Add(customer);

            return(result);
        }
示例#15
0
 public async Task CreateCustomer(CreateCustomerInput input)
 {
     var customer = ObjectMapper.Map <Customer>(input);
     await _customerRepository.InsertAsync(customer);
 }