Ejemplo n.º 1
0
        public async Task <IActionResult> GetTransactionsByMerchantAsJson([FromQuery] Int32 merchantCount,
                                                                          [FromQuery] SortDirection sortDirection,
                                                                          [FromQuery] SortField sortField,
                                                                          [FromQuery] DateTime startDate,
                                                                          [FromQuery] DateTime endDate,
                                                                          CancellationToken cancellationToken)
        {
            try
            {
                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                DataByMerchantModel model = await this.ApiClient.GetTransactionsByMerchant(accessToken,
                                                                                           this.User.Identity as ClaimsIdentity,
                                                                                           startDate,
                                                                                           endDate,
                                                                                           merchantCount,
                                                                                           sortDirection,
                                                                                           sortField,
                                                                                           cancellationToken);

                DataByMerchantViewModel viewModel = this.ViewModelFactory.ConvertFrom(model);

                return(this.Json(viewModel));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                throw;
            }
        }
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public DataByMerchantViewModel ConvertFrom(DataByMerchantModel model)
        {
            if (model == null)
            {
                return(new DataByMerchantViewModel());
            }

            DataByMerchantViewModel viewModel = new DataByMerchantViewModel();

            viewModel.DataMerchantViewModels = new List <DataMerchantViewModel>();


            foreach (DataMerchantModel transactionMerchantModel in model.DataMerchantModels)
            {
                viewModel.DataMerchantViewModels.Add(new DataMerchantViewModel
                {
                    CurrencyCode = transactionMerchantModel.CurrencyCode,
                    MerchantId   = transactionMerchantModel.MerchantId,
                    MerchantName = transactionMerchantModel.MerchantName,
                    Count        = transactionMerchantModel.Count,
                    Value        = transactionMerchantModel.Value
                });
            }

            return(viewModel);
        }