using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using LCU.Shared.Collections.RepoApiLib.Models; using LCU.Shared.Collections.RepoApiLib.WebServices.AutoIMS; namespace LCU.API.Collections.RepoApi.Models.Requests { public class AuctionAssignmentPostRequest : IValidatableObject { [Required] public Shared.Collections.RepoApiLib.Models.AuctionAssignment AuctionAssignment { get; set; } [Required] public IReadOnlyCollection Collaterals { get; set; } [Required] public VehicleLocation VehicleLocation { get; set; } [Required] public int? PrimaryCollateralId { get; set; } public IEnumerable Validate(ValidationContext validationContext) { var failedValidations = new List(); if (this.Collaterals.Count == 0) { failedValidations.Add(new ValidationResult("There must be at least one collateral when creating an auction assignment.")); } var primaryCollateral = Collaterals.Where(collateral => collateral.CollateralId == PrimaryCollateralId).FirstOrDefault(); if (primaryCollateral == null) { failedValidations.Add(new ValidationResult("Collaterals must contain a piece of Collateral with a CollateralID that matches the PrimaryCollateralId.")); } return failedValidations; } } }