Compare commits
2 Commits
Feature/Le
...
Feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 112369c2a5 | |||
| 53eab1be67 |
75
ServiceHost/Areas/Admin/Controllers/DashboardController.cs
Normal file
75
ServiceHost/Areas/Admin/Controllers/DashboardController.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.Sms;
|
||||
using AccountManagement.Application.Contracts.Task;
|
||||
using AccountManagement.Application.Contracts.Ticket;
|
||||
using CompanyManagment.App.Contracts.ClientDashboard;
|
||||
using CompanyManagment.App.Contracts.HolidayItem;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PersianTools.Core;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers;
|
||||
|
||||
public class DashboardController : AdminBaseController
|
||||
{
|
||||
private readonly ISmsService _smsService;
|
||||
private readonly IHolidayItemApplication _holidayItemApplication;
|
||||
private readonly ITaskApplication _taskApplication;
|
||||
private readonly ITicketApplication _ticketApplication;
|
||||
private long UserId;
|
||||
|
||||
public DashboardController(ISmsService smsService, IHolidayItemApplication holidayItemApplication, ITaskApplication taskApplication,IAuthHelper authHelper, ITicketApplication ticketApplication)
|
||||
{
|
||||
_smsService = smsService;
|
||||
_holidayItemApplication = holidayItemApplication;
|
||||
_taskApplication = taskApplication;
|
||||
_ticketApplication = ticketApplication;
|
||||
UserId = authHelper.CurrentAccountId();
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<AdminDashboardViewModel>> Index()
|
||||
{
|
||||
var calenderList = new List<CalenderViewModel>();
|
||||
|
||||
var todayGr = DateTime.Today;
|
||||
var todayFa = todayGr.ToFarsi();
|
||||
|
||||
var todayPersian = new PersianDateTime(
|
||||
int.Parse(todayFa.Substring(0, 4)),
|
||||
int.Parse(todayFa.Substring(5, 2)),
|
||||
int.Parse(todayFa.Substring(8, 2))
|
||||
);
|
||||
|
||||
var startDate =new PersianDateTime(todayGr.AddDays(-3));
|
||||
var endDate =new PersianDateTime(todayGr.AddDays(3));
|
||||
|
||||
|
||||
for (var day = startDate; day <= endDate; day = day.AddDays(1))
|
||||
{
|
||||
var calenderNewItem = new CalenderViewModel
|
||||
{
|
||||
DayNumber = day.ToString("dd"),
|
||||
IsToday = day.DateTime == todayGr,
|
||||
DayOfWeek = day.DayOfWeek,
|
||||
Holiday = _holidayItemApplication.IsHoliday(day.ToGregorianDateTime()) || day.DayOfWeek== "جمعه"
|
||||
};
|
||||
calenderList.Add(calenderNewItem);
|
||||
}
|
||||
var taskCount = await _taskApplication.RequestedAndOverdueTasksCount(UserId);
|
||||
var ticketCount = _ticketApplication.GetAdminTicketsCount();
|
||||
|
||||
|
||||
return new AdminDashboardViewModel(calenderList, taskCount, ticketCount);
|
||||
}
|
||||
|
||||
[HttpGet("sms-remaining")]
|
||||
public async Task<ActionResult<SmsRemainingResult>> OnGetSmsRemaining()
|
||||
{
|
||||
var result = (int)await _smsService.GetCreditAmount();
|
||||
return new SmsRemainingResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
public record SmsRemainingResult(int Data);
|
||||
|
||||
public record AdminDashboardViewModel(List<CalenderViewModel> Calender, int TaskCount, int TicketCount);
|
||||
Reference in New Issue
Block a user