Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

CustomWishlistService.cs

using Nop.Core.Domain.Orders;
using Nop.Data;

namespace Nop.Services.Orders;

/// 
/// Custom wishlist service
/// 
public partial class CustomWishlistService : ICustomWishlistService
{
    #region Fields

    protected readonly IRepository _customWishlistRepository;
    protected readonly ShoppingCartSettings _shoppingCartSettings;

    #endregion

    #region Ctor

    public CustomWishlistService(IRepository customWishlistRepository, 
        ShoppingCartSettings shoppingCartSettings)
    {
        _customWishlistRepository = customWishlistRepository;
        _shoppingCartSettings = shoppingCartSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Retrieves all custom wishlists associated with the specified customer.
    /// 
    /// The unique identifier of the customer whose custom wishlists are to be retrieved.
    /// A task that represents the asynchronous operation. The task result contains a list of   objects associated with the specified customer. If multiple wishlists  are not allowed,
    /// an empty list is returned.
    public virtual async Task> GetAllCustomWishlistsAsync(int customerId)
    {
        if (!_shoppingCartSettings.AllowMultipleWishlist)
            return new List();

        var query = _customWishlistRepository.Table
            .Where(w => w.CustomerId == customerId)
            .OrderByDescending(w => w.CreatedOnUtc);
        return await query.ToListAsync();
    }

    /// 
    /// Adds a custom wishlist item to the repository.
    /// 
    /// The custom wishlist item to add. Cannot be .
    public virtual async Task AddCustomWishlistAsync(CustomWishlist item)
    {

        await _customWishlistRepository.InsertAsync(item);
    }

    /// 
    /// Removes a custom wishlist item with the specified identifier.
    /// 
    /// The unique identifier of the custom wishlist item to remove. Must be a valid identifier of an existing item.
    public virtual async Task RemoveCustomWishlistAsync(int itemId)
    {
        var item = await _customWishlistRepository.GetByIdAsync(itemId);
        if (item != null)
        {
            await _customWishlistRepository.DeleteAsync(item);
        }
    }

    /// 
    /// Retrieves a custom wishlist by its unique identifier.
    /// 
    /// The unique identifier of the custom wishlist to retrieve. Must be a positive integer.
    /// A  object representing the custom wishlist with the specified identifier. Returns
    /// null if no wishlist is found with the given identifier.
    public virtual async Task GetCustomWishlistByIdAsync(int itemId)
    {
        return await _customWishlistRepository.GetByIdAsync(itemId);
    }

    #endregion
}