64 lines
2.5 KiB
C#
64 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
|
|
public class UserDepartmentHistoryRepository : BaseRepository, IUserDepartmentHistoryRepository
|
|
{
|
|
public UserDepartmentHistoryRepository(IApplicationDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<List<UserDepartmentHistory>> SaveUserDepartmentUpdate(UserDepartment currentUserDepartment, DepartmentUpdateRequest departmentUpdateRequest)
|
|
{
|
|
var userDepartmentHistoryUpdates = new List<UserDepartmentHistory>();
|
|
|
|
if (currentUserDepartment.Role.Name != departmentUpdateRequest.Role)
|
|
{
|
|
userDepartmentHistoryUpdates.Add(new UserDepartmentHistory
|
|
{
|
|
UserDepartmentId = currentUserDepartment.Id,
|
|
FieldName = "Role",
|
|
NewValue = departmentUpdateRequest.Role,
|
|
OldValue = currentUserDepartment.Role.Name
|
|
});
|
|
}
|
|
|
|
if (currentUserDepartment.SlidingPayout != departmentUpdateRequest.SlidingPayout)
|
|
{
|
|
userDepartmentHistoryUpdates.Add(new UserDepartmentHistory
|
|
{
|
|
UserDepartmentId = currentUserDepartment.Id,
|
|
FieldName = "SlidingPayout",
|
|
NewValue = departmentUpdateRequest.SlidingPayout.ToString(CultureInfo.InvariantCulture),
|
|
OldValue = currentUserDepartment.SlidingPayout.ToString(CultureInfo.InvariantCulture)
|
|
});
|
|
}
|
|
|
|
if (currentUserDepartment.EndDate?.Date != departmentUpdateRequest.EndDate?.Date)
|
|
{
|
|
userDepartmentHistoryUpdates.Add(new UserDepartmentHistory
|
|
{
|
|
UserDepartmentId = currentUserDepartment.Id,
|
|
FieldName = "EndDate",
|
|
NewValue = departmentUpdateRequest.EndDate.ToString(),
|
|
OldValue = currentUserDepartment.EndDate.ToString()
|
|
});
|
|
}
|
|
|
|
await _context.UserDepartmentHistories.AddRangeAsync(userDepartmentHistoryUpdates);
|
|
return userDepartmentHistoryUpdates;
|
|
}
|
|
|
|
public async Task<List<UserPermissionHistory>> GetUserDepartmentHistory(int employeeId)
|
|
{
|
|
return await _context.UserPermissionHistories.Where(history => history.EmployeeId == employeeId).ToListAsync();
|
|
}
|
|
}
|