Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions EstateAdministrationUI/Areas/Estate/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -48,8 +50,12 @@ public HomeController(IApiClient apiClient,

[HttpPost]
public async Task<IActionResult> GetComparisonDatesAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

List<ComparisonDateModel> 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);

Expand All @@ -58,11 +64,15 @@ public async Task<IActionResult> GetComparisonDatesAsJson(CancellationToken canc

[HttpPost]
public async Task<IActionResult> GetComparisonDateSettlementAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(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);

Expand All @@ -71,11 +81,15 @@ public async Task<IActionResult> GetComparisonDateSettlementAsJson(CancellationT

[HttpPost]
public async Task<IActionResult> GetComparisonDateTransactionsAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(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);

Expand All @@ -84,10 +98,14 @@ public async Task<IActionResult> GetComparisonDateTransactionsAsJson(Cancellatio

[HttpPost]
public async Task<IActionResult> GetSalesCountByHourAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd");

List<TodaysSalesCountByHourModel> response =
await this.ApiClient.GetTodaysSalesCountByHour(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken);
await this.ApiClient.GetTodaysSalesCountByHour(accessToken, estateId, comparisonDate, cancellationToken);

List<HourCountViewModel> viewModels = ViewModelFactory.ConvertFrom(response);
viewModels = viewModels.OrderBy(r => r.Hour).ToList();
Expand All @@ -102,10 +120,14 @@ public async Task<IActionResult> GetSalesCountByHourAsJson(CancellationToken can

[HttpPost]
public async Task<IActionResult> GetSalesValueByHourAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

DateTime comparisonDate = QueryStringHelper.GetDateTimeValueFromQueryString(this.Request.QueryString.Value, "comparisonDate", "yyyy-MM-dd");

List<TodaysSalesValueByHourModel> response =
await this.ApiClient.GetTodaysSalesValueByHour(null, Guid.Parse("435613AC-A468-47A3-AC4F-649D89764C22"), comparisonDate, cancellationToken);
await this.ApiClient.GetTodaysSalesValueByHour(accessToken, estateId, comparisonDate, cancellationToken);

List<HourValueViewModel> viewModels = ViewModelFactory.ConvertFrom(response);
viewModels = viewModels.OrderBy(r => r.Hour).ToList();
Expand All @@ -120,7 +142,11 @@ public async Task<IActionResult> GetSalesValueByHourAsJson(CancellationToken can

[HttpPost]
public async Task<IActionResult> 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<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

TodaysSettlementModel response = await this.ApiClient.GetTodaysSettlement(accessToken, estateId, DateTime.Now, cancellationToken);

TodaysSettlementViewModel viewModel = ViewModelFactory.ConvertFrom(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,10 +84,14 @@ public async Task<IActionResult> GetTransactionAnalysis(CancellationToken cancel
[HttpPost]
public async Task<IActionResult> GetComparisonDateTransactionsAsJson(CancellationToken cancellationToken)
{
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(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);

Expand All @@ -96,11 +101,15 @@ public async Task<IActionResult> GetComparisonDateTransactionsAsJson(Cancellatio
[HttpPost]
public async Task<IActionResult> GetComparisonDateFailedTransactionsDueToLowCreditAsJson(CancellationToken cancellationToken)
{
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(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);

Expand All @@ -110,20 +119,28 @@ public async Task<IActionResult> GetComparisonDateFailedTransactionsDueToLowCred
[HttpPost]
public async Task<IActionResult> GetMerchantKpisAsJson(CancellationToken cancellationToken){

String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(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);
}

[HttpPost]
public async Task<IActionResult> GetBottom3MerchantsBySalesValueAsJson(CancellationToken cancellationToken){
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

List<BottomMerchantModel> merchants = new List<BottomMerchantModel>();

List<TopBottomMerchantDataModel> 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);

Expand All @@ -135,11 +152,15 @@ await this.ApiClient.GetTopBottomMerchantData(null, Guid.Parse("435613AC-A468-47
[HttpPost]
public async Task<IActionResult> GetBottom3OperatorsBySalesValueAsJson(CancellationToken cancellationToken)
{
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

List<BottomOperatorModel> operators = new List<BottomOperatorModel>();

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);

Expand All @@ -151,11 +172,14 @@ await this.ApiClient.GetTopBottomOperatorData(null, Guid.Parse("435613AC-A468-47
[HttpPost]
public async Task<IActionResult> GetBottom3ProductsBySalesValueAsJson(CancellationToken cancellationToken)
{
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

List<BottomProductModel> products = new List<BottomProductModel>();

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);

Expand All @@ -168,10 +192,14 @@ await this.ApiClient.GetTopBottomProductData(null, Guid.Parse("435613AC-A468-47A
[HttpPost]
public async Task<IActionResult> GetComparisonDatesAsJson(CancellationToken cancellationToken)
{
String accessToken = await this.HttpContext.GetTokenAsync("access_token");

Guid estateId = Helpers.GetClaimValue<Guid>(this.User.Identity as ClaimsIdentity, Helpers.EstateIdClaimType);

List<(String value, String text)> datesList = new List<(String, String)>();

List<ComparisonDateModel> 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);
Expand Down