57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System;
|
|
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
|
|
namespace LCU.Library.Internal.IncentiveApiModels.Entities
|
|
{
|
|
public class UserDepartment : Auditable
|
|
{
|
|
public const int PayoutMax = 100;
|
|
public int Id { get; set; }
|
|
public Guid AppUserId { get; set; }
|
|
public int DepartmentId { get; set; }
|
|
public Role Role { get; set; }
|
|
public DateTime StartDate { get; set; }
|
|
public DateTime? EndDate { get; set; }
|
|
public string? Note { get; set; }
|
|
public bool IsHome { get; set; }
|
|
public decimal SlidingPayout { get; set; }
|
|
public AppUser Employee { get; set; }
|
|
public Department Department { get; set; }
|
|
|
|
public int SafeGetDepartmentId()
|
|
{
|
|
return Department?.Id ?? DepartmentId;
|
|
}
|
|
|
|
public bool IsConflictingAssignment(UserDepartment newAssignment, out string message)
|
|
{
|
|
message = string.Empty;
|
|
if (newAssignment.Employee.EmployeeId != Employee.EmployeeId || newAssignment.Department.Id != DepartmentId)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (EndDate == null)
|
|
{
|
|
message = $"Current assignment to department: {newAssignment.Department.DepartmentName} exists.";
|
|
return true;
|
|
}
|
|
|
|
if (newAssignment.EndDate == null)
|
|
{
|
|
var startsBeforeEndDate = newAssignment.StartDate.Date <= EndDate.Value.Date;
|
|
message = startsBeforeEndDate ? $"Assignment would overlap existing assignment to department: {newAssignment.Department.DepartmentName}" : string.Empty;
|
|
return startsBeforeEndDate;
|
|
}
|
|
|
|
if (newAssignment.StartDate.Date > EndDate.Value.Date || newAssignment.EndDate.Value.Date < StartDate.Date)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
message = $"Assignment would overlap existing assignment to department: {newAssignment.Department.DepartmentName}";
|
|
return true;
|
|
}
|
|
}
|
|
}
|