From 8d45d8129dc02c049390b3038818b1eb501ed940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 21 Jul 2019 18:37:04 +0300 Subject: [PATCH] Get counts from app service. --- .../IDashboardAppService.cs | 28 +++++++++++++++++++ .../DashboardAppService.cs | 23 +++++++++++++++ .../CountersWidgetViewComponent.cs | 25 ++++++++++------- .../CountersWidget/CountersWidgetViewModel.cs | 10 ------- .../Components/CountersWidget/Default.cshtml | 2 +- 5 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 samples/DashboardDemo/src/DashboardDemo.Application.Contracts/IDashboardAppService.cs create mode 100644 samples/DashboardDemo/src/DashboardDemo.Application/DashboardAppService.cs delete mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs diff --git a/samples/DashboardDemo/src/DashboardDemo.Application.Contracts/IDashboardAppService.cs b/samples/DashboardDemo/src/DashboardDemo.Application.Contracts/IDashboardAppService.cs new file mode 100644 index 0000000000..b1957d10b3 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Application.Contracts/IDashboardAppService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace DashboardDemo +{ + public interface IDashboardAppService : IApplicationService + { + Task GetCountersWidgetAsync(CountersWidgetInputDto input); + } + + public class CountersWidgetInputDto + { + public DateTime StartDate { get; set; } + + public DateTime EndDate { get; set; } + } + + public class CountersWidgetResultDto + { + public int NewUsers { get; set; } + public int ActiveUsers { get; set; } + public double TotalIncome { get; set; } + public double TotalProfit { get; set; } + } +} diff --git a/samples/DashboardDemo/src/DashboardDemo.Application/DashboardAppService.cs b/samples/DashboardDemo/src/DashboardDemo.Application/DashboardAppService.cs new file mode 100644 index 0000000000..26de2f5abc --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Application/DashboardAppService.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; + +namespace DashboardDemo +{ + public class DashboardAppService : DashboardDemoAppService, IDashboardAppService + { + public async Task GetCountersWidgetAsync(CountersWidgetInputDto input) + { + /* Instead of hard-coded / calculated values, get counts from a repository! + */ + + var dayFactor = (int)Math.Round(input.EndDate.Subtract(input.StartDate).TotalDays + 1); + return new CountersWidgetResultDto + { + NewUsers = dayFactor * 86, + ActiveUsers = dayFactor * 58, + TotalIncome = dayFactor * 749.53, + TotalProfit = dayFactor * 239.45, + }; + } + } +} diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs index a945691194..885b040f48 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs @@ -11,19 +11,24 @@ namespace DashboardDemo.Web.Pages.Components.CountersWidget )] public class CountersWidgetViewComponent : AbpViewComponent { + private readonly IDashboardAppService _dashboardAppService; + + public CountersWidgetViewComponent(IDashboardAppService dashboardAppService) + { + _dashboardAppService = dashboardAppService; + } + public async Task InvokeAsync(DateTime startDate, DateTime endDate) { - /* Instead of hard-coded / calculated values, get counts from a database or a service! - */ + var result = await _dashboardAppService.GetCountersWidgetAsync( + new CountersWidgetInputDto + { + StartDate = startDate, + EndDate = endDate + } + ); - var dayFactor = (int)Math.Round(endDate.Subtract(startDate).TotalDays + 1); - return View(new CountersWidgetViewModel - { - NewUsers = dayFactor * 86, - ActiveUsers = dayFactor * 58, - TotalIncome = dayFactor * 749.53, - TotalProfit = dayFactor * 239.45, - }); + return View(result); } } } diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs deleted file mode 100644 index bf532a47bc..0000000000 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DashboardDemo.Web.Pages.Components.CountersWidget -{ - public class CountersWidgetViewModel - { - public int NewUsers { get; set; } - public int ActiveUsers { get; set; } - public double TotalIncome { get; set; } - public double TotalProfit { get; set; } - } -} \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml index 58c18c506c..0c020a6b33 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml @@ -1,4 +1,4 @@ -@model DashboardDemo.Web.Pages.Components.CountersWidget.CountersWidgetViewModel +@model DashboardDemo.CountersWidgetResultDto