using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using LCU.API.Collections.CollectionsApiLib.Models; namespace LCU.API.Internal.RepoApi.Repos.Models { public class RepoCompanySelection : IValidatableObject { public int? Id { get; set; } [Required] public int? CollateralId { get; set; } public RepoType RepoType { get; set; } public int? RepoCompanyId { get; set; } public DateTime? RepoCompanyAssignmentDate { get; set; } public DateTime? DateRepoed { get; set; } public DateTime? DateTimeCreated { get; set; } public IEnumerable Validate(ValidationContext validationContext) { var failedValidations = new List(); // This cannot be a required field on account of it resulting in a SQL error if (RepoType == null) { failedValidations.Add(new ValidationResult("Repo Company Selection: The RepoType cannot be blank")); } if (RepoCompanyAssignmentDate > DateRepoed) { failedValidations.Add(new ValidationResult("Repo Company Selection: The date repoed cannot come before the date assigned.")); } if (RepoCompanyId != null && RepoCompanyAssignmentDate == null) { failedValidations.Add(new ValidationResult("Repo Company Selection: The Repo Company Assignment date cannot be null when a Repo Company is set.")); } return failedValidations; } } }