fix alert bug 2
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using CompanyManagment.App.Contracts.File1;
|
||||
|
||||
@@ -13,4 +14,5 @@ public interface IFileAlertApplication
|
||||
List<EditFileAlert> Search(FileAlertSearchModel searchModel);
|
||||
List<FileAlertViewModel> GetFilesAlerts(List<FileViewModel> files);
|
||||
int getMaximumAdditionalDeadlineTimes(int additionalDeadline);
|
||||
Task<List<FileAlertViewModel>> GetFileAlerts();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using Company.Domain.FileAlert;
|
||||
using CompanyManagment.App.Contracts.File1;
|
||||
@@ -178,4 +179,8 @@ public class FileAlertApplication : IFileAlertApplication
|
||||
return 0;
|
||||
}
|
||||
|
||||
public async Task<List<FileAlertViewModel>> GetFileAlerts()
|
||||
{
|
||||
return await _fileAlertRepository.GetFileAlerts();
|
||||
}
|
||||
}
|
||||
@@ -64,18 +64,21 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
return query.OrderByDescending(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
#region Mahan
|
||||
public async Task<List<FileAlertViewModel>> GetFileAlerts()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var fileAlertsVM = new List<FileAlertViewModel>();
|
||||
|
||||
var fileStates = _context.FileStates.Include(x => x.FileTiming).Select(x => new
|
||||
var fileStates = await _context.FileStates.Include(x => x.FileTiming).Select(x => new
|
||||
{
|
||||
Id = x.id,
|
||||
x.FileTiming_Id,
|
||||
x.State,
|
||||
x.Title,
|
||||
x.FileTiming.Deadline
|
||||
});
|
||||
}).ToListAsync();
|
||||
|
||||
var files = await _context.Files.Where(x => x.Status == FileEnums.ACTIVE)
|
||||
.Include(x => x.BoardsList).ThenInclude(x => x.ProceedingSessionsList)
|
||||
.Include(x => x.PetitionsList)
|
||||
@@ -98,6 +101,10 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
|
||||
var fileWithState = files.Select(x =>
|
||||
{
|
||||
if (x.id == 74)
|
||||
{
|
||||
|
||||
}
|
||||
var state = GetFileState(x);
|
||||
return new
|
||||
{
|
||||
@@ -105,20 +112,114 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
State = state,
|
||||
StateDate = GetFileStateDate(x, state)
|
||||
};
|
||||
}).Where(x => x.StateDate > today);
|
||||
}).Where(x => x.StateDate > today).ToList();
|
||||
|
||||
|
||||
var res = fileWithState.Select(x =>
|
||||
foreach (var file in fileWithState)
|
||||
{
|
||||
var file = x.File;
|
||||
if (x.File.FileAlertsList.Any() == false)
|
||||
if (file.File.FileAlertsList.Count == 0)
|
||||
{
|
||||
var dueDate = x.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(f => f.State == x.State)?.Deadline ?? 0);
|
||||
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline);
|
||||
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
|
||||
|
||||
if (workingDaysDifference <= 1)
|
||||
{
|
||||
var fileAlertEntity = new FileAlert(file.File.id, file.State, 0);
|
||||
Create(fileAlertEntity);
|
||||
SaveChanges();
|
||||
var fileState = fileStates.FirstOrDefault(x => x.Id == file.State);
|
||||
|
||||
var fileAlert = new FileAlertViewModel()
|
||||
{
|
||||
AdditionalDeadline = fileAlertEntity.AdditionalDeadline,
|
||||
FileState = new FileStateViewModel()
|
||||
{
|
||||
State = fileState?.State ?? 0,
|
||||
Id = fileState.Id,
|
||||
FileTiming_Id = fileState.FileTiming_Id,
|
||||
Title = fileState.Title
|
||||
},
|
||||
Id = fileAlertEntity.id,
|
||||
FileState_Id = fileAlertEntity.FileState_Id,
|
||||
File_Id = fileAlertEntity.File_Id,
|
||||
IsExpired = false
|
||||
};
|
||||
if (workingDaysDifference < 0)
|
||||
fileAlert.IsExpired = true;
|
||||
|
||||
fileAlertsVM.Add(fileAlert);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
else if (file.File.FileAlertsList.Count == 1)
|
||||
{
|
||||
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline);
|
||||
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
|
||||
|
||||
if (workingDaysDifference <= 1)
|
||||
{
|
||||
var fileAlertEntity = file.File.FileAlertsList.First();
|
||||
var fileState = fileStates.FirstOrDefault(x => x.Id == file.State);
|
||||
|
||||
var fileAlert = new FileAlertViewModel()
|
||||
{
|
||||
AdditionalDeadline = fileAlertEntity.AdditionalDeadline,
|
||||
FileState = new FileStateViewModel()
|
||||
{
|
||||
State = fileState?.State ?? 0,
|
||||
Id = fileState.Id,
|
||||
FileTiming_Id = fileState.FileTiming_Id,
|
||||
Title = fileState.Title
|
||||
},
|
||||
Id = fileAlertEntity.id,
|
||||
FileState_Id = fileAlertEntity.FileState_Id,
|
||||
File_Id = fileAlertEntity.File_Id,
|
||||
IsExpired = false
|
||||
};
|
||||
if (workingDaysDifference < 0)
|
||||
fileAlert.IsExpired = true;
|
||||
|
||||
fileAlertsVM.Add(fileAlert);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var totalAdditionalDeadline = file.File.FileAlertsList.Sum(x => x.AdditionalDeadline);
|
||||
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline) + TimeSpan.FromDays(totalAdditionalDeadline);
|
||||
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
|
||||
|
||||
if (workingDaysDifference <= 1)
|
||||
{
|
||||
var fileAlertEntity = file.File.FileAlertsList.Last();
|
||||
|
||||
var fileState = fileStates.FirstOrDefault(x => x.Id == file.State);
|
||||
|
||||
var fileAlert = new FileAlertViewModel()
|
||||
{
|
||||
AdditionalDeadline = fileAlertEntity.AdditionalDeadline,
|
||||
FileState = new FileStateViewModel()
|
||||
{
|
||||
State = fileState?.State ?? 0,
|
||||
Id = fileState.Id,
|
||||
FileTiming_Id = fileState.FileTiming_Id,
|
||||
Title = fileState.Title
|
||||
},
|
||||
Id = fileAlertEntity.id,
|
||||
FileState_Id = fileAlertEntity.FileState_Id,
|
||||
File_Id = fileAlertEntity.File_Id,
|
||||
IsExpired = false
|
||||
};
|
||||
if (workingDaysDifference < 0)
|
||||
fileAlert.IsExpired = true;
|
||||
|
||||
fileAlertsVM.Add(fileAlert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fileAlertsVM;
|
||||
}
|
||||
public int GetFileState(File1 file)
|
||||
{
|
||||
@@ -135,20 +236,21 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
|
||||
if ((file.BoardsList.Any(a =>
|
||||
a.BoardType_Id == 1 && a.DisputeResolutionPetitionDate != new DateTime() &&
|
||||
a.ProceedingSessionsList.Count == 0)))
|
||||
a.ProceedingSessionsList.Count == 1)))
|
||||
return FileStateEnums.NO_DIAGNOSIS_INVITATION_ISSUED;
|
||||
|
||||
if ((file.BoardsList.Any(a => a.BoardType_Id == 1 && a.ProceedingSessionsList.Count != 0) &&
|
||||
if ((file.BoardsList.Any(a => a.BoardType_Id == 1 && a.ProceedingSessionsList.Count > 1) &&
|
||||
(file.PetitionsList.Any(x => x.BoardType_Id == 1) == false)))
|
||||
return FileStateEnums.NO_DIAGNOSIS_PETITION_ISSUED;
|
||||
|
||||
if ((file.PetitionsList.Any(x => x.BoardType_Id == 1) && file.BoardsList.Any(a =>
|
||||
a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate == new DateTime())))
|
||||
a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate == new DateTime()) || file.BoardsList.Any(a =>
|
||||
a.BoardType_Id == 2) == false))
|
||||
return FileStateEnums.PROTEST_NOT_REGISTERED;
|
||||
|
||||
if ((file.BoardsList.Any(a =>
|
||||
a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate != new DateTime() &&
|
||||
a.ProceedingSessionsList.Count == 0)))
|
||||
a.ProceedingSessionsList.Count == 1)))
|
||||
return FileStateEnums.NO_DISPUTE_INVITATION_ISSUED;
|
||||
|
||||
if ((file.PetitionsList.Any(x => x.BoardType_Id == 2) == false))
|
||||
@@ -176,7 +278,7 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
return diagnosisBoard?.DisputeResolutionPetitionDate;
|
||||
|
||||
case FileStateEnums.NO_DIAGNOSIS_PETITION_ISSUED:
|
||||
var lastDiagnosisPs = file.BoardsList.First(x => x.BoardType_Id == 1).ProceedingSessionsList.Last();
|
||||
var lastDiagnosisPs = file.BoardsList.First(x => x.BoardType_Id == 1).ProceedingSessionsList.LastOrDefault();
|
||||
|
||||
return lastDiagnosisPs.Date;
|
||||
|
||||
@@ -188,12 +290,13 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
|
||||
return disputeResolutionBoard?.DisputeResolutionPetitionDate;
|
||||
|
||||
case FileStateEnums.NO_DISPUTE_PETITION_ISSUED:
|
||||
var lastDisputeResolutionPs = file.BoardsList.First(x => x.BoardType_Id == 2).ProceedingSessionsList.Last();
|
||||
return lastDisputeResolutionPs.Date;
|
||||
var lastDisputeResolutionPs = file.BoardsList.First(x => x.BoardType_Id == 2).ProceedingSessionsList.LastOrDefault();
|
||||
return lastDisputeResolutionPs?.Date;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -30,12 +30,13 @@ public class AlertsModel : PageModel
|
||||
_fileStateApplication = fileStateApplication;
|
||||
}
|
||||
|
||||
public void OnGet(FileAlertSearchModel searchModel)
|
||||
public async Task OnGet(FileAlertSearchModel searchModel)
|
||||
{
|
||||
var files = _fileApplication.Search(new FileSearchModel
|
||||
{ ArchiveNo = searchModel.ArchiveNo, FileClass = searchModel.FileClass, Status = FileEnums.ACTIVE });
|
||||
|
||||
viewModels = _fileAlertApplication.GetFilesAlerts(files);
|
||||
viewModels = _fileAlertApplication.GetFilesAlerts(files.Where(x=>x.Id == 74).ToList());
|
||||
viewModels =await _fileAlertApplication.GetFileAlerts();
|
||||
|
||||
if (searchModel.FileState_Id != 0)
|
||||
viewModels = viewModels.Where(x => x.FileState_Id == searchModel.FileState_Id).ToList();
|
||||
|
||||
Reference in New Issue
Block a user