From 53eab1be67d6b04b274be992847ce13bcb5d97a9 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 21 Sep 2025 11:03:06 +0330 Subject: [PATCH] feat: Add DashboardController for Admin --- .../Admin/Controllers/DashboardController.cs | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ServiceHost/Areas/Admin/Controllers/DashboardController.cs diff --git a/ServiceHost/Areas/Admin/Controllers/DashboardController.cs b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs new file mode 100644 index 00000000..4df39f0a --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/DashboardController.cs @@ -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> Index() + { + var calenderList = new List(); + + 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()) + }; + 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> OnGetSmsRemaining() + { + var result = (int)await _smsService.GetCreditAmount(); + return new SmsRemainingResult(result); + } +} + +public record SmsRemainingResult(int Data); + +public record AdminDashboardViewModel(List Calender, int TaskCount, int TicketCount); \ No newline at end of file