42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
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<Collateral> Collaterals { get; set; }
|
|
|
|
[Required]
|
|
public VehicleLocation VehicleLocation { get; set; }
|
|
|
|
[Required]
|
|
public int? PrimaryCollateralId { get; set; }
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
var failedValidations = new List<ValidationResult>();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|