ini leave groupList
This commit is contained in:
@@ -644,5 +644,98 @@ public class LeaveRepository : RepositoryBase<long, Leave>, ILeaveRepository
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<GroupLeaveListDto>> GetGroupList(LeaveListSearchModel searchModel)
|
||||
{
|
||||
var query = _context.LeaveList.Where(x => x.WorkshopId == searchModel.WorkshopId && x.EmployeeId == searchModel.EmployeeId);
|
||||
|
||||
|
||||
|
||||
if (searchModel.LeaveType == LeaveType.PaidLeave)
|
||||
query = query.Where(x => x.LeaveType == "استحقاقی");
|
||||
|
||||
if (searchModel.LeaveType == LeaveType.SickLeave)
|
||||
query = query.Where(x => x.LeaveType == "استعلاجی");
|
||||
|
||||
if (searchModel.IsInvalid)
|
||||
{
|
||||
query = query.IgnoreQueryFilters().Where(x => x.IsInvalid);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.StartLeave) && !string.IsNullOrWhiteSpace(searchModel.EndLeave))
|
||||
{
|
||||
var start = new DateTime();
|
||||
var end = new DateTime();
|
||||
try
|
||||
{
|
||||
start = searchModel.StartLeave.ToGeorgianDateTime();
|
||||
end = searchModel.EndLeave.ToGeorgianDateTime();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new List<GroupLeaveListDto>();
|
||||
}
|
||||
|
||||
query = query.Where(x => x.StartLeave >= start && x.EndLeave <= end);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(searchModel.YearStr) || !string.IsNullOrWhiteSpace(searchModel.MonthStr))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.YearStr))
|
||||
{
|
||||
try
|
||||
{
|
||||
int year = Convert.ToInt32(searchModel.YearStr);
|
||||
query = query.Where(x => x.Year == year);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
return new List<GroupLeaveListDto>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchModel.MonthStr))
|
||||
{
|
||||
try
|
||||
{
|
||||
int month = Convert.ToInt32(searchModel.MonthStr);
|
||||
query = query.Where(x => x.Month == month);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
return new List<GroupLeaveListDto>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var leaveList = await query.GroupBy(x => new { x.Year, x.Month })
|
||||
.OrderByDescending(group => group.Key.Year)
|
||||
.ThenByDescending(group => group.Key.Month)
|
||||
.Select(group => new GroupLeaveListDto
|
||||
{
|
||||
YearStr = $"{group.Key.Year}",
|
||||
MonthStr = group.Key.Month.ToFarsiMonthByIntNumber(),
|
||||
LeaveListItemsDto = group.OrderByDescending(x=>x.StartLeave).Select(item => new LeaveListItemsDto
|
||||
{
|
||||
Id = item.id,
|
||||
IsInvalid = item.IsInvalid,
|
||||
LeaveType = item.LeaveType,
|
||||
StartLeave = item.StartLeave.ToFarsi(),
|
||||
EndLeave = item.EndLeave.ToFarsi(),
|
||||
HourlyInterval = item.PaidLeaveType == "ساعتی" ? $"{item.StartLeave.TimeOfDay:hh\\:mm} الی {item.EndLeave.TimeOfDay:hh\\:mm}" : "-",
|
||||
LeaveDuration = Tools.CalculateLeaveHoursAndDays(item.PaidLeaveType, item.LeaveHourses),
|
||||
IsAccepted = item.IsAccepted,
|
||||
WorkshopId = item.WorkshopId,
|
||||
EmployeeId = item.EmployeeId,
|
||||
}).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
return leaveList;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user