/// <summary>
        /// Calculates total fees.
        /// </summary>
        /// <remarks>
        ///		Calculates Rental rate fee, Cancellation fee from all reservations for specified client.
        ///
        ///		NOTE: The calculation includes only the rental fees that come from rezervations that are completed or cancelled.
        /// </remarks>
        /// <param name="clientId">Client identifier.</param>
        /// <returns>Client balance model.</returns>
        public ClientBalanceModel GetClientAccountBalance(int clientId)
        {
            if (clientId < 1)
            {
                throw new InvalidParameterException(nameof(clientId));
            }

            var dbClientAccount = this.dbContext.ClientAccounts.SingleOrDefault(x => x.ClientId == clientId);

            if (dbClientAccount == null)
            {
                throw new NotFoundException("Client account not found.");
            }

            var clientBalanceModel = new ClientBalanceModel
            {
                ClientAccount = dbClientAccount.ToModel(),
            };

            var dbClientRezervations = this.dbContext.Rezervations.Where(x => x.ClientId == clientId).ToList();

            if (!dbClientRezervations.Any())
            {
                return(clientBalanceModel);
            }

            clientBalanceModel.TotalRentalFee       = dbClientRezervations.Where(x => x.IsReturned).Sum(x => x.RentaltFee);
            clientBalanceModel.TotalCancellationFee = dbClientRezervations.Where(x => x.CancellationFee.HasValue && x.IsCancelled).Sum(x => x.CancellationFee.Value);
            clientBalanceModel.TotalFees            = clientBalanceModel.TotalCancellationFee + clientBalanceModel.TotalRentalFee;

            return(clientBalanceModel);
        }
 public static ClientBalanceResponseModel Create(ClientBalanceModel src)
 {
     return(new ClientBalanceResponseModel
     {
         AssetId = src.AssetId,
         Balance = src.Balance,
         Reserved = src.Reserved
     });
 }
Example #3
0
        public static Task <ClientBalanceModel> GetAllBalancesForClientByAssetId()
        {
            var balance = new ClientBalanceModel()
            {
                AssetId = "USD",
                Balance = 1000
            };

            return(Task.FromResult(balance));
        }
Example #4
0
        public async Task <IActionResult> GetClientBalancesByAssetId(string clientId, string assetId)
        {
            var wallet = await _cachedWalletsRepository.GetAsync(clientId, assetId);

            if (wallet == null)
            {
                return(NotFound());
            }

            return(Ok(ClientBalanceModel.Create(wallet)));
        }
        public async Task <ClientBalanceModel> GetClientBalanceByAssetId(
            AutorestClient.Models.ClientBalanceByAssetIdModel model)
        {
            var response = await _service.GetClientBalancesByAssetIdAsync(model.ClientId, model.AssetId);

            if (response == null)
            {
                return(null);
            }

            if (response is ErrorResponse error)
            {
                throw new Exception(error.ErrorMessage);
            }

            if (response is ClientBalanceResponseModel result)
            {
                return(ClientBalanceModel.Create(result));
            }

            throw new Exception(UexpectedApiResponse);
        }