コード例 #1
0
        public async Task <IActionResult> Delete(int id)
        {
            ActionResult         result;
            var                  input = new DeleteCustomerInput();
            DeleteCustomerOutput output;

            try
            {
                input.CustomerId = id;
                output           = await this._facadeOrchestratorCustomer.DeleteCustomerAsync(input);

                if (output.Success)
                {
                    result = Ok(output.Success);
                }
                else
                {
                    result = BadRequest(output.GetJoinedErrors());
                }
            }
            catch (Exception ex)
            {
                result = BadRequest(ex);
            }

            return(result);
        }
コード例 #2
0
        public async Task <OperationResult> DeleteCustomerAsync(DeleteCustomerInput input)
        {
            var validationResult = await _customerValidator.ValidateDeleteCustomer(input);

            if (validationResult.IsSuccess)
            {
                var entity = await _customerRepository.GetCustomer(input.Email);

                await _customerRepository.RemoveAsync(entity);

                return(OperationResult.Success());
            }

            return(OperationResult <CustomerDto> .Fail(validationResult));
        }
コード例 #3
0
        public async Task <ValidationResult> ValidateDeleteCustomer(DeleteCustomerInput input)
        {
            ValidationResult validationResult = new();

            if (string.IsNullOrWhiteSpace(input.Email))
            {
                validationResult.Messages.Add(new(nameof(DeleteCustomerInput.Email), "Debe ingresar un email."));
            }
            else if (!input.Email.IsEmail())
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "Debe ingresar un email valido."));
            }
            else
            {
                Customer customer = await _customerRepository.GetCustomer(input.Email);

                if (customer is null)
                {
                    validationResult.Messages.Add(new(nameof(DeleteCustomerInput.Email), "no existe un cliente con este email."));
                }
            }

            return(validationResult);
        }
コード例 #4
0
        public async Task <DeleteCustomerOutput> DeleteCustomerAsync(DeleteCustomerInput input)
        {
            DeleteCustomerOutput output = await Orchestrator.Execute <DeleteCustomer, DeleteCustomerInput, DeleteCustomerOutput, DeleteCustomerValidator>(_customerManager, input);

            return(output);
        }