public async Task <IResult <Guid> > CreateCustomer(CreateCustomerCommand createCommand)
        {
            if (createCommand == null)
            {
                return(await Result <Guid> .FailAsync("customer fields"));
            }

            var validator = createCommand.Validate();

            if (!validator.IsValid)
            {
                return(await Result <Guid> .FailValidationAsync(validator.Errors));
            }

            var customer = await _service.GetCustomerByEmail(createCommand.Email);

            if (customer != null)
            {
                return(await Result <Guid> .FailAsync("customer already exists"));
            }

            var id = await _service.CreateCustomer(createCommand);

            if (id == Guid.Empty)
            {
                return(await Result <Guid> .FailAsync("unable to create customer"));
            }

            return(await Result <Guid> .CreatedAsync(id));
        }
 private int AddCustomer()
 {
     return(_customersService.CreateCustomer(new Customer
     {
         Company = "Test Company Name",
         BillAddr1 = "16 Dog Lane",
         BillAddr2 = "Suite D",
         BillCity = "Storrs",
         BillState = "CT"
     }).Id);
 }
Пример #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _customersService.CreateCustomer(Customer);

            return(RedirectToPage("./Index"));
        }
        private int TakeCustomerId()
        {
            var id = _customersService.CreateCustomer(new Customer
            {
                Company   = "Test Company Name",
                BillAddr1 = "16 Dog Lane",
                BillAddr2 = "Suite D",
                BillCity  = "Storrs",
                BillState = "CT",
            }).Id;

            return(id);
        }
Пример #5
0
        public async Task <ActionResult <CustomerAPIModel> > CreateCustomer(CustomerAPIModel customer)
        {
            var validator        = new CustomerValidator();
            var validationResult = await validator.ValidateAsync(customer);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var customerModel = _mapper.Map <CustomerAPIModel, Customers>(customer);
            await _customersService.CreateCustomer(customerModel);

            return(Ok(customer));
        }
Пример #6
0
        public void Run()
        {
            var customer = new Customer
            {
                Company   = "Test Company Name",
                BillAddr1 = "16 Dog Lane",
                BillAddr2 = "Suite D",
                BillCity  = "Storrs",
            };

            var result = _service.CreateCustomer(customer);

            if (!result.IsSuccess())
            {
                throw new Exception("Create customer failed.");
            }

            Console.WriteLine("Customer created with id: " + result.Id);
        }
Пример #7
0
        private void CreateCustomer()
        {
            var customer = new Customer
            {
                Company        = "Test Company Name",
                BillAddr1      = "16 Dog Lane",
                BillAddr2      = "Suite D",
                BillCity       = "Storrs",
                SuperUserName  = "******",
                SuperUserEmail = "*****@*****.**"
            };

            var result = _service.CreateCustomer(customer);

            if (!result.IsSuccess())
            {
                throw new Exception("Create customer failed.");
            }

            Console.WriteLine("Customer created with id: " + result.Id);
        }
Пример #8
0
 public CustomerDto CreateCustomer([FromBody] CreateCustomerDto createCustomerDto)
 {
     return(customersService.CreateCustomer(createCustomerDto));
 }