Пример #1
0
        public async Task <bool> CreateTransfer(TransferDto transferDto, string login, CancellationToken cancellationToken)
        {
            string stat = "in progress";

            if (transferDto.executionDate.CompareTo(transferDto.sendingDate) == 0)
            {
                stat = "executed";
            }
            if (transferDto.executionDate.CompareTo(transferDto.sendingDate) < 0)
            {
                return(false);
            }

            return(await repository.CreateTransfer(new Transfer
            {
                Sending_Date = transferDto.sendingDate,
                Execution_Date = transferDto.executionDate,
                Title = transferDto.title,
                Receiver = transferDto.receiver,
                Description = transferDto.description,
                Status = stat,
                Amount = transferDto.amount,
                Sender_Bank_Account = transferDto.senderBankAccountId,
                Receiver_Bank_Account = transferDto.receiverBankAccountId
            }, cancellationToken));
        }
Пример #2
0
        public void Transfer(int productId, int sourceLocationId, int destinationLocationId, int quantity)
        {
            var productItem          = productRepository.GetProduct(productId);
            var originalLocationItem = locationRepository.GetLocation(sourceLocationId);
            var newLocationItem      = locationRepository.GetLocation(destinationLocationId);

            if (productItem == null)
            {
                throw new ApplicationException("Inventory item not found.");
            }

            if (originalLocationItem == null)
            {
                throw new ApplicationException("Source location not found.");
            }

            if (newLocationItem == null)
            {
                throw new ApplicationException("Destination location not found.");
            }

            try
            {
                transferRepository.CreateTransfer(productId, sourceLocationId, destinationLocationId, quantity);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Transfer reverted. Please validate and try again.");
            }
        }
        public async Task <IActionResult> Create(TransferViewModel transferViewModel)
        {
            if (ModelState.IsValid)
            {
                var accessToken = await HttpContext.GetTokenAsync("access_token");

                var result = await _transferRepository.CreateTransfer(
                    "https://localhost:44382/Income/Create", accessToken, transferViewModel);

                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "Income"));
                }
            }
            return(View(transferViewModel));
        }