using System.ComponentModel.DataAnnotations;
using DomainObjects.Documents.Posts;
using DomainObjects.Enumerations;
using DomainObjects.L10n;
using DomainObjects;
using Core.Enumerations;
using Core.Abstractions.Models;
namespace WeatherForecast.Models.Blog.Requests {
///
///
///
public class PostMediaAttachmentL10nRequestModel : RequestModelBase {
///
///
///
public Locales Locale { get; set; } = Locales.Unknown;
///
///
///
public string Alt { get; set; } = string.Empty;
///
///
///
public string? Target { get; set; }
///
///
///
public string? Title { get; set; }
///
///
///
public string? Description { get; set; }
}
///
///
///
public class PostMediaAttachmentRequestModel : RequestModelBase {
///
///
///
public string Src { get; set; } = string.Empty;
///
///
///
public MediaTypes MediaType { get; set; } = MediaTypes.Unknown;
///
///
///
public List L10n { get; set; } = new List();
}
///
///
///
public class PostBlogitemL10nRequestModel : RequestModelBase {
///
///
///
public Locales Locale { get; set; } = Locales.Unknown;
///
///
///
public string Slug { get; set; } = string.Empty;
///
///
///
public string Description { get; set; } = string.Empty;
///
///
///
public string Title { get; set; } = string.Empty;
///
///
///
public string ShortText { get; set; } = string.Empty;
///
///
///
public string Text { get; set; } = string.Empty;
///
///
///
public string? PlainText { get; set; }
///
///
///
public TextFormat TextFormat { get; set; } = TextFormat.Unknown;
///
///
///
public List? Badges { get; set; }
}
///
///
///
public class PostBlogItemRequestModel : RequestModelBase, IValidatableObject {
///
///
///
public List L10n { get; set; } = new List();
///
///
///
public List MediaAttachments { get; set; } = new List();
///
///
///
public List Categories { get; set; } = new List();
///
///
///
public List? Tags { get; set; }
///
///
///
public bool? FamilyFriendly { get; set; }
///
///
///
public uint? ReadTime { get; set; }
///
///
///
public uint? Likes { get; set; }
///
///
///
///
public BlogDocument ToDomainObject(Guid userId, Guid siteId) => new() {
SiteId = siteId,
L10n = L10n.Select(x => new PostItemL10n() {
Locale = x.Locale,
Slug = x.Slug,
Description = x.Description,
Title = x.Title,
Text = x.Text,
ShortText = x.ShortText,
// TODO: create plain text creation logic
PlainText = "TODO",
TextFormat = x.TextFormat,
Badges = x.Badges
}).ToList(),
MediaAttachments = MediaAttachments.Select(x => new MediaAttachment {
Src = x.Src,
MediaType = x.MediaType,
L10n = x.L10n.Select(y => new MediaAttachmentL10n() {
Locale = y.Locale,
Alt = y.Alt,
Target = y.Target,
Titile = y.Title,
Description = y.Description
}).ToList()
}).ToList(),
Author = userId,
Created = DateTime.UtcNow,
Tags = Tags,
Categories = Categories,
FamilyFriendly = FamilyFriendly,
ReadTime = ReadTime,
Likes = Likes
};
///
///
///
///
///
public IEnumerable Validate(ValidationContext validationContext) {
if (L10n.Count == 0)
yield return new ValidationResult($"{nameof(L10n)} {Errors.NullOrEmpty.Name}");
foreach (var item in L10n) {
if (item.Locale == Locales.Unknown)
yield return new ValidationResult($"{nameof(item.Locale)} {Errors.UnableToParse.Name}");
if (string.IsNullOrWhiteSpace(item.Slug))
yield return new ValidationResult($"{nameof(item.Slug)} {Errors.NullOrWhiteSpace.Name}");
if (string.IsNullOrWhiteSpace(item.Description))
yield return new ValidationResult($"{nameof(item.Description)} {Errors.NullOrWhiteSpace.Name}");
if (string.IsNullOrWhiteSpace(item.Title))
yield return new ValidationResult($"{nameof(item.Title)} {Errors.NullOrWhiteSpace.Name}");
if (string.IsNullOrWhiteSpace(item.Text))
yield return new ValidationResult($"{nameof(item.Text)} {Errors.NullOrWhiteSpace.Name}");
if (string.IsNullOrWhiteSpace(item.ShortText))
yield return new ValidationResult($"{nameof(item.ShortText)} {Errors.NullOrWhiteSpace.Name}");
if (item.TextFormat == TextFormat.Unknown)
yield return new ValidationResult($"{nameof(item.TextFormat)} {Errors.UnableToParse.Name}");
}
if (MediaAttachments.Count == 0)
yield return new ValidationResult($"{nameof(MediaAttachments)} {Errors.NullOrEmpty.Name}");
foreach (var att in MediaAttachments) {
if (string.IsNullOrWhiteSpace(att.Src))
yield return new ValidationResult($"{nameof(att.Src)} {Errors.NullOrWhiteSpace.Name}");
if (att.MediaType == MediaTypes.Unknown)
yield return new ValidationResult($"{nameof(att.MediaType)} {Errors.UnableToParse.Name}");
if (att.L10n.Count == 0)
yield return new ValidationResult($"{nameof(att.L10n)} {Errors.NullOrEmpty.Name}");
foreach (var res in att.L10n) {
if (res.Locale == Locales.Unknown)
yield return new ValidationResult($"{nameof(res.Locale)} {Errors.UnableToParse.Name}");
if (string.IsNullOrWhiteSpace(res.Alt))
yield return new ValidationResult($"{nameof(res.Alt)} {Errors.NullOrWhiteSpace.Name}");
}
}
}
}
}