Exemple #1
0
        public async Task <ApplicationResponse> When(DeleteCustomer command)
        {
            var customer = await _customerRepository.Get(command.Id);

            if (customer == null)
            {
                return(ApplicationResponse.Fail(StatusCode.NotFound, "Customer not found"));
            }

            await _customerRepository.Delete(customer.Id);

            return(ApplicationResponse.Success());
        }
Exemple #2
0
        public async Task <ApplicationResponse> When(Deposit command)
        {
            var customer = await _customerRepository.Get(command.Id);

            if (customer == null)
            {
                return(ApplicationResponse.Fail(StatusCode.NotFound, "Customer not found"));
            }

            customer.Account.Deposit(command.Balance);

            await _customerRepository.Update(customer);

            return(ApplicationResponse.Success());
        }
Exemple #3
0
        public async Task <ApplicationResponse> When(UpdateProfile command)
        {
            var customer = await _customerRepository.Get(command.Id);

            if (customer == null)
            {
                return(ApplicationResponse.Fail(StatusCode.NotFound, "Customer not found"));
            }

            customer.UpdateProfile(command.Email, command.Firstname, command.Lastname);

            await _customerRepository.Update(customer);

            return(ApplicationResponse.Success());
        }
Exemple #4
0
        public async Task <ApplicationResponse <Guid> > When(CreateCustomer command)
        {
            var customer = new CustomerBuilder().WithEmail(command.Email)
                           .WithFirstname(command.Firstname)
                           .WithLastname(command.Lastname)
                           .WithBalance(command.Balance)
                           .BuildCreateCustomer();

            if (customer == null)
            {
                return(ApplicationResponse <Guid> .Fail(StatusCode.BadRequest, "could not create create customer"));
            }

            await _customerRepository.Create(customer);

            return(ApplicationResponse <Guid> .Success(customer.Id));
        }