Merge branch 'Feature/client/dashboard' into Main
This commit is contained in:
56
ServiceHost/Areas/Client/Controllers/DashboardController.cs
Normal file
56
ServiceHost/Areas/Client/Controllers/DashboardController.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagment.App.Contracts.ClientDashboard;
|
||||
using CompanyManagment.App.Contracts.Holiday;
|
||||
using CompanyManagment.App.Contracts.HolidayItem;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PersianTools.Core;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Client.Controllers;
|
||||
public record ClientDashboardViewModel(List<CalenderViewModel> Calender, int Year,string Month,int Day,string DayOfWeek);
|
||||
|
||||
public class DashboardController:ClientBaseController
|
||||
{
|
||||
private readonly IHolidayItemApplication _holidayItemApplication;
|
||||
|
||||
public DashboardController(IHolidayItemApplication holidayItemApplication)
|
||||
{
|
||||
_holidayItemApplication = holidayItemApplication;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult<ClientDashboardViewModel> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new ClientDashboardViewModel(calenderList, todayPersian.Year,todayPersian.MonthOfYear,todayPersian.Day,todayPersian.DayOfWeek);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user