diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs index 45cec0f..c10d714 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; + using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using BusinessLogic.Models; @@ -11,6 +12,7 @@ using EstateReportingAPI.DataTransferObjects; using EstateReportingAPI.DataTrasferObjects; using Factories; + using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Services; @@ -48,8 +50,12 @@ public HomeController(IApiClient apiClient, [HttpPost] public async Task GetComparisonDatesAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List response = - await this.ApiClient.GetComparisonDates(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), cancellationToken); + await this.ApiClient.GetComparisonDates(accessToken, estateId, cancellationToken); List<(String value, String text)> viewModels = ViewModelFactory.ConvertFrom(response); @@ -58,11 +64,15 @@ public async Task GetComparisonDatesAsJson(CancellationToken canc [HttpPost] public async Task GetComparisonDateSettlementAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd"); String comparisonDateLabel = QueryStringHelper.GetValueFromQueryString(this.Request.QueryString.Value, "comparisonDateLabel"); TodaysSettlementModel response = - await this.ApiClient.GetTodaysSettlement(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken); + await this.ApiClient.GetTodaysSettlement(accessToken, estateId, comparisonDate, cancellationToken); TodaysSettlementViewModel viewModel = ViewModelFactory.ConvertFrom(response, comparisonDateLabel); @@ -71,11 +81,15 @@ public async Task GetComparisonDateSettlementAsJson(CancellationT [HttpPost] public async Task GetComparisonDateTransactionsAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd"); String comparisonDateLabel = QueryStringHelper.GetValueFromQueryString(this.Request.QueryString.Value, "comparisonDateLabel"); TodaysSalesModel response = - await this.ApiClient.GetTodaysSales(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken); + await this.ApiClient.GetTodaysSales(accessToken, estateId, comparisonDate, cancellationToken); TodaysSalesViewModel viewModel = ViewModelFactory.ConvertFrom(response, comparisonDateLabel); @@ -84,10 +98,14 @@ public async Task GetComparisonDateTransactionsAsJson(Cancellatio [HttpPost] public async Task GetSalesCountByHourAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd"); List response = - await this.ApiClient.GetTodaysSalesCountByHour(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken); + await this.ApiClient.GetTodaysSalesCountByHour(accessToken, estateId, comparisonDate, cancellationToken); List viewModels = ViewModelFactory.ConvertFrom(response); viewModels = viewModels.OrderBy(r => r.Hour).ToList(); @@ -102,10 +120,14 @@ public async Task GetSalesCountByHourAsJson(CancellationToken can [HttpPost] public async Task GetSalesValueByHourAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd"); List response = - await this.ApiClient.GetTodaysSalesValueByHour(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken); + await this.ApiClient.GetTodaysSalesValueByHour(accessToken, estateId, comparisonDate, cancellationToken); List viewModels = ViewModelFactory.ConvertFrom(response); viewModels = viewModels.OrderBy(r => r.Hour).ToList(); @@ -120,7 +142,11 @@ public async Task GetSalesValueByHourAsJson(CancellationToken can [HttpPost] public async Task GetYesterdaysSettlementAsJson(CancellationToken cancellationToken){ - TodaysSettlementModel response = await this.ApiClient.GetTodaysSettlement(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), DateTime.Now, cancellationToken); + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + + TodaysSettlementModel response = await this.ApiClient.GetTodaysSettlement(accessToken, estateId, DateTime.Now, cancellationToken); TodaysSettlementViewModel viewModel = ViewModelFactory.ConvertFrom(response); diff --git a/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs b/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs index 773aff6..b5191be 100644 --- a/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs +++ b/EstateAdministrationUI/Areas/Estate/Controllers/ReportingController.cs @@ -9,6 +9,7 @@ namespace EstateAdministrationUI.Areas.Estate.Controllers using System.Threading; using System.Threading.Tasks; using System.Web; + using Azure.Core; using BusinessLogic.Models; using Common; using EstateReportingAPI.Client; @@ -83,10 +84,14 @@ public async Task GetTransactionAnalysis(CancellationToken cancel [HttpPost] public async Task GetComparisonDateTransactionsAsJson(CancellationToken cancellationToken) { + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + var comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(Request.QueryString.Value, "comparisonDate"); var comparisonDateLabel = QueryStringHelper.GetValueFromQueryString(Request.QueryString.Value, "comparisonDateLabel"); - TodaysSalesModel response = await this.ApiClient.GetTodaysSales(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken); + TodaysSalesModel response = await this.ApiClient.GetTodaysSales(accessToken, estateId, comparisonDate, cancellationToken); var viewModel = ViewModelFactory.ConvertFrom(response, comparisonDateLabel); @@ -96,11 +101,15 @@ public async Task GetComparisonDateTransactionsAsJson(Cancellatio [HttpPost] public async Task GetComparisonDateFailedTransactionsDueToLowCreditAsJson(CancellationToken cancellationToken) { + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + var comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(Request.QueryString.Value, "comparisonDate"); var comparisonDateLabel = QueryStringHelper.GetValueFromQueryString(Request.QueryString.Value, "comparisonDateLabel"); TodaysSalesModel response = - await this.ApiClient.GetTodaysFailedSales(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"),"1009", comparisonDate, cancellationToken); + await this.ApiClient.GetTodaysFailedSales(accessToken, estateId, "1009", comparisonDate, cancellationToken); TodaysSalesViewModel viewModel = ViewModelFactory.ConvertFrom(response, comparisonDateLabel); @@ -110,8 +119,12 @@ public async Task GetComparisonDateFailedTransactionsDueToLowCred [HttpPost] public async Task GetMerchantKpisAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + MerchantKpiModel response = - await this.ApiClient.GetMerchantKpi(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), cancellationToken); + await this.ApiClient.GetMerchantKpi(accessToken, estateId, cancellationToken); MerchantKpiViewModel viewModel = ViewModelFactory.ConvertFrom(response); return this.Json(viewModel); @@ -119,11 +132,15 @@ public async Task GetMerchantKpisAsJson(CancellationToken cancell [HttpPost] public async Task GetBottom3MerchantsBySalesValueAsJson(CancellationToken cancellationToken){ + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List merchants = new List(); List response = - await this.ApiClient.GetTopBottomMerchantData(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22") - , BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); + await this.ApiClient.GetTopBottomMerchantData(accessToken, estateId + , BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); var viewModel = ViewModelFactory.ConvertFrom(response); @@ -135,11 +152,15 @@ await this.ApiClient.GetTopBottomMerchantData(null, Guid.Parse("435613AC-A468-47 [HttpPost] public async Task GetBottom3OperatorsBySalesValueAsJson(CancellationToken cancellationToken) { + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List operators = new List(); var response = - await this.ApiClient.GetTopBottomOperatorData(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22") - , BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); + await this.ApiClient.GetTopBottomOperatorData(accessToken, estateId + , BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); var viewModel = ViewModelFactory.ConvertFrom(response); @@ -151,11 +172,14 @@ await this.ApiClient.GetTopBottomOperatorData(null, Guid.Parse("435613AC-A468-47 [HttpPost] public async Task GetBottom3ProductsBySalesValueAsJson(CancellationToken cancellationToken) { + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List products = new List(); var response = - await this.ApiClient.GetTopBottomProductData(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22") - , BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); + await this.ApiClient.GetTopBottomProductData(accessToken, estateId, BusinessLogic.Models.TopBottom.Bottom, 3, cancellationToken); var viewModel = ViewModelFactory.ConvertFrom(response); @@ -168,10 +192,14 @@ await this.ApiClient.GetTopBottomProductData(null, Guid.Parse("435613AC-A468-47A [HttpPost] public async Task GetComparisonDatesAsJson(CancellationToken cancellationToken) { + String accessToken = await this.HttpContext.GetTokenAsync("access_token"); + + Guid estateId = Helpers.GetClaimValue(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType); + List<(String value, String text)> datesList = new List<(String, String)>(); List response = - await this.ApiClient.GetComparisonDates(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), cancellationToken); + await this.ApiClient.GetComparisonDates(accessToken, estateId, cancellationToken); List<(String value, String text)> viewModels = ViewModelFactory.ConvertFrom(response); return this.Json(viewModels);