/// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="merchantBalanceModel">The merchant balance model.</param>
        /// <returns></returns>
        public MerchantBalanceHistoryListViewModel ConvertFrom(List <MerchantBalanceHistory> merchantBalanceModel)
        {
            if (merchantBalanceModel == null)
            {
                return(new MerchantBalanceHistoryListViewModel());
            }

            MerchantBalanceHistoryListViewModel viewModel = new MerchantBalanceHistoryListViewModel();

            viewModel.MerchantBalanceHistoryViewModels = new List <MerchantBalanceHistoryViewModel>();

            merchantBalanceModel.ForEach(h =>
            {
                viewModel.MerchantBalanceHistoryViewModels.Add(new MerchantBalanceHistoryViewModel
                {
                    MerchantId    = h.MerchantId,
                    Balance       = h.Balance,
                    ChangeAmount  = h.ChangeAmount,
                    EntryDateTime = h.EntryDateTime,
                    EntryType     = h.EntryType,
                    EstateId      = h.EstateId,
                    EventId       = h.EventId,
                    In            = h.In,
                    Out           = h.Out,
                    Reference     = h.Reference,
                    TransactionId = h.TransactionId
                });
            });

            return(viewModel);
        }
        public async Task <IActionResult> GetMerchantBalanceHistoryAsJson([FromQuery] Guid merchantId,
                                                                          CancellationToken cancellationToken)
        {
            try
            {
                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                // Start and End Date
                // Set the defaults
                DateTime startDateTime = DateTime.Now.AddDays(-1).Date;
                DateTime endDateTime   = DateTime.Now.Date;

                if (this.HttpContext.Request.Form.ContainsKey("startDate"))
                {
                    startDateTime = DateTime.ParseExact(this.HttpContext.Request.Form["startDate"], "yyyy-MM-dd", null);
                }

                if (this.HttpContext.Request.Form.ContainsKey("endDate"))
                {
                    endDateTime = DateTime.ParseExact(this.HttpContext.Request.Form["endDate"], "yyyy-MM-dd", null);
                    endDateTime = endDateTime.AddDays(1);
                }

                List <MerchantBalanceHistory> merchantBalanceHistory =
                    await this.ApiClient.GetMerchantBalanceHistory(accessToken, this.User.Identity as ClaimsIdentity, merchantId, startDateTime, endDateTime, cancellationToken);

                MerchantBalanceHistoryListViewModel viewModel = this.ViewModelFactory.ConvertFrom(merchantBalanceHistory);

                // Search Value from (Search box)
                String searchValue = this.HttpContext.Request.Form["search[value]"].FirstOrDefault();
                Expression <Func <MerchantBalanceHistoryViewModel, Boolean> > whereClause = m => m.Reference.Contains(searchValue, StringComparison.OrdinalIgnoreCase);

                return(this.Json(Helpers.GetDataForDataTable(this.Request.Form, viewModel.MerchantBalanceHistoryViewModels, whereClause)));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                return(this.Json(Helpers.GetErrorDataForDataTable <String>("Error getting merchant balance history")));
            }
        }