using Core.Abstractions.Models;
using Core.DomainObjects;
using Core.DomainObjects.Documents;
using Core.Enumerations;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace WeatherForecast.Models.Requests {
///
///
///
public class ShopCartItemRequestModel : RequestModelBase {
///
///
///
public uint? Quantity { get; set; }
///
///
///
///
public override ShopCartItem ToDomainObject() {
if (HasValidationErrors()) throw new ValidationException();
return new ShopCartItem() {
Quantity = Quantity.Value,
Created = DateTime.UtcNow
};
}
///
///
///
///
///
public override IEnumerable Validate(ValidationContext validationContext) {
if (Quantity == null)
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
}
[MemberNotNullWhen(false, new[] { nameof(Quantity) })]
private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
}
}