using _0_Framework_b.Application; using CompanyManagment.App.Contracts.File1; using CompanyManagment.App.Contracts.ProceedingSession; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using ArchiveNo_FileClass_UserIdList = CompanyManagment.App.Contracts.ProceedingSession.ArchiveNo_FileClass_UserIdList; using Users = CompanyManagment.App.Contracts.ProceedingSession.Users; namespace ServiceHost.Areas.Admin.Pages.Company.FilePage; public class SessionsModel : PageModel { private readonly IFileApplication _fileApplication; private readonly IProceedingSessionApplication _proceedingSessionApplication; public ProceedingSessionSearchModel searchModel; public List viewModels = new(); public int Year; //private readonly IBoardApplication _boardApplication; public SessionsModel ( IFileApplication fileApplication, IProceedingSessionApplication proceedingSessionApplication //IBoardApplication boardApplication ) { _fileApplication = fileApplication; _proceedingSessionApplication = proceedingSessionApplication; //_boardApplication = boardApplication; } public void OnGet(ProceedingSessionSearchModel searchModel) { _proceedingSessionApplication.UpdatePastProceedingSessions(); viewModels = _proceedingSessionApplication.FilterSessions(searchModel); var files = _fileApplication.Search(new FileSearchModel(){Status = 0}); var ArchiveNo_FileClass_UserIdList = files.Select(x => new ArchiveNo_FileClass_UserIdList { ArchiveNo = x.ArchiveNo.ToString(), FileClass = x.FileClass, UserId = x.Client == 1 ? x.Reqester : x.Summoned }).Where(x => x.FileClass != null).ToList(); var UserIds = ArchiveNo_FileClass_UserIdList.Select(x => x.UserId).ToList(); var UsersList = _fileApplication.GetAllEmploees() .Select(x => new Users { Id = x.Id, FullName = x.EmployeeFullName, RequesterOrSummoned = 1 }) .Where(x => UserIds.Contains(x.Id)).ToList(); UsersList.AddRange(_fileApplication.GetAllEmployers() .Select(x => new Users { Id = x.Id, FullName = x.FullName, RequesterOrSummoned = 2 }) .Where(x => UserIds.Contains(x.Id)).ToList()); UsersList.Distinct(); if (this.searchModel == null) this.searchModel = new ProceedingSessionSearchModel(); this.searchModel.ArchiveNo_FileClass_UserIdList = ArchiveNo_FileClass_UserIdList; this.searchModel.UsersList = UsersList; Year = GetLatestPsYear(); } public JsonResult OnPostSetSessionStatus(long PsId, int status) { var Ps = _proceedingSessionApplication.Search(new ProceedingSessionSearchModel { Id = PsId, Status = 0 }) .FirstOrDefault(); Ps.Status = status; var operationResult = _proceedingSessionApplication.Edit(Ps); return new JsonResult(operationResult); } private int GetLatestPsYear() { var lastPS = _proceedingSessionApplication.Search(new ProceedingSessionSearchModel()) .OrderByDescending(x => x.Date).FirstOrDefault(); if (lastPS == null) return int.Parse(DateTime.Today.ToFarsiYear()); return int.Parse(lastPS.Date.ToGeorgianDateTime().ToFarsiYear()); } }