60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
namespace LCU.Library.Internal.IncentiveApiModels.Entities
|
|
{
|
|
public class Department : Auditable, IValidatableObject
|
|
{
|
|
public int? Id { get; set; }
|
|
|
|
[Required]
|
|
[StringLength(255, MinimumLength = 3)]
|
|
public string DepartmentName { get; set; }
|
|
|
|
[Required]
|
|
[StringLength(255, MinimumLength = 3)]
|
|
public string DayforceDepartmentName { get; set; }
|
|
|
|
public string? DnaOrgNbr { get; set; }
|
|
|
|
[Required]
|
|
public string? DayForceGlCode { get; set; }
|
|
|
|
[Required]
|
|
public string? BusinessLineCode { get; set; }
|
|
|
|
public string? RegionCode { get; set; }
|
|
|
|
[Required]
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public DepartmentState State { get; set; }
|
|
|
|
public List<UserDepartment> Assignments { get; set; }
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
var results = new List<ValidationResult>();
|
|
|
|
if (!typeof(BusinessLine).GetFields(BindingFlags.Static | BindingFlags.Public)
|
|
.Where(x => x.FieldType == typeof(BusinessLine))
|
|
.Select(x => (x.GetValue(x.Name) as BusinessLine)?.Code).Contains(BusinessLineCode))
|
|
{
|
|
results.Add(new ValidationResult("The supplied BusinessLineCode is not associated with any known BusinessLine", new[] { "BusinessLine" }));
|
|
}
|
|
|
|
if (RegionCode != null && Region.FindByCode(RegionCode) == null)
|
|
{
|
|
results.Add(new ValidationResult("The supplied RegionCode is not associated with any known Region", new[] { "Region" }));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
}
|
|
}
|