using Core.DomainObjects.Documents; using Core.Enumerations; using Extensions; using System.ComponentModel.DataAnnotations; using WeatherForecast.Models.Abstractions; namespace WeatherForecast.Models.Requests { /// /// /// public class BlogItemRequestModel : PostItemRequestModelBase { /// /// /// public uint? ReadTime { get; set; } /// /// /// public uint? Likes { get; set; } /// /// /// /// public override BlogItem ToDomainObject() { if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException(); return new BlogItem() { L10n = L10n.Select(x => x.ToDomainObject()).ToList(), // Images // Author Tags = Tags, Categories = Categories, FamilyFriendly = FamilyFriendly, ReadTime = ReadTime, Likes = Likes }; } /// /// /// /// /// 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}"); } private bool HasValidationErrors(BlogItemRequestModel model) => Validate(new ValidationContext(model)).Any(); } }