(refactor): nullable model properties
This commit is contained in:
parent
39a1e587f6
commit
d7fcc49e72
@ -1,11 +1,9 @@
|
|||||||
using System;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Collections.Generic;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Core.Abstractions.Models {
|
namespace Core.Abstractions.Models {
|
||||||
public abstract class RequestModelBase<T> : ModelBase {
|
public abstract class RequestModelBase<T> : ModelBase, IValidatableObject {
|
||||||
public abstract T ToDomainObject();
|
public abstract T ToDomainObject();
|
||||||
|
public abstract IEnumerable<ValidationResult> Validate(ValidationContext validationContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
webapi/Core/Enumerations/Errors.cs
Normal file
16
webapi/Core/Enumerations/Errors.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using Core.Abstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Core.Enumerations {
|
||||||
|
public class Errors : Enumeration {
|
||||||
|
public static Errors NullOrWhiteSpace = new(0, "is null or white space");
|
||||||
|
public static Errors WrongOrNotManaged = new(1, "is wrong or not managed");
|
||||||
|
public static Errors NullOrEmpty = new(2, "is null or empty");
|
||||||
|
|
||||||
|
private Errors(int id, string displayName) : base(id, displayName) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,21 +40,6 @@ namespace DataProviders.Abstractions {
|
|||||||
_sessionService = sessionService;
|
_sessionService = sessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Testing constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
/// <param name="collection"></param>
|
|
||||||
public DataProviderBase(
|
|
||||||
ILogger<DataProviderBase<T>> logger,
|
|
||||||
ISessionService sessionService,
|
|
||||||
List<T> collection
|
|
||||||
) {
|
|
||||||
_logger = logger;
|
|
||||||
_sessionService = sessionService;
|
|
||||||
_collection = collection ?? new List<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Insert
|
#region Insert
|
||||||
private protected (Guid?, IDomainResult) Insert(T obj, string collectionName) =>
|
private protected (Guid?, IDomainResult) Insert(T obj, string collectionName) =>
|
||||||
InsertAsync(obj, collectionName).Result;
|
InsertAsync(obj, collectionName).Result;
|
||||||
|
|||||||
14
webapi/Extensions/IEnumerableExtensions.cs
Normal file
14
webapi/Extensions/IEnumerableExtensions.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Extensions {
|
||||||
|
public static class IEnumerableExtensions {
|
||||||
|
|
||||||
|
public static bool IsNullOrEmpty<T>([NotNullWhen(false)] this IEnumerable<T>? list) =>
|
||||||
|
list == null || (list != null && !list.Any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,7 +40,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{siteId}")]
|
[HttpPost("{siteId}")]
|
||||||
public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostBlogItemRequestModel requestData) {
|
public IActionResult Post([FromRoute] Guid siteId, [FromBody] BlogItemRequestModel requestData) {
|
||||||
var result = _blogItemService.Post(siteId, requestData);
|
var result = _blogItemService.Post(siteId, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("{siteId}/{blogId}")]
|
[HttpPut("{siteId}/{blogId}")]
|
||||||
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] PutBlogItemRequestModel requestData) {
|
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid blogId, [FromBody] BlogItemRequestModel requestData) {
|
||||||
var result = _blogItemService.Update(siteId, blogId, requestData);
|
var result = _blogItemService.Update(siteId, blogId, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{siteId}")]
|
[HttpPost("{siteId}")]
|
||||||
public IActionResult Post([FromRoute] Guid siteId, [FromBody] PostCategoryItemRequestModel requestData) {
|
public IActionResult Post([FromRoute] Guid siteId, [FromBody] CategoryItemRequestModel requestData) {
|
||||||
var result = _categoryItemService.Post(siteId, requestData);
|
var result = _categoryItemService.Post(siteId, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("{siteId}/{categoryId}")]
|
[HttpPut("{siteId}/{categoryId}")]
|
||||||
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid categoryId, [FromBody] PutCategoryItemRequestModel requestData) {
|
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid categoryId, [FromBody] CategoryItemRequestModel requestData) {
|
||||||
var result = _categoryItemService.Update(siteId, categoryId, requestData);
|
var result = _categoryItemService.Update(siteId, categoryId, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{siteId}/{userId}/{sku}")]
|
[HttpPost("{siteId}/{userId}/{sku}")]
|
||||||
public IActionResult Post([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] PostShopCartItemRequestModel requestData) {
|
public IActionResult Post([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] ShopCartItemRequestModel requestData) {
|
||||||
var result = _shopCartItemService.Post(siteId, userId, sku, requestData);
|
var result = _shopCartItemService.Post(siteId, userId, sku, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("{siteId}/{userId}/{sku}")]
|
[HttpPut("{siteId}/{userId}/{sku}")]
|
||||||
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] PutShopCartItemRequestModel requestData) {
|
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] string sku, [FromBody] ShopCartItemRequestModel requestData) {
|
||||||
var result = _shopCartItemService.Update(siteId, userId, sku, requestData);
|
var result = _shopCartItemService.Update(siteId, userId, sku, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{siteId}/{sku}")]
|
[HttpPost("{siteId}/{sku}")]
|
||||||
public IActionResult Post([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] PostShopItemRequestModel requestData) {
|
public IActionResult Post([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) {
|
||||||
var result = _shopItemService.Post(siteId, sku, requestData);
|
var result = _shopItemService.Post(siteId, sku, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ namespace WeatherForecast.Controllers {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut("{siteId}/{sku}")]
|
[HttpPut("{siteId}/{sku}")]
|
||||||
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] PutShopItemRequestModel requestData) {
|
public IActionResult Update([FromRoute] Guid siteId, [FromRoute] string sku, [FromBody] ShopItemRequestModel requestData) {
|
||||||
var result = _shopItemService.Update(siteId, sku, requestData);
|
var result = _shopItemService.Update(siteId, sku, requestData);
|
||||||
return result.ToActionResult();
|
return result.ToActionResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,8 +30,8 @@ public class WeatherForecastController : ControllerBase {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(Name = "GetWeatherForecast")]
|
[HttpGet(Name = "GetWeatherForecast")]
|
||||||
public IEnumerable<GetWeatherForecastResponseModel> Get() {
|
public IEnumerable<WeatherForecastResponseModel> Get() {
|
||||||
return Enumerable.Range(1, 5).Select(index => new GetWeatherForecastResponseModel {
|
return Enumerable.Range(1, 5).Select(index => new WeatherForecastResponseModel {
|
||||||
Date = DateTime.Now.AddDays(index),
|
Date = DateTime.Now.AddDays(index),
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
TemperatureC = Random.Shared.Next(-20, 55),
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
using Core.Abstractions.DomainObjects;
|
using Core.Abstractions.DomainObjects;
|
||||||
using Core.Abstractions.Models;
|
using Core.Abstractions.Models;
|
||||||
using WeatherForecast.Models.L10n;
|
using Core.Enumerations;
|
||||||
|
using Extensions;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using WeatherForecast.Models.Requests.L10n;
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Abstractions {
|
namespace WeatherForecast.Models.Abstractions {
|
||||||
|
|
||||||
@ -13,7 +17,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<PostItemL10nModel> L10n { get; set; }
|
public List<PostItemL10nModel>? L10n { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -29,5 +33,13 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? FamilyFriendly { get; set; }
|
public bool? FamilyFriendly { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base MemberNotNullWhen workaround
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hasErrors"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(L10n) })]
|
||||||
|
private protected bool HasValidationErrorsBase(bool hasErrors) => hasErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
using Core.Abstractions.Models;
|
using Core.Abstractions.Models;
|
||||||
using Core.DomainObjects;
|
using Core.DomainObjects;
|
||||||
using Core.Enumerations;
|
using Core.Enumerations;
|
||||||
using WeatherForecast.Models.L10n;
|
using WeatherForecast.Models.Responses.L10n;
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Abstractions {
|
namespace WeatherForecast.Models.Abstractions {
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ImageModel> Images { get; set; }
|
public List<ImageModel>? Images { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorModel Author { get; set; }
|
public AuthorModel? Author { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -88,18 +88,19 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Tags { get; set; }
|
public List<string>? Tags { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CategoryModel> Categories { get; set; }
|
public List<CategoryModel>? Categories { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? FamilyFriendly { get; set; }
|
public bool? FamilyFriendly { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -107,7 +108,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
public PostItemResponseModelBase(PostItemBase<T> postItem) {
|
public PostItemResponseModelBase(PostItemBase<T> postItem) {
|
||||||
Id = postItem.Id;
|
Id = postItem.Id;
|
||||||
SiteId = postItem.SiteId;
|
SiteId = postItem.SiteId;
|
||||||
// Author = new AuthorModel(postItem.Author);
|
//Author = new AuthorModel(postItem.Author);
|
||||||
Created = postItem.Created;
|
Created = postItem.Created;
|
||||||
Tags = postItem.Tags;
|
Tags = postItem.Tags;
|
||||||
FamilyFriendly = postItem.FamilyFriendly;
|
FamilyFriendly = postItem.FamilyFriendly;
|
||||||
@ -121,7 +122,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories) : this(postItem) {
|
public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories) : this(postItem) {
|
||||||
L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList();
|
L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList();
|
||||||
Categories = categories.Select(x => new CategoryModel(x)).ToList();
|
Categories = categories.Select(x => new CategoryModel(x)).ToList();
|
||||||
Images = postItem.Images.Select(x => new ImageModel(x)).ToList();
|
Images = postItem.Images?.Select(x => new ImageModel(x)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -144,7 +145,7 @@ namespace WeatherForecast.Models.Abstractions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Categories = categories.Select(x => new CategoryModel(x, locale)).ToList();
|
Categories = categories.Select(x => new CategoryModel(x, locale)).ToList();
|
||||||
Images = postItem.Images.Select(x => new ImageModel(x, locale)).ToList();
|
Images = postItem.Images?.Select(x => new ImageModel(x, locale)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
using Core.DomainObjects.Documents;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using Extensions;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using WeatherForecast.Models.Abstractions;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class BlogItemRequestModel : PostItemRequestModelBase<BlogItem> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public uint? ReadTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public uint? Likes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> Validate( ValidationContext validationContext) {
|
||||||
|
if (L10n.IsNullOrEmpty())
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
||||||
|
else {
|
||||||
|
foreach (var item in L10n)
|
||||||
|
foreach (var validationResult in item.Validate(validationContext))
|
||||||
|
yield return validationResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasValidationErrors(BlogItemRequestModel validationContext) => Validate(new ValidationContext(validationContext)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using Extensions;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using WeatherForecast.Models.Requests.L10n;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class CategoryItemRequestModel : RequestModelBase<Category> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public List<CategoryL10nModel>? L10n { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override Category ToDomainObject() {
|
||||||
|
if (HasValidationErrors()) throw new ValidationException();
|
||||||
|
|
||||||
|
return new Category() {
|
||||||
|
L10n = L10n.Select(x => x.ToDomainObject()).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (L10n.IsNullOrEmpty())
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
||||||
|
else {
|
||||||
|
foreach (var item in L10n)
|
||||||
|
foreach (var validationResult in item.Validate(validationContext))
|
||||||
|
yield return validationResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(L10n) })]
|
||||||
|
private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Core.Abstractions;
|
||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests.L10n {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class CategoryL10nModel : RequestModelBase<CategoryL10n> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Locale { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Slug { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override CategoryL10n ToDomainObject() {
|
||||||
|
if (HasValidationErrors()) throw new ValidationException();
|
||||||
|
|
||||||
|
return new CategoryL10n() {
|
||||||
|
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
||||||
|
Slug = Slug,
|
||||||
|
Text = Text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Slug))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Text))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://www.meziantou.net/csharp-8-nullable-reference-types.htm
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Text) })]
|
||||||
|
private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
using Core.Abstractions;
|
||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests.L10n {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ImageL10nModel : RequestModelBase<ImageL10n> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Locale { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Alt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override ImageL10n ToDomainObject() {
|
||||||
|
if (HasValidationErrors()) throw new ValidationException();
|
||||||
|
|
||||||
|
return new ImageL10n() {
|
||||||
|
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
||||||
|
Alt = Alt
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Alt))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Alt) })]
|
||||||
|
private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
118
webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs
Normal file
118
webapi/WeatherForecast/Models/Requests/L10n/PostItemL10nModel.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
using Core.Abstractions;
|
||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests.L10n {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class PostItemL10nModel : RequestModelBase<PostItemL10n> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Locale { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Slug { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? ShortText { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? PlainText { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? ContentType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public List<string>? Badges { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override PostItemL10n ToDomainObject() {
|
||||||
|
if (HasValidationErrors()) throw new ValidationException();
|
||||||
|
|
||||||
|
return new PostItemL10n() {
|
||||||
|
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
||||||
|
Slug = Slug,
|
||||||
|
Description = Description,
|
||||||
|
Title = Title,
|
||||||
|
Text = Text,
|
||||||
|
ShortText = ShortText,
|
||||||
|
|
||||||
|
// TODO: create plain text creation logic
|
||||||
|
PlainText = "TODO",
|
||||||
|
|
||||||
|
ContentType = Enumeration.FromDisplayName<ContentTypes>(ContentType),
|
||||||
|
Badges = Badges
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (string.IsNullOrWhiteSpace(Locale))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
else if (Enumeration.FromDisplayName<Locales>(Locale) == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Slug))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Description))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Title))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(Text))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(ShortText))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(ContentType))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrWhiteSpace.Name}");
|
||||||
|
else if (Enumeration.FromDisplayName<ContentTypes>(ContentType) == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.WrongOrNotManaged}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(Locale), nameof(Slug), nameof(Description), nameof(Title), nameof(Text), nameof(ShortText), nameof(ContentType) })]
|
||||||
|
private bool HasValidationErrors() => Validate(new ValidationContext(this)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,39 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
using WeatherForecast.Models.Abstractions;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PostBlogItemRequestModel : PostItemRequestModelBase<BlogItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint? ReadTime { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint? Likes { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override BlogItem ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
|
||||||
// Images
|
|
||||||
// Author
|
|
||||||
Created = DateTime.UtcNow,
|
|
||||||
Tags = Tags,
|
|
||||||
Categories = Categories,
|
|
||||||
FamilyFriendly = FamilyFriendly,
|
|
||||||
|
|
||||||
ReadTime = ReadTime,
|
|
||||||
Likes = Likes
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using Core.DomainObjects.L10n;
|
|
||||||
using WeatherForecast.Models.L10n;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PostCategoryItemRequestModel : RequestModelBase<Category> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public List<CategoryL10nModel> L10n { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override Category ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PostShopCartItemRequestModel : RequestModelBase<ShopCartItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint Quantity { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override ShopCartItem ToDomainObject() => new() {
|
|
||||||
Quantity = Quantity,
|
|
||||||
Created = DateTime.UtcNow
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
using Core.DomainObjects.L10n;
|
|
||||||
using ExtensionMethods;
|
|
||||||
using WeatherForecast.Models.Abstractions;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PostShopItemRequestModel : PostItemRequestModelBase<ShopItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string BrandName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal? Rating { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal Price { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal? NewPrice { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint Quantity { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override ShopItem ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
|
||||||
// Images
|
|
||||||
// Author
|
|
||||||
Created = DateTime.UtcNow,
|
|
||||||
Tags = Tags,
|
|
||||||
Categories = Categories,
|
|
||||||
FamilyFriendly = FamilyFriendly,
|
|
||||||
|
|
||||||
BrandName = BrandName,
|
|
||||||
Rating = Rating,
|
|
||||||
Price = Price,
|
|
||||||
NewPrice = NewPrice,
|
|
||||||
Quantity = Quantity
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
using WeatherForecast.Models.Abstractions;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PutBlogItemRequestModel : PostItemRequestModelBase<BlogItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint? ReadTime { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint? Likes { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override BlogItem ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
|
||||||
// Images
|
|
||||||
// Author
|
|
||||||
Created = DateTime.UtcNow,
|
|
||||||
Tags = Tags,
|
|
||||||
Categories = Categories,
|
|
||||||
FamilyFriendly = FamilyFriendly,
|
|
||||||
|
|
||||||
ReadTime = ReadTime,
|
|
||||||
Likes = Likes
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using WeatherForecast.Models.L10n;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PutCategoryItemRequestModel : RequestModelBase<Category> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public List<CategoryL10nModel> L10n { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override Category ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PutShopCartItemRequestModel : RequestModelBase<ShopCartItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint Quantity { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override ShopCartItem ToDomainObject() => new() {
|
|
||||||
Quantity = Quantity
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
using WeatherForecast.Models.Abstractions;
|
|
||||||
|
|
||||||
using Core.DomainObjects;
|
|
||||||
using Core.DomainObjects.Documents;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.Requests {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class PutShopItemRequestModel : PostItemRequestModelBase<ShopItem> {
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public string BrandName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal? Rating { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal Price { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public decimal? NewPrice { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public uint Quantity { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override ShopItem ToDomainObject() => new() {
|
|
||||||
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
|
||||||
// Images
|
|
||||||
// Author
|
|
||||||
Created = DateTime.UtcNow,
|
|
||||||
Tags = Tags,
|
|
||||||
Categories = Categories,
|
|
||||||
FamilyFriendly = FamilyFriendly,
|
|
||||||
|
|
||||||
BrandName = BrandName,
|
|
||||||
Rating = Rating,
|
|
||||||
Price = Price,
|
|
||||||
NewPrice = NewPrice,
|
|
||||||
Quantity = Quantity
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
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 {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ShopCartItemRequestModel : RequestModelBase<ShopCartItem> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public uint? Quantity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override ShopCartItem ToDomainObject() {
|
||||||
|
if (HasValidationErrors()) throw new ValidationException();
|
||||||
|
|
||||||
|
return new ShopCartItem() {
|
||||||
|
Quantity = Quantity.Value,
|
||||||
|
Created = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
using Core.Abstractions.Models;
|
||||||
|
using Core.DomainObjects;
|
||||||
|
using Core.DomainObjects.Documents;
|
||||||
|
using Core.DomainObjects.L10n;
|
||||||
|
using Core.Enumerations;
|
||||||
|
using ExtensionMethods;
|
||||||
|
using Extensions;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using WeatherForecast.Models.Abstractions;
|
||||||
|
|
||||||
|
namespace WeatherForecast.Models.Requests {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ShopItemRequestModel : PostItemRequestModelBase<ShopItem> {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? BrandName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public decimal? Rating { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public decimal? Price { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public decimal? NewPrice { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public uint? Quantity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override ShopItem ToDomainObject() {
|
||||||
|
if (HasValidationErrors(this) || HasValidationErrorsBase(HasValidationErrors(this))) throw new ValidationException();
|
||||||
|
|
||||||
|
return new ShopItem() {
|
||||||
|
L10n = L10n.Select(x => x.ToDomainObject()).ToList(),
|
||||||
|
// Images
|
||||||
|
// Author
|
||||||
|
Created = DateTime.UtcNow,
|
||||||
|
Tags = Tags,
|
||||||
|
Categories = Categories,
|
||||||
|
FamilyFriendly = FamilyFriendly,
|
||||||
|
|
||||||
|
BrandName = BrandName,
|
||||||
|
Rating = Rating,
|
||||||
|
Price = Price.Value,
|
||||||
|
NewPrice = NewPrice,
|
||||||
|
Quantity = Quantity.Value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
|
if (L10n.IsNullOrEmpty())
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
||||||
|
else {
|
||||||
|
foreach (var item in L10n)
|
||||||
|
foreach (var validationResult in item.Validate(validationContext))
|
||||||
|
yield return validationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(BrandName))
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrWhiteSpace}");
|
||||||
|
|
||||||
|
if (Price == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} {Errors.NullOrEmpty.Name}");
|
||||||
|
|
||||||
|
if (Quantity == null)
|
||||||
|
yield return new ValidationResult($"{validationContext.DisplayName} ${Errors.NullOrEmpty}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[MemberNotNullWhen(false, new[] { nameof(BrandName), nameof(Price), nameof(Quantity) })]
|
||||||
|
private bool HasValidationErrors(ShopItemRequestModel validationContext) => Validate(new ValidationContext(validationContext)).Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,11 +5,11 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetBlogCategoriesResponseModel : ResponseModelBase {
|
public class BlogCategoriesResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CategoryModel> Items { get; set; }
|
public List<CategoryModel>? Items { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,7 +5,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetBlogFeaturedResponseModel : ResponseModelBase {
|
public class BlogFeaturedResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -16,7 +16,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public GetBlogFeaturedResponseModel(List<BlogItemModel> items) {
|
public BlogFeaturedResponseModel(List<BlogItemModel> items) {
|
||||||
Items = items;
|
Items = items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,7 +10,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetBlogItemResponseModel : PostItemResponseModelBase<BlogItem> {
|
public class BlogItemResponseModel : PostItemResponseModelBase<BlogItem> {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -27,7 +27,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="blogItem"></param>
|
/// <param name="blogItem"></param>
|
||||||
/// <param name="categories"></param>
|
/// <param name="categories"></param>
|
||||||
public GetBlogItemResponseModel(BlogItem blogItem, List<Category> categories) : base(blogItem, categories) {
|
public BlogItemResponseModel(BlogItem blogItem, List<Category> categories) : base(blogItem, categories) {
|
||||||
ReadTime = blogItem.ReadTime;
|
ReadTime = blogItem.ReadTime;
|
||||||
Likes = blogItem.Likes;
|
Likes = blogItem.Likes;
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <param name="blogItem"></param>
|
/// <param name="blogItem"></param>
|
||||||
/// <param name="categories"></param>
|
/// <param name="categories"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public GetBlogItemResponseModel(BlogItem blogItem, List<Category> categories, Locales locale) : base(blogItem, categories, locale) {
|
public BlogItemResponseModel(BlogItem blogItem, List<Category> categories, Locales locale) : base(blogItem, categories, locale) {
|
||||||
ReadTime = blogItem.ReadTime;
|
ReadTime = blogItem.ReadTime;
|
||||||
Likes = blogItem.Likes;
|
Likes = blogItem.Likes;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetBlogItemsResponseModel : PaginationModelBase<GetBlogItemResponseModel> {
|
public class BlogItemsResponseModel : PaginationModelBase<BlogItemResponseModel> {
|
||||||
|
|
||||||
|
|
||||||
//public BlogItemModel FeaturedBlog { get; set; }
|
//public BlogItemModel FeaturedBlog { get; set; }
|
||||||
@ -20,7 +20,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <param name="currentPage"></param>
|
/// <param name="currentPage"></param>
|
||||||
/// <param name="totalPages"></param>
|
/// <param name="totalPages"></param>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public GetBlogItemsResponseModel(int currentPage, int totalPages, List<GetBlogItemResponseModel> items)
|
public BlogItemsResponseModel(int currentPage, int totalPages, List<BlogItemResponseModel> items)
|
||||||
: base(currentPage, totalPages, items) { }
|
: base(currentPage, totalPages, items) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -8,7 +8,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetCategoryItemResponseModel : ResponseModelBase {
|
public class CategoryItemResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -39,7 +39,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="category"></param>
|
/// <param name="category"></param>
|
||||||
public GetCategoryItemResponseModel(Category category) {
|
public CategoryItemResponseModel(Category category) {
|
||||||
Id = category.Id;
|
Id = category.Id;
|
||||||
SiteId = category.SiteId;
|
SiteId = category.SiteId;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="category"></param>
|
/// <param name="category"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public GetCategoryItemResponseModel(Category category, Locales locale) {
|
public CategoryItemResponseModel(Category category, Locales locale) {
|
||||||
Id = category.Id;
|
Id = category.Id;
|
||||||
SiteId = category.SiteId;
|
SiteId = category.SiteId;
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetContentResponseModel : ResponseModelBase {
|
public class ContentResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -103,7 +103,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="domainObject"></param>
|
/// <param name="domainObject"></param>
|
||||||
public GetContentResponseModel(Content domainObject) {
|
public ContentResponseModel(Content domainObject) {
|
||||||
|
|
||||||
SiteName = domainObject.SiteName;
|
SiteName = domainObject.SiteName;
|
||||||
SiteUrl = domainObject.SiteUrl;
|
SiteUrl = domainObject.SiteUrl;
|
||||||
@ -1,14 +1,12 @@
|
|||||||
using Core.Abstractions;
|
using Core.Abstractions.Models;
|
||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects.L10n;
|
using Core.DomainObjects.L10n;
|
||||||
using Core.Enumerations;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.L10n {
|
namespace WeatherForecast.Models.Responses.L10n {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CategoryL10nModel : ModelBase {
|
public class CategoryL10nModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -25,11 +23,6 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public CategoryL10nModel() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -39,15 +32,5 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
Slug = categoryL10n.Slug;
|
Slug = categoryL10n.Slug;
|
||||||
Text = categoryL10n.Text;
|
Text = categoryL10n.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public CategoryL10n ToDomainObject() => new() {
|
|
||||||
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
|
||||||
Slug = Slug,
|
|
||||||
Text = Text
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,14 +1,12 @@
|
|||||||
using Core.Abstractions;
|
using Core.Abstractions.Models;
|
||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects.L10n;
|
using Core.DomainObjects.L10n;
|
||||||
using Core.Enumerations;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.L10n {
|
namespace WeatherForecast.Models.Responses.L10n {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ImageL10nModel : ModelBase {
|
public class ImageL10nModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -20,11 +18,6 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Alt { get; set; }
|
public string Alt { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public ImageL10nModel() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,14 +26,5 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
Locale = imageL10n.Locale.Name;
|
Locale = imageL10n.Locale.Name;
|
||||||
Alt = imageL10n.Alt;
|
Alt = imageL10n.Alt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public ImageL10n ToDomainObject() => new() {
|
|
||||||
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
|
||||||
Alt = Alt
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,14 +1,12 @@
|
|||||||
using Core.Abstractions;
|
using Core.Abstractions.Models;
|
||||||
using Core.Abstractions.Models;
|
|
||||||
using Core.DomainObjects.L10n;
|
using Core.DomainObjects.L10n;
|
||||||
using Core.Enumerations;
|
|
||||||
|
|
||||||
namespace WeatherForecast.Models.L10n {
|
namespace WeatherForecast.Models.Responses.L10n {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PostItemL10nModel : ModelBase {
|
public class PostItemL10nModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -38,7 +36,7 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Text { get; set; }
|
public string? Text { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -55,10 +53,6 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string>? Badges { get; set; }
|
public List<string>? Badges { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public PostItemL10nModel() { }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -70,28 +64,10 @@ namespace WeatherForecast.Models.L10n {
|
|||||||
Description = postItemL10n.Description;
|
Description = postItemL10n.Description;
|
||||||
Title = postItemL10n.Title;
|
Title = postItemL10n.Title;
|
||||||
ShortText = postItemL10n.ShortText;
|
ShortText = postItemL10n.ShortText;
|
||||||
|
PlainText = postItemL10n.PlainText;
|
||||||
Text = postItemL10n.Text;
|
Text = postItemL10n.Text;
|
||||||
ContentType = postItemL10n.ContentType.Name;
|
ContentType = postItemL10n.ContentType.Name;
|
||||||
Badges = postItemL10n.Badges;
|
Badges = postItemL10n.Badges;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public PostItemL10n ToDomainObject() => new() {
|
|
||||||
Locale = Enumeration.FromDisplayName<Locales>(Locale),
|
|
||||||
Slug = Slug,
|
|
||||||
Description = Description,
|
|
||||||
Title = Title,
|
|
||||||
Text = Text,
|
|
||||||
ShortText = ShortText,
|
|
||||||
|
|
||||||
// TODO: create plain text creation logic
|
|
||||||
PlainText = "TODO",
|
|
||||||
|
|
||||||
ContentType = Enumeration.FromDisplayName<ContentTypes>(ContentType),
|
|
||||||
Badges = Badges
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,7 +7,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetShopCartItemResponseModel : ResponseModelBase {
|
public class ShopCartItemResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -62,7 +62,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GetShopCartItemResponseModel() { }
|
public ShopCartItemResponseModel() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -70,7 +70,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <param name="shopItem"></param>
|
/// <param name="shopItem"></param>
|
||||||
/// <param name="shopCartItem"></param>
|
/// <param name="shopCartItem"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public GetShopCartItemResponseModel(ShopItem shopItem, ShopCartItem shopCartItem, Locales locale) {
|
public ShopCartItemResponseModel(ShopItem shopItem, ShopCartItem shopCartItem, Locales locale) {
|
||||||
|
|
||||||
Sku = shopItem.Sku;
|
Sku = shopItem.Sku;
|
||||||
BrandName = shopItem.BrandName;
|
BrandName = shopItem.BrandName;
|
||||||
@ -9,7 +9,7 @@ namespace WeatherForecast.Models {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetShopItemResponseModel : PostItemResponseModelBase<ShopItem> {
|
public class ShopItemResponseModel : PostItemResponseModelBase<ShopItem> {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -41,7 +41,7 @@ namespace WeatherForecast.Models {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="shopCatalogItem"></param>
|
/// <param name="shopCatalogItem"></param>
|
||||||
/// <param name="categories"></param>
|
/// <param name="categories"></param>
|
||||||
public GetShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories) : base(shopCatalogItem, categories) {
|
public ShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories) : base(shopCatalogItem, categories) {
|
||||||
Sku = shopCatalogItem.Sku;
|
Sku = shopCatalogItem.Sku;
|
||||||
Rating = shopCatalogItem.Rating;
|
Rating = shopCatalogItem.Rating;
|
||||||
Price = shopCatalogItem.Price;
|
Price = shopCatalogItem.Price;
|
||||||
@ -55,7 +55,7 @@ namespace WeatherForecast.Models {
|
|||||||
/// <param name="shopCatalogItem"></param>
|
/// <param name="shopCatalogItem"></param>
|
||||||
/// <param name="categories"></param>
|
/// <param name="categories"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
public GetShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories, Locales locale) : base(shopCatalogItem, categories, locale) {
|
public ShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories, Locales locale) : base(shopCatalogItem, categories, locale) {
|
||||||
Sku = shopCatalogItem.Sku;
|
Sku = shopCatalogItem.Sku;
|
||||||
Rating = shopCatalogItem.Rating;
|
Rating = shopCatalogItem.Rating;
|
||||||
Price = shopCatalogItem.Price;
|
Price = shopCatalogItem.Price;
|
||||||
@ -6,7 +6,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetShopItemsResponseModel : PaginationModelBase<GetShopItemResponseModel> {
|
public class ShopItemsResponseModel : PaginationModelBase<ShopItemResponseModel> {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -14,7 +14,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <param name="currentPage"></param>
|
/// <param name="currentPage"></param>
|
||||||
/// <param name="totalPages"></param>
|
/// <param name="totalPages"></param>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
public GetShopItemsResponseModel(int currentPage, int totalPages, List<GetShopItemResponseModel> items)
|
public ShopItemsResponseModel(int currentPage, int totalPages, List<ShopItemResponseModel> items)
|
||||||
: base(currentPage, totalPages, items) { }
|
: base(currentPage, totalPages, items) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,7 +5,7 @@ namespace WeatherForecast.Models.Responses {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetWeatherForecastResponseModel : ResponseModelBase {
|
public class WeatherForecastResponseModel : ResponseModelBase {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -17,7 +17,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel);
|
(Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -25,7 +25,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="blogId"></param>
|
/// <param name="blogId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId);
|
(BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -33,7 +33,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
(BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -42,7 +42,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="blogId"></param>
|
/// <param name="blogId"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData);
|
(Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -84,7 +84,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, BlogItemRequestModel requestModel) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="blogId"></param>
|
/// <param name="blogId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) {
|
public (BlogItemResponseModel?, IDomainResult) Get(Guid siteId, Guid blogId) {
|
||||||
var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId);
|
var (item, result) = _blogCatalogDataProvider.Get(siteId, blogId);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -109,7 +109,7 @@ namespace WeatherForecast.Services {
|
|||||||
categories.Add(category);
|
categories.Add(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new GetBlogItemResponseModel(item, categories));
|
return IDomainResult.Success(new BlogItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -118,7 +118,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (BlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -135,7 +135,7 @@ namespace WeatherForecast.Services {
|
|||||||
categories.Add(category);
|
categories.Add(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, locale));
|
return IDomainResult.Success(new BlogItemResponseModel(item, categories, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -146,7 +146,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, BlogItemRequestModel requestData) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetBlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText);
|
(BlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -67,12 +67,12 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetBlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) {
|
public (BlogItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) {
|
||||||
var (items, result) = _blogCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
var (items, result) = _blogCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
var blogItems = new List<GetBlogItemResponseModel>();
|
var blogItems = new List<BlogItemResponseModel>();
|
||||||
foreach (var item in items) {
|
foreach (var item in items) {
|
||||||
var categories = new List<Category>();
|
var categories = new List<Category>();
|
||||||
foreach (var catId in item.Categories) {
|
foreach (var catId in item.Categories) {
|
||||||
@ -84,14 +84,14 @@ namespace WeatherForecast.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(locale != null)
|
if(locale != null)
|
||||||
blogItems.Add(new GetBlogItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
blogItems.Add(new BlogItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
||||||
else
|
else
|
||||||
blogItems.Add(new GetBlogItemResponseModel(item, categories));
|
blogItems.Add(new BlogItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
return blogItems.Count > 0
|
return blogItems.Count > 0
|
||||||
? IDomainResult.Success(new GetBlogItemsResponseModel(currentPage, 0, blogItems))
|
? IDomainResult.Success(new BlogItemsResponseModel(currentPage, 0, blogItems))
|
||||||
: IDomainResult.NotFound<GetBlogItemsResponseModel?>();
|
: IDomainResult.NotFound<BlogItemsResponseModel?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel);
|
(Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -25,7 +25,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId);
|
(CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -33,7 +33,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
(CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -42,7 +42,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData);
|
(Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -80,7 +80,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, CategoryItemRequestModel requestModel) {
|
||||||
var (_, getResult) = _categoryDataProvider.GetBySlugs(siteId, requestModel.L10n.Select(x => x.Slug).ToList());
|
var (_, getResult) = _categoryDataProvider.GetBySlugs(siteId, requestModel.L10n.Select(x => x.Slug).ToList());
|
||||||
if (getResult.IsSuccess)
|
if (getResult.IsSuccess)
|
||||||
return IDomainResult.Failed<Guid?>();
|
return IDomainResult.Failed<Guid?>();
|
||||||
@ -103,12 +103,12 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) {
|
public (CategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId) {
|
||||||
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
return IDomainResult.Success(new GetCategoryItemResponseModel(item));
|
return IDomainResult.Success(new CategoryItemResponseModel(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -117,14 +117,14 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (CategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _categoryDataProvider.GetBySlug(siteId, slug);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us;
|
var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us;
|
||||||
|
|
||||||
return IDomainResult.Success(new GetCategoryItemResponseModel(item, locale));
|
return IDomainResult.Success(new CategoryItemResponseModel(item, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -134,7 +134,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="categoryId"></param>
|
/// <param name="categoryId"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, CategoryItemRequestModel requestData) {
|
||||||
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
var (item, result) = _categoryDataProvider.Get(siteId, categoryId);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(List<GetCategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale);
|
(List<CategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -54,16 +54,16 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (List<GetCategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale) {
|
public (List<CategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale) {
|
||||||
var (items, result) = _categoryDataProvider.GetAll(siteId);
|
var (items, result) = _categoryDataProvider.GetAll(siteId);
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us)).ToList());
|
return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us)).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x)).ToList());
|
return IDomainResult.Success(items.Select(x => new CategoryItemResponseModel(x)).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale);
|
(ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,13 +46,13 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) {
|
public (ContentResponseModel?, IDomainResult) GetContent(Guid siteId, string locale) {
|
||||||
var (content, result) = _contentDataProvider.Get(siteId, locale);
|
var (content, result) = _contentDataProvider.Get(siteId, locale);
|
||||||
|
|
||||||
if (!result.IsSuccess || content == null)
|
if (!result.IsSuccess || content == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
return IDomainResult.Success(new GetContentResponseModel(content));
|
return IDomainResult.Success(new ContentResponseModel(content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, PostShopCartItemRequestModel requestModel);
|
(Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -32,7 +32,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US");
|
(ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -42,7 +42,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, PutShopCartItemRequestModel requestData);
|
(Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -87,7 +87,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, PostShopCartItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestModel) {
|
||||||
var (_, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (_, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (getResult.IsSuccess)
|
if (getResult.IsSuccess)
|
||||||
return IDomainResult.Failed<Guid?>();
|
return IDomainResult.Failed<Guid?>();
|
||||||
@ -114,7 +114,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US") {
|
public (ShopCartItemResponseModel?, IDomainResult) Get(Guid siteId, Guid userId, string sku, string locale = "en-US") {
|
||||||
|
|
||||||
var (cartItem, getCartItemResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (cartItem, getCartItemResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (!getCartItemResult.IsSuccess || cartItem == null)
|
if (!getCartItemResult.IsSuccess || cartItem == null)
|
||||||
@ -124,7 +124,7 @@ namespace WeatherForecast.Services {
|
|||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
return IDomainResult.Success(new GetShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
return IDomainResult.Success(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -135,7 +135,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, PutShopCartItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, Guid userId, string sku, ShopCartItemRequestModel requestData) {
|
||||||
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
var (item, getResult) = _shopCartDataProvider.Get(siteId, userId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return (null, getResult);
|
return (null, getResult);
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(List<GetShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US");
|
(List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -64,24 +64,24 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (List<GetShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US") {
|
public (List<ShopCartItemResponseModel>?, IDomainResult) Get(Guid siteId, Guid userId, string locale = "en-US") {
|
||||||
|
|
||||||
var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId);
|
var (cartItems, getCartItemsResult) = _shopCartDataProvider.GetAll(siteId, userId);
|
||||||
if (!getCartItemsResult.IsSuccess || cartItems == null)
|
if (!getCartItemsResult.IsSuccess || cartItems == null)
|
||||||
return (null, getCartItemsResult);
|
return (null, getCartItemsResult);
|
||||||
|
|
||||||
var items = new List<GetShopCartItemResponseModel>();
|
var items = new List<ShopCartItemResponseModel>();
|
||||||
foreach (var cartItem in cartItems) {
|
foreach (var cartItem in cartItems) {
|
||||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
var (item, result) = _shopCatalogDataProvider.Get(siteId, cartItem.Sku);
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
items.Add(new GetShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
items.Add(new ShopCartItemResponseModel(item, cartItem, Enumeration.FromDisplayName<Locales>(locale)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.Count > 0
|
return items.Count > 0
|
||||||
? IDomainResult.Success(items)
|
? IDomainResult.Success(items)
|
||||||
: IDomainResult.NotFound<List<GetShopCartItemResponseModel>?>();
|
: IDomainResult.NotFound<List<ShopCartItemResponseModel>?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel);
|
(Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -29,7 +29,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku);
|
(ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -37,7 +37,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
(ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -46,7 +46,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData);
|
(Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -89,7 +89,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestModel"></param>
|
/// <param name="requestModel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel) {
|
public (Guid?, IDomainResult) Post(Guid siteId, string sku, ShopItemRequestModel requestModel) {
|
||||||
var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (_, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
if (getResult.IsSuccess)
|
if (getResult.IsSuccess)
|
||||||
return IDomainResult.Failed<Guid?>();
|
return IDomainResult.Failed<Guid?>();
|
||||||
@ -132,7 +132,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) {
|
public (ShopItemResponseModel?, IDomainResult) Get(Guid siteId, string sku) {
|
||||||
var (item, result) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (item, result) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -149,7 +149,7 @@ namespace WeatherForecast.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new GetShopItemResponseModel(item, categories));
|
return IDomainResult.Success(new ShopItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -158,7 +158,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="siteId"></param>
|
/// <param name="siteId"></param>
|
||||||
/// <param name="slug"></param>
|
/// <param name="slug"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
public (ShopItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) {
|
||||||
var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug);
|
var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug);
|
||||||
|
|
||||||
if (!result.IsSuccess || item == null)
|
if (!result.IsSuccess || item == null)
|
||||||
@ -177,7 +177,7 @@ namespace WeatherForecast.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IDomainResult.Success(new GetShopItemResponseModel(item, categories, locale));
|
return IDomainResult.Success(new ShopItemResponseModel(item, categories, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -187,7 +187,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="sku"></param>
|
/// <param name="sku"></param>
|
||||||
/// <param name="requestData"></param>
|
/// <param name="requestData"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) {
|
public (Guid?, IDomainResult) Update(Guid siteId, string sku, ShopItemRequestModel requestData) {
|
||||||
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
var (item, getResult) = _shopCatalogDataProvider.Get(siteId, sku);
|
||||||
if (!getResult.IsSuccess || item == null)
|
if (!getResult.IsSuccess || item == null)
|
||||||
return (null, getResult);
|
return (null, getResult);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText);
|
(ShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -67,14 +67,14 @@ namespace WeatherForecast.Services {
|
|||||||
/// <param name="locale"></param>
|
/// <param name="locale"></param>
|
||||||
/// <param name="searchText"></param>
|
/// <param name="searchText"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public (GetShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) {
|
public (ShopItemsResponseModel?, IDomainResult) Get(Guid siteId, Guid? category, int currentPage, int itemsPerPage, string? locale, string? searchText) {
|
||||||
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
var (items, result) = _shopCatalogDataProvider.GetAll(siteId, currentPage > 0 ? ((currentPage - 1) * itemsPerPage) : 0, itemsPerPage);
|
||||||
|
|
||||||
if (!result.IsSuccess || items == null)
|
if (!result.IsSuccess || items == null)
|
||||||
return (null, result);
|
return (null, result);
|
||||||
|
|
||||||
|
|
||||||
var shopItems = new List<GetShopItemResponseModel>();
|
var shopItems = new List<ShopItemResponseModel>();
|
||||||
foreach (var item in items) {
|
foreach (var item in items) {
|
||||||
|
|
||||||
var categories = new List<Category>();
|
var categories = new List<Category>();
|
||||||
@ -89,14 +89,14 @@ namespace WeatherForecast.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(locale != null)
|
if(locale != null)
|
||||||
shopItems.Add(new GetShopItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
shopItems.Add(new ShopItemResponseModel(item, categories, Enumeration.FromDisplayName<Locales>(locale) ?? Locales.Us));
|
||||||
else
|
else
|
||||||
shopItems.Add(new GetShopItemResponseModel(item, categories));
|
shopItems.Add(new ShopItemResponseModel(item, categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
return shopItems.Count > 0
|
return shopItems.Count > 0
|
||||||
? IDomainResult.Success(new GetShopItemsResponseModel(currentPage, 0, shopItems))
|
? IDomainResult.Success(new ShopItemsResponseModel(currentPage, 0, shopItems))
|
||||||
: IDomainResult.NotFound<GetShopItemsResponseModel?>();
|
: IDomainResult.NotFound<ShopItemsResponseModel?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user