87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using DomainResults.Common;
|
|
|
|
using DataProviders.Collections;
|
|
|
|
using Core.Abstractions;
|
|
using DomainObjects.Documents;
|
|
using DomainObjects.Enumerations;
|
|
using WeatherForecast.Models.ShopCart.Requests;
|
|
using WeatherForecast.Models.ShopCart.Responses;
|
|
using DomainObjects.Documents.Sites;
|
|
|
|
namespace WeatherForecast.Services
|
|
{
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public interface IShopCartItemsService {
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="cartItems"></param>
|
|
/// <param name="requestData"></param>
|
|
/// <returns></returns>
|
|
(List<GetShopCartItemLocalizedResponseModel>?, IDomainResult) Get(List<ShopCartDocument> cartItems, GetShopCartItemsLocalizedRequestModel requestData);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ShopCartItemsService : ServiceBase<ShopCartItemsService>, IShopCartItemsService {
|
|
|
|
private readonly IShopCatalogDataProvider _shopCatalogDataProvider;
|
|
private readonly IShopCartDataProvider _shopCartDataProvider;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="logger"></param>
|
|
/// <param name="shopCatalogDataProvider"></param>
|
|
/// <param name="shopCartDataprovider"></param>
|
|
public ShopCartItemsService(
|
|
ILogger<ShopCartItemsService> logger,
|
|
IShopCatalogDataProvider shopCatalogDataProvider,
|
|
IShopCartDataProvider shopCartDataprovider
|
|
) : base(logger) {
|
|
_shopCatalogDataProvider = shopCatalogDataProvider;
|
|
_shopCartDataProvider = shopCartDataprovider;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="cartItems"></param>
|
|
/// <param name="requestData"></param>
|
|
/// <returns></returns>
|
|
public (List<GetShopCartItemLocalizedResponseModel>?, IDomainResult) Get(List<ShopCartDocument> cartItems, GetShopCartItemsLocalizedRequestModel requestData) {
|
|
|
|
//var (count, getCountResult) = _shopCatalogDataProvider.Count(siteId);
|
|
//if (!getCountResult.IsSuccess || count == null)
|
|
// return (null, getCountResult);
|
|
|
|
//var skip = (requestData.CurrentPage - 1) * requestData.ItemsPerPage;
|
|
//var take = requestData.ItemsPerPage;
|
|
|
|
//var totalPages = (int)Math.Ceiling((decimal)count / take);
|
|
|
|
var items = new List<GetShopCartItemLocalizedResponseModel>();
|
|
foreach (var cartItem in cartItems) {
|
|
var (item, result) = _shopCatalogDataProvider.Get(cartItem.Id, cartItem.Sku);
|
|
if (!result.IsSuccess || item == null) {
|
|
var delteResult = _shopCartDataProvider.Delete(cartItem.Id);
|
|
if (!delteResult.IsSuccess)
|
|
return (null, delteResult);
|
|
}
|
|
else
|
|
items.Add(new GetShopCartItemLocalizedResponseModel(item, cartItem, requestData.Locale));
|
|
}
|
|
|
|
return items.Count > 0
|
|
? IDomainResult.Success(items)
|
|
: IDomainResult.NotFound<List<GetShopCartItemLocalizedResponseModel>?>();
|
|
}
|
|
}
|
|
}
|