public async Task Execute(WithdrawInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            IDebit debit = account.Withdraw(_entityFactory, input.Amount);

            if (debit == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not have enough funds to withdraw {input.Amount}.");
                return;
            }

            await _accountRepository.Update(account, debit);

            await _unitOfWork.Save();

            WithdrawOutput output = new WithdrawOutput(
                debit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
        public async Task Execute(RefundInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            IDebit debit = account.Withdraw(_entityFactory, input.Amount);

            if (debit == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not have enough funds to withdraw {input.Amount}.");
                return;
            }

            await _accountRepository.Update(account, debit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new Shared.Events.WithdrawCompleted()
            {
                AccountId = input.AccountId, Amount = input.Amount.ToMoney().ToDecimal()
            });

            await _unitOfWork.Save();

            RefundOutput output = new RefundOutput(
                debit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
Exemple #3
0
        public async Task Execute(TransferInput input)
        {
            IAccount originAccount = await _accountRepository.Get(input.OriginAccountId);

            if (originAccount == null)
            {
                _outputHandler.Error($"The account {input.OriginAccountId} does not exist or is already closed.");
                return;
            }

            IAccount destinationAccount = await _accountRepository.Get(input.DestinationAccountId);

            if (destinationAccount == null)
            {
                _outputHandler.Error($"The account {input.DestinationAccountId} does not exist or is already closed.");
                return;
            }

            IDebit  debit  = originAccount.Withdraw(_entityFactory, input.Amount);
            ICredit credit = destinationAccount.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(originAccount, debit);

            await _accountRepository.Update(destinationAccount, credit);

            await _unitOfWork.Save();

            TransferOutput output = new TransferOutput(
                debit,
                originAccount.GetCurrentBalance(),
                input.OriginAccountId,
                input.DestinationAccountId);

            _outputHandler.Default(output);
        }
        public async Task Execute(RegisterInput input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var customer = _entityFactory.NewCustomer(input.SSN, input.Name);
            var account  = _entityFactory.NewAccount(customer);

            ICredit credit = account.Deposit(_entityFactory, input.InitialAmount);

            if (credit == null)
            {
                _outputHandler.Error("An error happened when depositing the amount.");
                return;
            }

            customer.Register(account);

            await _customerRepository.Add(customer);

            await _accountRepository.Add(account, credit);

            await _unitOfWork.Save();

            RegisterOutput output = new RegisterOutput(customer, account);

            _outputHandler.Standard(output);
        }
        public async Task ExecuteAsync(string userId, int postId)
        {
            var post = await _postRepository.GetAsync(postId);

            if (post is null || post.UserId != userId)
            {
                _outputPort.NotFound();

                return;
            }

            var result = await _imageService.RemoveAsync(post.Image);

            if (result.IsT1)
            {
                _notification.Add("Detail", result.AsT1.Value);
                _outputPort.Error();

                return;
            }

            await _postRepository.RemoveAsync(postId);

            _outputPort.Ok();
        }
        public async Task Execute(DepositInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new Shared.Events.DepositCompleted()
            {
                AccountId = input.AccountId, Amount = input.Amount.ToMoney().ToDecimal()
            });

            await _unitOfWork.Save();

            DepositOutput output = new DepositOutput(
                credit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
        public async Task Execute(CloseAccountInput closeAccountInput)
        {
            IAccount account = await _accountRepository.Get(closeAccountInput.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account '{closeAccountInput.AccountId}' does not exist or is already closed.");
                return;
            }

            if (account.IsClosingAllowed())
            {
                await _accountRepository.Delete(account);

                // Publish the event to the enterprice service bus
                await _serviceBus.PublishEventAsync(new Shared.Events.CloseAccountCompleted()
                {
                    AccountId = account.Id
                });

                await _unitOfWork.Save();
            }

            var closeAccountOutput = new CloseAccountOutput(account);

            _outputHandler.Default(closeAccountOutput);
        }
        public async Task ExecuteAsync(string userId, string title, string content, Stream image, string extension)
        {
            var post = new Post
            {
                Title     = title,
                Content   = content,
                CreatedAt = DateTime.Now,
                UserId    = userId,
                Image     = $"{Guid.NewGuid()}{extension}"
            };

            var result = await _imageService.UploadAsync(post.Image, image);

            if (result.IsT1)
            {
                _notification.Add("Detail", result.AsT1.Value);
                _outputPort.Error();

                return;
            }

            await _postRepository.AddAsync(post);

            _outputPort.Ok();
        }
Exemple #9
0
 public void Execute(CustomerDeleteRequest request)
 {
     try
     {
         var ret = customerWriteOnlyRepository.Delete(request.CustomerId);
         if (ret == 0)
         {
             output.Error($"Error on process Delete Customer");
             return;
         }
         output.Standard(request.CustomerId);
     }
     catch (Exception ex)
     {
         output.Error($"Error on process: {ex.Message}");
     }
 }
        public async Task Execute(TransferInput input)
        {
            IAccount originAccount = await _accountRepository.Get(input.OriginAccountId);

            if (originAccount == null)
            {
                _outputHandler.Error($"The account {input.OriginAccountId} does not exist or is already closed.");
                return;
            }

            IAccount destinationAccount = await _accountRepository.Get(input.DestinationAccountId);

            if (destinationAccount == null)
            {
                _outputHandler.Error($"The account {input.DestinationAccountId} does not exist or is already closed.");
                return;
            }

            IDebit  debit  = originAccount.Withdraw(_entityFactory, input.Amount);
            ICredit credit = destinationAccount.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(originAccount, debit);

            await _accountRepository.Update(destinationAccount, credit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new Shared.Events.TransferCompleted()
            {
                OriginalAccountId = originAccount.Id, DestinationAccountId = destinationAccount.Id, Amount = input.Amount.ToMoney().ToDecimal()
            });

            await _unitOfWork.Save();

            TransferOutput output = new TransferOutput(
                debit,
                originAccount.GetCurrentBalance(),
                input.OriginAccountId,
                input.DestinationAccountId);

            _outputHandler.Default(output);
        }
Exemple #11
0
 public void Execute(CustomerSaveRequest request)
 {
     try
     {
         validateHandler.ProcessRequest(request);
         output.Standard(request.Customer.Id);
     }
     catch (Exception ex)
     {
         output.Error($"Error on process: {ex.Message}");
     }
 }
Exemple #12
0
 public void Execute()
 {
     try
     {
         var customers = customerReadOnlyRepository.GetAll();
         output.Standard(customers);
     }
     catch (System.Exception ex)
     {
         output.Error($"Error on process: {ex.Message}");
     }
 }
Exemple #13
0
        public async Task Execute(RegisterInput input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var customer = _entityFactory.NewCustomer(input.SSN, input.Name);
            var account  = _entityFactory.NewAccount(customer);

            ICredit credit = account.Deposit(_entityFactory, input.InitialAmount);

            if (credit == null)
            {
                _outputHandler.Error("An error happened when depositing the amount.");
                return;
            }

            customer.Register(account);

            // Call to an external Web Api

            await _customerRepository.Add(customer);

            await _accountRepository.Add(account, credit);

            // Publish the event to the enterprice service bus
            await _serviceBus.PublishEventAsync(new RegistrationCompleted()
            {
                CustomerId = customer.Id, AccountId = account.Id, CreditId = credit.Id
            });

            await _unitOfWork.Save();


            RegisterOutput output = new RegisterOutput(customer, account);

            _outputHandler.Standard(output);
        }
Exemple #14
0
        public void Execute()
        {
            IEnumerable <domain.WeatherForecast> weathers;

            try
            {
                weathers = getWeather.Get();
                output.Standard(weathers);
            }
            catch (System.Exception e)
            {
                output.Error(e.Message);
            }
        }
        public async Task Handle(int input, IOutputPort <TodoDetailsOutputModel> output)
        {
            var todo = await todoGateway.Details(input);

            if (todo == null)
            {
                output.Error($"Todo with id: {input} does not exist in our database!");
            }
            else
            {
                var username    = userService.GetUserName(todo.UserId);
                var outputModel = new TodoDetailsOutputModel(todo.Title, todo.Content, username);
                output.Success(outputModel);
            }
        }
Exemple #16
0
 public void Execute(CustomerGetRequest request)
 {
     try
     {
         var customer = customerReadOnlyRepository.GetById(request.CustomerId);
         if (customer == null)
         {
             output.NotFound($"Not found customer with id: {request.CustomerId}");
             return;
         }
         output.Standard(customer);
     }
     catch (Exception ex)
     {
         output.Error($"Error on process: {ex.Message}");
     }
 }
Exemple #17
0
        public async Task Execute(CloseAccountInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            if (account.IsClosingAllowed())
            {
                await _accountRepository.Delete(account);
            }

            var output = new CreateAccountOutput(account);

            _outputHandler.Default(output);
        }
        public async Task Execute(AirlineInput airlineInput)
        {
            if (airlineInput == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var airline = new Airline()
            {
                Name        = airlineInput.Airline.Name,
                Description = airlineInput.Airline.Description,
                Planes      = airlineInput.Airline.Planes
            };
            await _airlineRepository.Add(airline);

            var airlineOutput = new AirlineOutput(airline);

            _outputHandler.Standard(airlineOutput);
        }
Exemple #19
0
        public async Task Handle(int input, IOutputPort <ArticleDetailsOutputModel> output)
        {
            var article = await this.articleGateway.Details(input);

            if (article == null)
            {
                this.logger.LogInformation($"Article {input} could not be found.");
                output.Error();
                return;
            }

            var author = this.userProvider.GetUserName(article.UserId);

            output.Success(new ArticleDetailsOutputModel(
                               article.Id,
                               article.Title,
                               article.Content,
                               article.IsPublic,
                               article.PublishedOn,
                               author));
        }
        public async Task Execute(DestinationInput input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var destinations = input.Destinations.Select(d =>
                                                         new Destination()
            {
                AirlineId = d.AirlineId,
                Country   = d.Country
            }).ToList();

            await _destinationRepository.Add(destinations);

            var airlineOutput = new DestinationOutput(destinations);

            _outputHandler.Standard(airlineOutput);
        }
Exemple #21
0
        public async Task Execute(DepositInput input)
        {
            IAccount account = await _accountRepository.Get(input.AccountId);

            if (account == null)
            {
                _outputHandler.Error($"The account {input.AccountId} does not exist or is already closed.");
                return;
            }

            ICredit credit = account.Deposit(_entityFactory, input.Amount);

            await _accountRepository.Update(account, credit);

            await _unitOfWork.Save();

            DepositOutput output = new DepositOutput(
                credit,
                account.GetCurrentBalance()
                );

            _outputHandler.Default(output);
        }
Exemple #22
0
        public async Task Execute(CreateClientInput input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var client = new User()
            {
                Name        = input.Name,
                Surname     = input.Surname,
                PhoneNumber = input.PhoneNumber,
                Email       = input.Email,
                Password    = CryptUtils.EncryptPassword(input.Password),
                Role        = Role.Client
            };
            await _clientRepository.Register(client);

            var createClientOutput = new CreateClientOutput(client.Name, client.Surname, client.PhoneNumber, client.Email);

            _outputHandler.Standard(createClientOutput);
        }
        public async Task Execute(CreateOrderInput input)
        {
            if (input == null)
            {
                _outputHandler.Error("Input is null.");
                return;
            }

            var parcel = new Parcel()
            {
                Name        = input.ParcelName,
                Description = input.ParcelDescription
            };
            var Parcel = await _parcelRepository.AddParcel(parcel);

            var order = new Order()
            {
                SenderId             = input.SenderId,
                RecipientName        = input.RecipientName,
                RecipientSurname     = input.RecipientSurname,
                RecipientPhonenumber = input.RecipientPhoneNumber,
                ParcelId             = Parcel.Id,
                Status = input.Status
            };
            await _orderRepository.RegisterOrder(order);

            var createOrderOutput = new CreateOrderOutput(
                input.SenderId,
                input.RecipientName,
                input.RecipientSurname,
                input.RecipientPhoneNumber,
                Parcel,
                input.Status
                );

            _outputHandler.Standard(createOrderOutput);
        }