|
@@ -14,6 +14,7 @@ using MTWorkHR.Core.Email;
|
|
|
using MTWorkHR.Core.Entities;
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
using System.Linq;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
namespace MTWorkHR.Application.Services
|
|
|
{
|
|
@@ -21,11 +22,13 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
private readonly GlobalInfo _globalInfo;
|
|
|
+ private readonly IUserService _userService;
|
|
|
|
|
|
- public AttendanceService(IUnitOfWork unitOfWork, GlobalInfo globalInfo) :base(unitOfWork)
|
|
|
+ public AttendanceService(IUnitOfWork unitOfWork, GlobalInfo globalInfo, IUserService userService) :base(unitOfWork)
|
|
|
{
|
|
|
_unitOfWork = unitOfWork;
|
|
|
_globalInfo = globalInfo;
|
|
|
+ _userService = userService;
|
|
|
}
|
|
|
public async Task<PagingResultDto<AttendanceDto>> GetAll(AttendancePagingInputDto PagingInputDto)
|
|
|
{
|
|
@@ -70,7 +73,7 @@ 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,
|
|
@@ -79,7 +82,35 @@ namespace MTWorkHR.Application.Services
|
|
|
// TotalHours = g.Sum(s=> s.TotalHours)
|
|
|
// }).ToList();
|
|
|
|
|
|
-
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ if (item.UserId != null)
|
|
|
+ {
|
|
|
+ var user = await _userService.GetUserWithAttachmentById(item.UserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ var entitiy = MapperObject.Mapper.Map<UserBasicInfoDto>(user);
|
|
|
+ item.Employee = entitiy;
|
|
|
+ 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.FileName)
|
|
|
+ {
|
|
|
+ Headers = new HeaderDictionary(),
|
|
|
+ ContentType = attach.ContentType,
|
|
|
+ };
|
|
|
+
|
|
|
+ System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
|
|
|
+ {
|
|
|
+ FileName = file.FileName
|
|
|
+ };
|
|
|
+ file.ContentDisposition = cd.ToString();
|
|
|
+ item.Employee.ProfileImage = file;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
var response = new PagingResultDto<AttendanceDto>
|
|
|
{
|
|
|
Result = list ,
|
|
@@ -107,6 +138,7 @@ namespace MTWorkHR.Application.Services
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ throw new AppException(ExceptionEnum.UserAlreadyCheckedIn);
|
|
|
var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(oldEntity);
|
|
|
return response;
|
|
|
}
|