using System.ComponentModel.DataAnnotations; using DomainObjects.Documents; using Core.Enumerations; using Extensions; using WeatherForecast.Models.Abstractions.PostItem.Requests; namespace WeatherForecast.Models.Requests { /// /// /// public class ShopItemRequestModel : PostItemRequestModelBase { /// /// /// public string? BrandName { get; set; } /// /// /// public decimal? Rating { get; set; } /// /// /// public decimal? Price { get; set; } /// /// /// public decimal? NewPrice { get; set; } /// /// /// public uint? Quantity { get; set; } /// /// /// /// public override ShopDocument ToDomainObject() { return new ShopDocument() { L10n = L10n.Select(x => x.ToDomainObject()).ToList(), MediaAttachments = MediaAttachments?.Select(x => x.ToDomainObject()).ToList(), // Author Created = DateTime.UtcNow, Tags = Tags, FamilyFriendly = FamilyFriendly, BrandName = BrandName, Rating = Rating, Price = Price.Value, NewPrice = NewPrice, Quantity = Quantity.Value }; } /// /// /// /// /// public override IEnumerable Validate(ValidationContext validationContext) { if (L10n.IsNullOrEmpty()) yield return new ValidationResult($"{nameof(L10n)} {Errors.NullOrEmpty}"); if (MediaAttachments.IsNullOrEmpty()) yield return new ValidationResult($"{nameof(MediaAttachments)} {Errors.NullOrEmpty}"); if (string.IsNullOrWhiteSpace(BrandName)) yield return new ValidationResult($"{nameof(BrandName)} {Errors.NullOrWhiteSpace}"); if (Price == null || (Price != null && Price == 0)) yield return new ValidationResult($"{nameof(Price)} {Errors.NullOrEmpty.Name}"); if (Quantity == null || (Quantity != null && Quantity == 0)) yield return new ValidationResult($"{nameof(Quantity)} {Errors.NullOrEmpty}"); } } }