|
@@ -56,14 +56,6 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
query = query.Where(u => u.UserId == PagingInputDto.UserId);
|
|
|
}
|
|
|
- //var dayGroupByUser = query.GroupBy(m => new { m.UserId, m.UserName, AttendanceDate = m.AttendanceDate.Date }).Select
|
|
|
- // (g => new Attendance
|
|
|
- // {
|
|
|
- // UserId = g.Key.UserId,
|
|
|
- // UserName = g.Key.UserName,
|
|
|
- // AttendanceDate = g.Key.AttendanceDate,
|
|
|
- // TotalHours = g.Sum(s => (s.CheckInTime.HasValue && s.CheckOutTime.HasValue) ? (s.CheckOutTime.Value - s.CheckInTime.Value).TotalHours : 0)
|
|
|
- // });
|
|
|
|
|
|
var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
|
|
|
|
|
@@ -74,21 +66,34 @@ namespace MTWorkHR.Application.Services
|
|
|
var list = MapperObject.Mapper
|
|
|
.Map<IList<AttendanceDto>>(await page.ToListAsync());
|
|
|
|
|
|
-
|
|
|
- //var dayGroupByUser = list.GroupBy(m => new { m.UserId,m.WeekDay, m.UserName, AttendanceDate = m.AttendanceDate.Date }).Select
|
|
|
- // (g => new AttendanceDto {
|
|
|
- // UserId = g.Key.UserId, UserName=g.Key.UserName,
|
|
|
- // WeekDay= g.Key.WeekDay,
|
|
|
- // AttendanceDate = g.Key.AttendanceDate,
|
|
|
- // TotalHours = g.Sum(s=> s.TotalHours)
|
|
|
- // }).ToList();
|
|
|
- var employeesList = list.Select(a => a.UserId).Distinct();
|
|
|
+ // var employeesListx = list.Select(a => a.UserId).Distinct();
|
|
|
+ var employeesList = await _userService.GetAllCompanyEmployees();
|
|
|
Dictionary<string, UserBasicInfoDto> employeeDictList = new Dictionary<string, UserBasicInfoDto>();
|
|
|
- foreach (var RequestingEmployeeId in employeesList)
|
|
|
+ List<AttendanceDto> attendanceResult = new List<AttendanceDto>();
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(PagingInputDto.UserId))
|
|
|
{
|
|
|
- if (RequestingEmployeeId != null)
|
|
|
+ if (PagingInputDto.UserName != null)
|
|
|
+ {
|
|
|
+ //employeesList = employeesList.Where(u => u.FirstName.Contains(PagingInputDto.UserName) || u.LastName.Contains(PagingInputDto.UserName) ||
|
|
|
+ //u.UserName.Contains(PagingInputDto.UserName) || u.Email.Contains(PagingInputDto.UserName)
|
|
|
+ //).ToList();
|
|
|
+ var filter = PagingInputDto.UserName;
|
|
|
+ var filters = filter.Split(" ");
|
|
|
+ var firstNameFilter = filters[0];
|
|
|
+ var lastNameFilter = filters.Length > 1 ? filters[1] : "";
|
|
|
+
|
|
|
+ employeesList = employeesList.Where(u =>
|
|
|
+ u.UserName.Contains(filter) || u.Email.Contains(filter) || u.FavoriteName.Contains(filter) || u.FirstName.Contains(filter) || u.LastName.Contains(filter) ||
|
|
|
+ u.FirstName.Contains(firstNameFilter) && (string.IsNullOrEmpty(lastNameFilter) || u.LastName.Contains(lastNameFilter)) ||
|
|
|
+ u.LastName.Contains(lastNameFilter) && (string.IsNullOrEmpty(firstNameFilter) || u.FirstName.Contains(firstNameFilter))
|
|
|
+ ).ToList();
|
|
|
+ }
|
|
|
+ foreach (var employee in employeesList)
|
|
|
{
|
|
|
- var user = await _userService.GetUserWithAttachmentById(RequestingEmployeeId);
|
|
|
+ var latestAttendance = list.LastOrDefault(a => a.UserId == employee.Id);
|
|
|
+
|
|
|
+ var user = await _userService.GetUserWithAttachmentById(employee.Id);
|
|
|
if (user != null)
|
|
|
{
|
|
|
var entitiy = MapperObject.Mapper.Map<UserBasicInfoDto>(user);
|
|
@@ -97,7 +102,7 @@ namespace MTWorkHR.Application.Services
|
|
|
if (attach != null)
|
|
|
using (var stream = new MemoryStream(attach.Content))
|
|
|
{
|
|
|
- var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
|
|
|
+ var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FilePath)
|
|
|
{
|
|
|
Headers = new HeaderDictionary(),
|
|
|
ContentType = attach.ContentType,
|
|
@@ -109,24 +114,55 @@ namespace MTWorkHR.Application.Services
|
|
|
};
|
|
|
file.ContentDisposition = cd.ToString();
|
|
|
entitiy.ProfileImage = file;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- employeeDictList.Add(RequestingEmployeeId, entitiy);
|
|
|
+ employeeDictList.Add(employee.Id, entitiy);
|
|
|
+ if (latestAttendance != null)
|
|
|
+ latestAttendance.Employee = entitiy;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ latestAttendance = new AttendanceDto { UserId = employee.Id, UserName = employee.UserName, Employee = entitiy };
|
|
|
+ }
|
|
|
+ attendanceResult.Add(latestAttendance);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- foreach (var item in list)
|
|
|
+ else
|
|
|
{
|
|
|
- UserBasicInfoDto? employee;
|
|
|
- bool success = employeeDictList.TryGetValue(item.UserId, out employee);
|
|
|
- // var employee2 = employeeDictList[item.UserId];
|
|
|
- if(success && employee != null) item.Employee = employee;
|
|
|
+ var user = await _userService.GetUserWithAttachmentById(PagingInputDto.UserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ var entitiy = MapperObject.Mapper.Map<UserBasicInfoDto>(user);
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
|
|
|
+ if (attach != null)
|
|
|
+ using (var stream = new MemoryStream(attach.Content))
|
|
|
+ {
|
|
|
+ var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FilePath)
|
|
|
+ {
|
|
|
+ Headers = new HeaderDictionary(),
|
|
|
+ ContentType = attach.ContentType,
|
|
|
+ };
|
|
|
+
|
|
|
+ System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
|
|
|
+ {
|
|
|
+ FileName = file.FileName
|
|
|
+ };
|
|
|
+ file.ContentDisposition = cd.ToString();
|
|
|
+ entitiy.ProfileImage = file;
|
|
|
+
|
|
|
+ }
|
|
|
+ item.Employee = entitiy;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
var response = new PagingResultDto<AttendanceDto>
|
|
|
{
|
|
|
- Result = list ,
|
|
|
+ Result = !string.IsNullOrEmpty(PagingInputDto.UserId) ? list : attendanceResult,
|
|
|
//Result = ! string.IsNullOrEmpty( PagingInputDto.UserId ) ? list : dayGroupByUser,
|
|
|
- Total = total
|
|
|
+ Total = !string.IsNullOrEmpty(PagingInputDto.UserId) ? total : attendanceResult.Count //total
|
|
|
};
|
|
|
|
|
|
return response;
|