Get counts from app service.

pull/1520/head
Halil İbrahim Kalkan 6 years ago
parent 46eb5b380b
commit 8d45d8129d

@ -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<CountersWidgetResultDto> 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; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Threading.Tasks;
namespace DashboardDemo
{
public class DashboardAppService : DashboardDemoAppService, IDashboardAppService
{
public async Task<CountersWidgetResultDto> 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,
};
}
}
}

@ -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<IViewComponentResult> 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);
}
}
}

@ -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; }
}
}

@ -1,4 +1,4 @@
@model DashboardDemo.Web.Pages.Components.CountersWidget.CountersWidgetViewModel
@model DashboardDemo.CountersWidgetResultDto
<div class="counters-widget">
<abp-row>
<abp-column size-md="_3">

Loading…
Cancel
Save