|
@@ -16,6 +16,7 @@ using MTWorkHR.Infrastructure.UnitOfWorks;
|
|
using System.Linq.Dynamic.Core;
|
|
using System.Linq.Dynamic.Core;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
using MTWorkHR.Core.Entities.User;
|
|
using MTWorkHR.Core.Entities.User;
|
|
|
|
+using MTWorkHR.Core.Entities.Base;
|
|
|
|
|
|
namespace MTWorkHR.Application.Services
|
|
namespace MTWorkHR.Application.Services
|
|
{
|
|
{
|
|
@@ -41,7 +42,9 @@ namespace MTWorkHR.Application.Services
|
|
{
|
|
{
|
|
var entity = await _unitOfWork.OrderRequest.GetByIdWithAllChildren(id);
|
|
var entity = await _unitOfWork.OrderRequest.GetByIdWithAllChildren(id);
|
|
var response = MapperObject.Mapper.Map<OrderRequestDto>(entity);
|
|
var response = MapperObject.Mapper.Map<OrderRequestDto>(entity);
|
|
- response.Employee = await _userService.GetUserWithAttachmentById(entity.RequestingEmployeeId);
|
|
|
|
|
|
+ var user = await _userService.GetUserById(entity.RequestingEmployeeId);
|
|
|
|
+ var image = await _userService.GetProfileImage(entity.RequestingEmployeeId);
|
|
|
|
+ response.Employee = new EmployeeDto { Id = entity.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, ProfileImagePath = image };
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,24 +97,24 @@ namespace MTWorkHR.Application.Services
|
|
var user = await _userService.GetUserWithAttachmentById(item.RequestingEmployeeId);
|
|
var user = await _userService.GetUserWithAttachmentById(item.RequestingEmployeeId);
|
|
if (user != null)
|
|
if (user != null)
|
|
{
|
|
{
|
|
- item.Employee = user;
|
|
|
|
|
|
+ item.Employee = new EmployeeDto { Id = item.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email };
|
|
var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
|
|
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;
|
|
|
|
- }
|
|
|
|
|
|
+ item.Employee.ProfileImagePath = attach?.FilePath;
|
|
|
|
+ // 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();
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -140,23 +143,29 @@ namespace MTWorkHR.Application.Services
|
|
input.OrderTypeId = 2;
|
|
input.OrderTypeId = 2;
|
|
input.LeaveTypeId = null;
|
|
input.LeaveTypeId = null;
|
|
}
|
|
}
|
|
|
|
+ var contract = await _unitOfWork.Contract.GetLatestActiveContract(input.RequestingEmployeeId);
|
|
|
|
+ if(contract!= null)
|
|
|
|
+ input.ContractId = contract.Id;
|
|
if (input.OrderTypeId == 1 && input.LeaveTypeId == 1) // Annual vacation in contract
|
|
if (input.OrderTypeId == 1 && input.LeaveTypeId == 1) // Annual vacation in contract
|
|
{
|
|
{
|
|
- var contractId = await _unitOfWork.Contract.GetLatestActiveContract(input.RequestingEmployeeId);
|
|
|
|
- var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, contractId.Id, period);
|
|
|
|
- input.ContractId = contractId.Id;
|
|
|
|
- if (allocation is null)
|
|
|
|
- {
|
|
|
|
- throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ if (contract != null)
|
|
{
|
|
{
|
|
- int daysRequested = (int)(input.EndDate - input.StartDate).TotalDays;
|
|
|
|
- if (daysRequested > allocation.NumberOfDays)
|
|
|
|
|
|
+ var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, contract.Id, period);
|
|
|
|
+
|
|
|
|
+ if (allocation is null)
|
|
{
|
|
{
|
|
- throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have enough days for this request");
|
|
|
|
|
|
+ throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ int daysRequested = (int)(input.EndDate - input.StartDate).TotalDays;
|
|
|
|
+ if (daysRequested > allocation.NumberOfDays)
|
|
|
|
+ {
|
|
|
|
+ throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have enough days for this request");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
var orderRequest = MapperObject.Mapper.Map<OrderRequest>(input);
|
|
var orderRequest = MapperObject.Mapper.Map<OrderRequest>(input);
|
|
@@ -189,24 +198,25 @@ namespace MTWorkHR.Application.Services
|
|
var user = await _userService.GetUserWithAttachmentById(response.RequestingEmployeeId);
|
|
var user = await _userService.GetUserWithAttachmentById(response.RequestingEmployeeId);
|
|
if (user != null)
|
|
if (user != null)
|
|
{
|
|
{
|
|
- response.Employee = user;
|
|
|
|
|
|
+ response.Employee = new EmployeeDto { Id = response.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email };
|
|
var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
|
|
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();
|
|
|
|
- response.Employee.ProfileImage = file;
|
|
|
|
- }
|
|
|
|
|
|
+ response.Employee.ProfileImagePath = attach?.FilePath;
|
|
|
|
+ //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();
|
|
|
|
+ // response.Employee.ProfileImage = file;
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return response;
|
|
return response;
|