(refactor): services and models refactoring
This commit is contained in:
		
							parent
							
								
									a1071da8bf
								
							
						
					
					
						commit
						514b194c7e
					
				| @ -4,9 +4,14 @@ | |||||||
|       "siteId":"404c8232-9048-4519-bfba-6e78dc7005ca", |       "siteId":"404c8232-9048-4519-bfba-6e78dc7005ca", | ||||||
|       "l10n":[ |       "l10n":[ | ||||||
|         { |         { | ||||||
|             "locale":0, |           "locale": 0, | ||||||
|             "slug":"default", |           "slug": "default", | ||||||
|             "text":"Default category" |           "text": "Default category" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "locale": 2, | ||||||
|  |           "slug": "predefinit", | ||||||
|  |           "text": "Categoria predefinita" | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|    } |    } | ||||||
|  | |||||||
| @ -15,16 +15,16 @@ namespace Core.Abstractions.DomainObjects { | |||||||
| 
 | 
 | ||||||
|     public List<PostItemL10n> L10n { get; set; } |     public List<PostItemL10n> L10n { get; set; } | ||||||
| 
 | 
 | ||||||
|     public List<Image> Images { get; set; } |     public List<Image>? Images { get; set; } | ||||||
| 
 | 
 | ||||||
|     public Guid Author { get; set; } |     public Guid Author { get; set; } | ||||||
| 
 | 
 | ||||||
|     public DateTime Created { get; set; } |     public DateTime Created { get; set; } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public List<string> Tags { get; set; } |     public List<string>? Tags { get; set; } | ||||||
| 
 | 
 | ||||||
|     public List<Guid> Categories { get; set; } |     public List<Guid>? Categories { get; set; } | ||||||
| 
 | 
 | ||||||
|     public bool? FamilyFriendly { get; set; } |     public bool? FamilyFriendly { get; set; } | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -10,7 +10,7 @@ namespace Core.DomainObjects { | |||||||
|       unchecked { |       unchecked { | ||||||
|         int hash = 17; |         int hash = 17; | ||||||
|         hash = hash * 23 + Id.GetHashCode(); |         hash = hash * 23 + Id.GetHashCode(); | ||||||
|         hash = hash * 23 + L10n.Sum(x => x.GetHashCode()); |         hash = hash + L10n.Sum(x => x.GetHashCode() * 23); | ||||||
|         return hash; |         return hash; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ namespace Core.DomainObjects.L10n { | |||||||
|       unchecked { |       unchecked { | ||||||
|         int hash = 17; |         int hash = 17; | ||||||
|         hash = hash * 23 + Locale.GetHashCode(); |         hash = hash * 23 + Locale.GetHashCode(); | ||||||
|  |         hash = hash * 23 + Slug.GetHashCode(); | ||||||
|         hash = hash * 23 + Text.GetHashCode(); |         hash = hash * 23 + Text.GetHashCode(); | ||||||
|         return hash; |         return hash; | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ namespace Core.DomainObjects.L10n { | |||||||
|     public ContentTypes ContentType { get; set; } |     public ContentTypes ContentType { get; set; } | ||||||
|     public string PlainText { get; set; } |     public string PlainText { get; set; } | ||||||
|     public string ShortText { get; set; } |     public string ShortText { get; set; } | ||||||
|     public List<string> Badges { get; set; } |     public List<string>? Badges { get; set; } | ||||||
| 
 | 
 | ||||||
|     public override int GetHashCode() { |     public override int GetHashCode() { | ||||||
|       unchecked { |       unchecked { | ||||||
|  | |||||||
| @ -12,8 +12,8 @@ namespace DataProviders { | |||||||
|   public interface IBlogCatalogDataProvider { |   public interface IBlogCatalogDataProvider { | ||||||
|     (Guid?, IDomainResult) Insert(BlogItem blogItem); |     (Guid?, IDomainResult) Insert(BlogItem blogItem); | ||||||
|     (BlogItem?, IDomainResult) Get(Guid siteId, Guid blogId); |     (BlogItem?, IDomainResult) Get(Guid siteId, Guid blogId); | ||||||
|     (BlogItem?, IDomainResult) Get(Guid siteId, string slug); |     (BlogItem?, IDomainResult) GetBySlug(Guid siteId, string slug); | ||||||
|     (BlogItem?, IDomainResult) Get(Guid siteId, List<string> slugs); |     (List<BlogItem>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs); | ||||||
|     (List<BlogItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take); |     (List<BlogItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take); | ||||||
|     (Guid?, IDomainResult) Update(BlogItem blogItem); |     (Guid?, IDomainResult) Update(BlogItem blogItem); | ||||||
|     IDomainResult Delete(Guid id); |     IDomainResult Delete(Guid id); | ||||||
| @ -43,11 +43,8 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (BlogItem?, IDomainResult) Get(Guid siteId, string slug) => |     public (BlogItem?, IDomainResult) GetBySlug(Guid siteId, string slug) { | ||||||
|       Get(siteId, new List<string> { slug }); |       var (list, result) = GetBySlugs(siteId, new List<string> { slug }); | ||||||
| 
 |  | ||||||
|     public (BlogItem?, IDomainResult) Get(Guid siteId, List<string> slugs) { |  | ||||||
|       var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); |  | ||||||
| 
 | 
 | ||||||
|       if (!result.IsSuccess || list == null) |       if (!result.IsSuccess || list == null) | ||||||
|         return (null, result); |         return (null, result); | ||||||
| @ -55,6 +52,9 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public (List<BlogItem>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs) => | ||||||
|  |       GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); | ||||||
|  | 
 | ||||||
|     public (List<BlogItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take) => |     public (List<BlogItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take) => | ||||||
|       GetWithPredicate(x => x.SiteId == siteId, 0, 0, _collectionName); |       GetWithPredicate(x => x.SiteId == siteId, 0, 0, _collectionName); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,8 +13,8 @@ namespace DataProviders { | |||||||
|   public interface ICategoryDataProvider { |   public interface ICategoryDataProvider { | ||||||
|     (Guid?, IDomainResult) Insert(Category obj); |     (Guid?, IDomainResult) Insert(Category obj); | ||||||
|     (Category?, IDomainResult) Get(Guid siteId, Guid categoryId); |     (Category?, IDomainResult) Get(Guid siteId, Guid categoryId); | ||||||
|     (Category?, IDomainResult) Get(Guid siteId, string slug); |     (Category?, IDomainResult) GetBySlug(Guid siteId, string slug); | ||||||
|     (Category?, IDomainResult) Get(Guid siteId, List<string> slugs); |     (List<Category>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs); | ||||||
|     (List<Category>?, IDomainResult) GetAll(Guid siteId); |     (List<Category>?, IDomainResult) GetAll(Guid siteId); | ||||||
|     (Guid?, IDomainResult) Update(Category obj); |     (Guid?, IDomainResult) Update(Category obj); | ||||||
|     IDomainResult Delete(Guid id); |     IDomainResult Delete(Guid id); | ||||||
| @ -43,11 +43,8 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (Category?, IDomainResult) Get(Guid siteId, string slug) => |     public (Category?, IDomainResult) GetBySlug(Guid siteId, string slug) { | ||||||
|       Get(siteId, new List<string> { slug }); |       var (list, result) = GetBySlugs(siteId, new List<string> { slug }); | ||||||
| 
 |  | ||||||
|     public (Category?, IDomainResult) Get(Guid siteId, List<string> slugs) { |  | ||||||
|       var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); |  | ||||||
| 
 | 
 | ||||||
|       if (!result.IsSuccess || list == null) |       if (!result.IsSuccess || list == null) | ||||||
|         return (null, result); |         return (null, result); | ||||||
| @ -55,6 +52,9 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public (List<Category>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs) => | ||||||
|  |       GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); | ||||||
|  | 
 | ||||||
|     public (List<Category>?, IDomainResult) GetAll(Guid siteId) => |     public (List<Category>?, IDomainResult) GetAll(Guid siteId) => | ||||||
|       GetWithPredicate(x => x.SiteId == siteId, _collectionName); |       GetWithPredicate(x => x.SiteId == siteId, _collectionName); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,8 +12,8 @@ namespace DataProviders { | |||||||
|   public interface IShopCatalogDataProvider { |   public interface IShopCatalogDataProvider { | ||||||
|     (Guid?, IDomainResult) Insert(ShopItem obj); |     (Guid?, IDomainResult) Insert(ShopItem obj); | ||||||
|     (ShopItem?, IDomainResult) Get(Guid siteId, string sku); |     (ShopItem?, IDomainResult) Get(Guid siteId, string sku); | ||||||
|     //(ShopItem?, IDomainResult) Get(Guid siteId, string slug); |     (ShopItem?, IDomainResult) GetBySlug(Guid siteId, string slug); | ||||||
|     (ShopItem?, IDomainResult) Get(Guid siteId, List<string> slugs); |     (List<ShopItem>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs); | ||||||
|     (List<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take); |     (List<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take); | ||||||
|     (Guid?, IDomainResult) Update(ShopItem shopCart); |     (Guid?, IDomainResult) Update(ShopItem shopCart); | ||||||
|     IDomainResult Delete(Guid id); |     IDomainResult Delete(Guid id); | ||||||
| @ -43,11 +43,8 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //public (ShopItem?, IDomainResult) Get(Guid siteId, string slug) => |     public (ShopItem?, IDomainResult) GetBySlug(Guid siteId, string slug) { | ||||||
|     //  Get(siteId, new List<string> { slug }); |       var (list, result) = GetBySlugs(siteId, new List<string> { slug }); | ||||||
| 
 |  | ||||||
|     public (ShopItem?, IDomainResult) Get(Guid siteId, List<string> slugs) { |  | ||||||
|       var (list, result) = GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); |  | ||||||
| 
 | 
 | ||||||
|       if (!result.IsSuccess || list == null) |       if (!result.IsSuccess || list == null) | ||||||
|         return (null, result); |         return (null, result); | ||||||
| @ -55,6 +52,9 @@ namespace DataProviders { | |||||||
|       return (list.First(), result); |       return (list.First(), result); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public (List<ShopItem>?, IDomainResult) GetBySlugs(Guid siteId, List<string> slugs) => | ||||||
|  |       GetWithPredicate(x => x.SiteId == siteId && x.L10n.Any(y => slugs.Contains(y.Slug)), _collectionName); | ||||||
|  | 
 | ||||||
|     public (List<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take) => |     public (List<ShopItem>?, IDomainResult) GetAll(Guid siteId, int skip, int take) => | ||||||
|       GetWithPredicate(x => x.SiteId == siteId, skip, take, _collectionName); |       GetWithPredicate(x => x.SiteId == siteId, skip, take, _collectionName); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ namespace WeatherForecast.Controllers { | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     [HttpGet("{siteId}")] |     [HttpGet("{siteId}")] | ||||||
|     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { |     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { | ||||||
|       var result = _blogItemService.Get(siteId, slug); |       var result = _blogItemService.GetSlug(siteId, slug); | ||||||
|       return result.ToActionResult(); |       return result.ToActionResult(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ namespace WeatherForecast.Controllers { | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     [HttpGet("{siteId}")] |     [HttpGet("{siteId}")] | ||||||
|     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { |     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { | ||||||
|       var result = _categoryItemService.Get(siteId, slug); |       var result = _categoryItemService.GetSlug(siteId, slug); | ||||||
|       return result.ToActionResult(); |       return result.ToActionResult(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,9 +36,7 @@ namespace WeatherForecast.Controllers { | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     [HttpGet("{siteId}")] |     [HttpGet("{siteId}")] | ||||||
|     public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) { |     public IActionResult Get([FromRoute] Guid siteId, [FromQuery] string? locale) { | ||||||
|       var result = _categoryItemsService.Get(siteId, locale != null |       var result = _categoryItemsService.Get(siteId, locale); | ||||||
|         ? Enumeration.FromDisplayName<Locales>(locale) |  | ||||||
|         : Locales.Us); |  | ||||||
|       return result.ToActionResult(); |       return result.ToActionResult(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ namespace WeatherForecast.Controllers { | |||||||
|     /// <returns></returns> |     /// <returns></returns> | ||||||
|     [HttpGet("{siteId}")] |     [HttpGet("{siteId}")] | ||||||
|     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { |     public IActionResult GetSlug([FromRoute] Guid siteId, [FromQuery] string slug) { | ||||||
|       var result = _shopItemService.Get(siteId, slug); |       var result = _shopItemService.GetSlug(siteId, slug); | ||||||
|       return result.ToActionResult(); |       return result.ToActionResult(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,26 +2,33 @@ | |||||||
| using Core.Abstractions.Models; | using Core.Abstractions.Models; | ||||||
| using Core.DomainObjects; | using Core.DomainObjects; | ||||||
| using Core.Enumerations; | using Core.Enumerations; | ||||||
|  | using WeatherForecast.Models.L10n; | ||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models.Abstractions { | namespace WeatherForecast.Models.Abstractions { | ||||||
|   public abstract class PostItemResponseModelBase<T> : ResponseModelBase { |   public abstract class PostItemResponseModelBase<T> : ResponseModelBase { | ||||||
| 
 | 
 | ||||||
|     public string Slug { get; set; } |     public Guid Id { get; set; } | ||||||
|  |     public Guid SiteId { get; set; } | ||||||
|  | 
 | ||||||
|  |     public List<PostItemL10nModel>? L10n { get; set; } | ||||||
|  | 
 | ||||||
|  |     #region Localized costrutor | ||||||
|  |     public string? Slug { get; set; } | ||||||
|  | 
 | ||||||
|  |     public string? Description { get; set; } | ||||||
|  |     public string? Title { get; set; } | ||||||
|  | 
 | ||||||
|  |     public string? ShortText { get; set; } | ||||||
|  |     public string? Text { get; set; } | ||||||
|  |     public string? PlainText { get; set; } | ||||||
|  | 
 | ||||||
|  |     public string? ContentType { get; set; } | ||||||
|  |     public List<string>? Badges { get; set; } | ||||||
|  |     #endregion | ||||||
| 
 | 
 | ||||||
|     public string Description { get; set; } |  | ||||||
| 
 | 
 | ||||||
|     public List<ImageModel> Images { get; set; } |     public List<ImageModel> Images { get; set; } | ||||||
| 
 | 
 | ||||||
|     public List<string> Badges { get; set; } |  | ||||||
| 
 |  | ||||||
|     public string Title { get; set; } |  | ||||||
| 
 |  | ||||||
|     public string ShortText { get; set; } |  | ||||||
| 
 |  | ||||||
|     public string Text { get; set; } |  | ||||||
| 
 |  | ||||||
|     public string PlainText { get; set; } |  | ||||||
| 
 |  | ||||||
|     public AuthorModel Author { get; set; } |     public AuthorModel Author { get; set; } | ||||||
| 
 | 
 | ||||||
|     public DateTime Created { get; set; } |     public DateTime Created { get; set; } | ||||||
| @ -32,7 +39,22 @@ namespace WeatherForecast.Models.Abstractions { | |||||||
| 
 | 
 | ||||||
|     public bool? FamilyFriendly { get; set; } |     public bool? FamilyFriendly { get; set; } | ||||||
| 
 | 
 | ||||||
|     public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories, Locales locale) { |     public PostItemResponseModelBase(PostItemBase<T> postItem) { | ||||||
|  |       Id = postItem.Id; | ||||||
|  |       SiteId = postItem.SiteId; | ||||||
|  |       // Author = new AuthorModel(postItem.Author); | ||||||
|  |       Created = postItem.Created; | ||||||
|  |       Tags = postItem.Tags; | ||||||
|  |       FamilyFriendly = postItem.FamilyFriendly; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories) : this(postItem) { | ||||||
|  |       L10n = postItem.L10n.Select(x => new PostItemL10nModel(x)).ToList(); | ||||||
|  |       Categories = categories.Select(x => new CategoryModel(x)).ToList(); | ||||||
|  |       Images = postItem.Images.Select(x => new ImageModel(x)).ToList(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public PostItemResponseModelBase(PostItemBase<T> postItem, List<Category> categories, Locales locale) : this(postItem) { | ||||||
| 
 | 
 | ||||||
|       var postItemL10n = postItem.L10n.SingleOrDefault(x => x.Locale == locale); |       var postItemL10n = postItem.L10n.SingleOrDefault(x => x.Locale == locale); | ||||||
|       if (postItemL10n != null) { |       if (postItemL10n != null) { | ||||||
| @ -45,18 +67,8 @@ namespace WeatherForecast.Models.Abstractions { | |||||||
|         Badges = postItemL10n.Badges; |         Badges = postItemL10n.Badges; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|       Categories = categories.Select(x => new CategoryModel(x, locale)).ToList(); |       Categories = categories.Select(x => new CategoryModel(x, locale)).ToList(); | ||||||
| 
 |  | ||||||
|       // Author = new AuthorModel(postItem.Author); |  | ||||||
| 
 |  | ||||||
|       Created = postItem.Created; |  | ||||||
|       Tags = postItem.Tags; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|       Images = postItem.Images.Select(x => new ImageModel(x, locale)).ToList(); |       Images = postItem.Images.Select(x => new ImageModel(x, locale)).ToList(); | ||||||
| 
 |  | ||||||
|       FamilyFriendly = postItem.FamilyFriendly; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,13 +1,19 @@ | |||||||
| using Core.DomainObjects; | using Core.DomainObjects; | ||||||
| using Core.Enumerations; | using Core.Enumerations; | ||||||
|  | using WeatherForecast.Models.L10n; | ||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models { | namespace WeatherForecast.Models { | ||||||
|   public class CategoryModel { |   public class CategoryModel { | ||||||
|     public string Slug { get; set; } |     public List<CategoryL10nModel>? L10n { get; set; } | ||||||
|     public string Text { get; set; } | 
 | ||||||
|  |     public string? Slug { get; set; } | ||||||
|  |     public string? Text { get; set; } | ||||||
|  | 
 | ||||||
|  |     public CategoryModel(Category category) { | ||||||
|  |       L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     public CategoryModel(Category category, Locales locale) { |     public CategoryModel(Category category, Locales locale) { | ||||||
| 
 |  | ||||||
|       var categoryL10n = category.L10n.SingleOrDefault(x => x.Locale == locale); |       var categoryL10n = category.L10n.SingleOrDefault(x => x.Locale == locale); | ||||||
|       if (categoryL10n != null) { |       if (categoryL10n != null) { | ||||||
|         Slug = categoryL10n.Slug; |         Slug = categoryL10n.Slug; | ||||||
|  | |||||||
| @ -1,12 +1,17 @@ | |||||||
| using Core.DomainObjects; | using Core.DomainObjects; | ||||||
| using Core.Enumerations; | using Core.Enumerations; | ||||||
|  | using WeatherForecast.Models.L10n; | ||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models { | namespace WeatherForecast.Models { | ||||||
|   public class ImageModel { |   public class ImageModel { | ||||||
|     public string Src { get; set; } |     public List<ImageL10nModel>? L10n { get; set; }  | ||||||
|     public string Alt { get; set; } |  | ||||||
| 
 | 
 | ||||||
|     public ImageModel() { } |     public string? Src { get; set; } | ||||||
|  |     public string? Alt { get; set; } | ||||||
|  | 
 | ||||||
|  |     public ImageModel(Image image) { | ||||||
|  |       L10n = image.L10n.Select(x => new ImageL10nModel(x)).ToList(); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     public ImageModel(Image image, Locales locale) { |     public ImageModel(Image image, Locales locale) { | ||||||
|       Src = image.Src; |       Src = image.Src; | ||||||
|  | |||||||
| @ -10,6 +10,8 @@ namespace WeatherForecast.Models.L10n { | |||||||
|     public string Slug { get; set; } |     public string Slug { get; set; } | ||||||
|     public string Text { get; set; } |     public string Text { get; set; } | ||||||
| 
 | 
 | ||||||
|  |     public CategoryL10nModel() { } | ||||||
|  | 
 | ||||||
|     public CategoryL10nModel(CategoryL10n categoryL10n) { |     public CategoryL10nModel(CategoryL10n categoryL10n) { | ||||||
|       Locale = categoryL10n.Locale.Name; |       Locale = categoryL10n.Locale.Name; | ||||||
|       Slug = categoryL10n.Slug; |       Slug = categoryL10n.Slug; | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								webapi/WeatherForecast/Models/L10n/ImageL10nModel.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | |||||||
|  | using Core.Abstractions; | ||||||
|  | using Core.Abstractions.Models; | ||||||
|  | using Core.DomainObjects.L10n; | ||||||
|  | using Core.Enumerations; | ||||||
|  | 
 | ||||||
|  | namespace WeatherForecast.Models.L10n { | ||||||
|  |   public class ImageL10nModel : ModelBase { | ||||||
|  |     public string Locale { get; set; } | ||||||
|  |     public string Alt { get; set; } | ||||||
|  | 
 | ||||||
|  |     public ImageL10nModel() { } | ||||||
|  | 
 | ||||||
|  |     public ImageL10nModel(ImageL10n imageL10n) { | ||||||
|  |       Locale = imageL10n.Locale.Name; | ||||||
|  |       Alt = imageL10n.Alt; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public ImageL10n ToDomainObject() => new ImageL10n { | ||||||
|  |       Locale = Enumeration.FromDisplayName<Locales>(Locale), | ||||||
|  |       Alt = Alt | ||||||
|  |     }; | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -13,9 +13,12 @@ namespace WeatherForecast.Models.L10n { | |||||||
| 
 | 
 | ||||||
|     public string ShortText { get; set; } |     public string ShortText { get; set; } | ||||||
|     public string Text { get; set; } |     public string Text { get; set; } | ||||||
|  |     public string PlainText { get; set; } | ||||||
| 
 | 
 | ||||||
|     public string ContentType { get; set; } |     public string ContentType { get; set; } | ||||||
|     public List<string> Badges { get; set; } |     public List<string>? Badges { get; set; } | ||||||
|  | 
 | ||||||
|  |     public PostItemL10nModel() { } | ||||||
| 
 | 
 | ||||||
|     public PostItemL10nModel(PostItemL10n postItemL10n) { |     public PostItemL10nModel(PostItemL10n postItemL10n) { | ||||||
|       Locale = postItemL10n.Locale.Name; |       Locale = postItemL10n.Locale.Name; | ||||||
|  | |||||||
| @ -1,10 +1,23 @@ | |||||||
| using Core.Abstractions.Models; | using Core.Abstractions.Models; | ||||||
| using Core.DomainObjects.Documents; | using Core.DomainObjects.Documents; | ||||||
|  | using WeatherForecast.Models.Abstractions; | ||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models.Requests { | namespace WeatherForecast.Models.Requests { | ||||||
|   public class PostBlogItemRequestModel : RequestModelBase<BlogItem> { |   public class PostBlogItemRequestModel : PostItemRequestModelBase<BlogItem> { | ||||||
|     public override BlogItem ToDomainObject() { |     public uint? ReadTime { get; set; } | ||||||
|       throw new NotImplementedException(); |     public uint? Likes { get; set; } | ||||||
|     } | 
 | ||||||
|  |     public override BlogItem ToDomainObject() => new BlogItem { | ||||||
|  |       L10n = L10n.Select(x => x.ToDomainObject()).ToList(), | ||||||
|  |       // Images | ||||||
|  |       // Author | ||||||
|  |       Created = DateTime.UtcNow, | ||||||
|  |       Tags = Tags, | ||||||
|  |       Categories = Categories, | ||||||
|  |       FamilyFriendly = FamilyFriendly, | ||||||
|  | 
 | ||||||
|  |       ReadTime = ReadTime, | ||||||
|  |       Likes = Likes | ||||||
|  |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,23 @@ | |||||||
| using Core.Abstractions.Models; | using Core.Abstractions.Models; | ||||||
| using Core.DomainObjects.Documents; | using Core.DomainObjects.Documents; | ||||||
|  | using WeatherForecast.Models.Abstractions; | ||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models.Requests { | namespace WeatherForecast.Models.Requests { | ||||||
|   public class PutBlogItemRequestModel : RequestModelBase<BlogItem> { |   public class PutBlogItemRequestModel : PostItemRequestModelBase<BlogItem> { | ||||||
|     public override BlogItem ToDomainObject() { |     public uint? ReadTime { get; set; } | ||||||
|       throw new NotImplementedException(); |     public uint? Likes { get; set; } | ||||||
|     } | 
 | ||||||
|  |     public override BlogItem ToDomainObject() => new BlogItem { | ||||||
|  |       L10n = L10n.Select(x => x.ToDomainObject()).ToList(), | ||||||
|  |       // Images | ||||||
|  |       // Author | ||||||
|  |       Created = DateTime.UtcNow, | ||||||
|  |       Tags = Tags, | ||||||
|  |       Categories = Categories, | ||||||
|  |       FamilyFriendly = FamilyFriendly, | ||||||
|  | 
 | ||||||
|  |       ReadTime = ReadTime, | ||||||
|  |       Likes = Likes | ||||||
|  |     }; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -12,6 +12,11 @@ namespace WeatherForecast.Models.Responses { | |||||||
| 
 | 
 | ||||||
|     public uint? Likes { get; set; } |     public uint? Likes { get; set; } | ||||||
| 
 | 
 | ||||||
|  |     public GetBlogItemResponseModel(BlogItem blogItem, List<Category> categories) : base(blogItem, categories) { | ||||||
|  |       ReadTime = blogItem.ReadTime; | ||||||
|  |       Likes = blogItem.Likes; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public GetBlogItemResponseModel(BlogItem blogItem, List<Category> categories, Locales locale) : base(blogItem, categories, locale) { |     public GetBlogItemResponseModel(BlogItem blogItem, List<Category> categories, Locales locale) : base(blogItem, categories, locale) { | ||||||
|       ReadTime = blogItem.ReadTime; |       ReadTime = blogItem.ReadTime; | ||||||
|       Likes = blogItem.Likes; |       Likes = blogItem.Likes; | ||||||
|  | |||||||
| @ -5,17 +5,26 @@ using WeatherForecast.Models.L10n; | |||||||
| 
 | 
 | ||||||
| namespace WeatherForecast.Models.Responses { | namespace WeatherForecast.Models.Responses { | ||||||
|   public class GetCategoryItemResponseModel : ResponseModelBase { |   public class GetCategoryItemResponseModel : ResponseModelBase { | ||||||
| 
 |     public Guid Id { get; set; } | ||||||
|  |     public Guid SiteId { get; set; } | ||||||
|     public string? Slug { get; set; } |     public string? Slug { get; set; } | ||||||
|     public string? Text { get; set; } |     public string? Text { get; set; } | ||||||
| 
 | 
 | ||||||
|     public List<CategoryL10nModel>? L10n { get; set; } |     public List<CategoryL10nModel>? L10n { get; set; } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     public GetCategoryItemResponseModel(Category category) { |     public GetCategoryItemResponseModel(Category category) { | ||||||
|  |       Id = category.Id; | ||||||
|  |       SiteId = category.SiteId; | ||||||
|  | 
 | ||||||
|       L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); |       L10n = category.L10n.Select(x => new CategoryL10nModel(x)).ToList(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public GetCategoryItemResponseModel(Category category, Locales locale) { |     public GetCategoryItemResponseModel(Category category, Locales locale) { | ||||||
|  |       Id = category.Id; | ||||||
|  |       SiteId = category.SiteId; | ||||||
|  | 
 | ||||||
|       var l10n = category.L10n.SingleOrDefault(x => x.Locale == locale); |       var l10n = category.L10n.SingleOrDefault(x => x.Locale == locale); | ||||||
|       if (l10n != null) { |       if (l10n != null) { | ||||||
|         Slug = l10n.Slug; |         Slug = l10n.Slug; | ||||||
|  | |||||||
| @ -13,6 +13,14 @@ namespace WeatherForecast.Models { | |||||||
|     public decimal? NewPrice { get; set; } |     public decimal? NewPrice { get; set; } | ||||||
|     public uint? Quantity { get; set; } |     public uint? Quantity { get; set; } | ||||||
| 
 | 
 | ||||||
|  |     public GetShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories) : base(shopCatalogItem, categories) { | ||||||
|  |       Sku = shopCatalogItem.Sku; | ||||||
|  |       Rating = shopCatalogItem.Rating; | ||||||
|  |       Price = shopCatalogItem.Price; | ||||||
|  |       NewPrice = shopCatalogItem.NewPrice; | ||||||
|  |       Quantity = shopCatalogItem.Quantity; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public GetShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories, Locales locale) : base(shopCatalogItem, categories, locale) { |     public GetShopItemResponseModel(ShopItem shopCatalogItem, List<Category> categories, Locales locale) : base(shopCatalogItem, categories, locale) { | ||||||
|       Sku = shopCatalogItem.Sku; |       Sku = shopCatalogItem.Sku; | ||||||
|       Rating = shopCatalogItem.Rating; |       Rating = shopCatalogItem.Rating; | ||||||
|  | |||||||
| @ -10,7 +10,7 @@ namespace WeatherForecast.Services { | |||||||
|   public interface IBlogItemService { |   public interface IBlogItemService { | ||||||
|     (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel); |     (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel); | ||||||
|     (GetBlogItemResponseModel, IDomainResult) Get(Guid siteId, Guid blogId); |     (GetBlogItemResponseModel, IDomainResult) Get(Guid siteId, Guid blogId); | ||||||
|     (GetBlogItemResponseModel, IDomainResult) Get(Guid siteId, string slug); |     (GetBlogItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug); | ||||||
|     (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData); |     (Guid?, IDomainResult) Update(Guid siteId, Guid blogId, PutBlogItemRequestModel requestData); | ||||||
|     IDomainResult Delete(Guid siteId, Guid blogId); |     IDomainResult Delete(Guid siteId, Guid blogId); | ||||||
|   } |   } | ||||||
| @ -22,10 +22,12 @@ namespace WeatherForecast.Services { | |||||||
| 
 | 
 | ||||||
|     public BlogItemService( |     public BlogItemService( | ||||||
|       ILogger<BlogItemService> logger, |       ILogger<BlogItemService> logger, | ||||||
|       IBlogCatalogDataProvider blogCatalogDataProvider |       IBlogCatalogDataProvider blogCatalogDataProvider, | ||||||
|  |       ICategoryDataProvider categoryDataProvider | ||||||
|     ) { |     ) { | ||||||
|       _logger = logger; |       _logger = logger; | ||||||
|       _blogCatalogDataProvider = blogCatalogDataProvider; |       _blogCatalogDataProvider = blogCatalogDataProvider; | ||||||
|  |       _categoryDataProvider = categoryDataProvider; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) { |     public (Guid?, IDomainResult) Post(Guid siteId, PostBlogItemRequestModel requestModel) { | ||||||
| @ -40,18 +42,18 @@ namespace WeatherForecast.Services { | |||||||
| 
 | 
 | ||||||
|       var categories = new List<Category>(); |       var categories = new List<Category>(); | ||||||
|       foreach (var catId in item.Categories) { |       foreach (var catId in item.Categories) { | ||||||
|         var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); |         var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|         if (!getCategoryResult.IsSuccess || category == null) |         if (!getCategoryResult.IsSuccess || category == null) | ||||||
|           return (null, getCategoryResult); |           return (null, getCategoryResult); | ||||||
| 
 | 
 | ||||||
|         categories.Add(category); |         categories.Add(category); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       return IDomainResult.Success(new GetBlogItemResponseModel(item, categories, Locales.Us)); |       return IDomainResult.Success(new GetBlogItemResponseModel(item, categories)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (GetBlogItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { |     public (GetBlogItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { | ||||||
|       var (item, result) = _blogCatalogDataProvider.Get(siteId, slug); |       var (item, result) = _blogCatalogDataProvider.GetBySlug(siteId, slug); | ||||||
| 
 | 
 | ||||||
|       if (!result.IsSuccess || item == null) |       if (!result.IsSuccess || item == null) | ||||||
|         return (null, result); |         return (null, result); | ||||||
| @ -60,7 +62,7 @@ namespace WeatherForecast.Services { | |||||||
| 
 | 
 | ||||||
|       var categories = new List<Category>(); |       var categories = new List<Category>(); | ||||||
|       foreach (var catId in item.Categories) { |       foreach (var catId in item.Categories) { | ||||||
|         var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); |         var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|         if (!getCategoryResult.IsSuccess || category == null) |         if (!getCategoryResult.IsSuccess || category == null) | ||||||
|           return (null, getCategoryResult); |           return (null, getCategoryResult); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ namespace WeatherForecast.Services { | |||||||
|       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) { | ||||||
|           var (cat, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); |           var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|           if (!getCategoryResult.IsSuccess || cat == null) |           if (!getCategoryResult.IsSuccess || cat == null) | ||||||
|             return (null, getCategoryResult); |             return (null, getCategoryResult); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ namespace WeatherForecast.Services { | |||||||
|   public interface ICategoryItemService { |   public interface ICategoryItemService { | ||||||
|     (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel); |     (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel); | ||||||
|     (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId); |     (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, Guid categoryId); | ||||||
|     (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, string slug); |     (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug); | ||||||
|     (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData); |     (Guid?, IDomainResult) Update(Guid siteId, Guid categoryId, PutCategoryItemRequestModel requestData); | ||||||
|     IDomainResult Delete(Guid siteId, Guid categoryId); |     IDomainResult Delete(Guid siteId, Guid categoryId); | ||||||
|   } |   } | ||||||
| @ -27,7 +27,7 @@ namespace WeatherForecast.Services { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel) { |     public (Guid?, IDomainResult) Post(Guid siteId, PostCategoryItemRequestModel requestModel) { | ||||||
|       var (_, getResult) = _categoryDataProvider.Get(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?>(); | ||||||
| 
 | 
 | ||||||
| @ -51,8 +51,8 @@ namespace WeatherForecast.Services { | |||||||
|       return IDomainResult.Success(new GetCategoryItemResponseModel(item)); |       return IDomainResult.Success(new GetCategoryItemResponseModel(item)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (GetCategoryItemResponseModel?, IDomainResult) Get(Guid siteId, string slug) { |     public (GetCategoryItemResponseModel?, IDomainResult) GetSlug(Guid siteId, string slug) { | ||||||
|       var (item, result) = _categoryDataProvider.Get(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); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| using Core.Enumerations; | using Core.Abstractions; | ||||||
|  | using Core.Enumerations; | ||||||
| using DataProviders; | using DataProviders; | ||||||
| using DomainResults.Common; | using DomainResults.Common; | ||||||
| using WeatherForecast.Models.Responses; | using WeatherForecast.Models.Responses; | ||||||
| @ -6,7 +7,7 @@ using WeatherForecast.Models.Responses; | |||||||
| namespace WeatherForecast.Services { | namespace WeatherForecast.Services { | ||||||
| 
 | 
 | ||||||
|   public interface ICategoryItemsService { |   public interface ICategoryItemsService { | ||||||
|     (List<GetCategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, Locales locale); |     (List<GetCategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, string? locale); | ||||||
|     IDomainResult Delete(Guid siteId); |     IDomainResult Delete(Guid siteId); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -23,12 +24,16 @@ namespace WeatherForecast.Services { | |||||||
|       _categoryDataProvider = categoryDataProvider; |       _categoryDataProvider = categoryDataProvider; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (List<GetCategoryItemResponseModel>?, IDomainResult) Get(Guid siteId, Locales locale) { |     public (List<GetCategoryItemResponseModel>?, 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); | ||||||
| 
 | 
 | ||||||
|       return IDomainResult.Success(items.Select(x => new GetCategoryItemResponseModel(x, locale)).ToList()); |       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 GetCategoryItemResponseModel(x)).ToList()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public IDomainResult Delete(Guid siteId) => _categoryDataProvider.DeleteAll(siteId); |     public IDomainResult Delete(Guid siteId) => _categoryDataProvider.DeleteAll(siteId); | ||||||
|  | |||||||
| @ -12,6 +12,8 @@ namespace WeatherForecast.Services { | |||||||
|   public interface IShopItemService { |   public interface IShopItemService { | ||||||
|     (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel); |     (Guid?, IDomainResult) Post(Guid siteId, string sku, PostShopItemRequestModel requestModel); | ||||||
|     (GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku); |     (GetShopItemResponseModel, IDomainResult) Get(Guid siteId, string sku); | ||||||
|  | 
 | ||||||
|  |     (GetShopItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug); | ||||||
|     (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData); |     (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData); | ||||||
|     IDomainResult Delete(Guid siteId, string sku); |     IDomainResult Delete(Guid siteId, string sku); | ||||||
|   } |   } | ||||||
| @ -77,14 +79,34 @@ namespace WeatherForecast.Services { | |||||||
| 
 | 
 | ||||||
|       var categories = new List<Category>(); |       var categories = new List<Category>(); | ||||||
|       foreach (var catId in item.Categories) { |       foreach (var catId in item.Categories) { | ||||||
|         var (category, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); |         var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|         if (!getCategoryResult.IsSuccess || category == null) |         if (!getCategoryResult.IsSuccess || category == null) | ||||||
|           return (null, getCategoryResult); |           return (null, getCategoryResult); | ||||||
| 
 | 
 | ||||||
|         categories.Add(category); |         categories.Add(category); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       return IDomainResult.Success(new GetShopItemResponseModel(item, categories, Locales.Us)); |       return IDomainResult.Success(new GetShopItemResponseModel(item, categories)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public (GetShopItemResponseModel, IDomainResult) GetSlug(Guid siteId, string slug) { | ||||||
|  |       var (item, result) = _shopCatalogDataProvider.GetBySlug(siteId, slug); | ||||||
|  | 
 | ||||||
|  |       if (!result.IsSuccess || item == null) | ||||||
|  |         return (null, result); | ||||||
|  | 
 | ||||||
|  |       var locale = item.L10n.SingleOrDefault(x => x.Slug == slug)?.Locale ?? Locales.Us; | ||||||
|  | 
 | ||||||
|  |       var categories = new List<Category>(); | ||||||
|  |       foreach (var catId in item.Categories) { | ||||||
|  |         var (category, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|  |         if (!getCategoryResult.IsSuccess || category == null) | ||||||
|  |           return (null, getCategoryResult); | ||||||
|  | 
 | ||||||
|  |         categories.Add(category); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       return IDomainResult.Success(new GetShopItemResponseModel(item, categories, locale)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) { |     public (Guid?, IDomainResult) Update(Guid siteId, string sku, PutShopItemRequestModel requestData) { | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ namespace WeatherForecast.Services { | |||||||
|       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) { | ||||||
|           var (cat, getCategoryResult) = _categoryDataProvider.Get(catId, siteId); |           var (cat, getCategoryResult) = _categoryDataProvider.Get(siteId, catId); | ||||||
|           if (!getCategoryResult.IsSuccess || cat == null) |           if (!getCategoryResult.IsSuccess || cat == null) | ||||||
|             return (null, getCategoryResult); |             return (null, getCategoryResult); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user