Webiant Logo Webiant Logo
  1. No results found.

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

CustomerRfqMenuComponent.cs

using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Services.Customers;
using Nop.Web.Framework.Components;
using Nop.Web.Models.Customer;

namespace Nop.Plugin.Misc.RFQ.Components;

/// 
/// Represents the view component to display an item in the customer menu
/// 
public class CustomerRfqMenuComponent : NopViewComponent
{
    #region Fields

    private readonly ICustomerService _customerService;
    private readonly IWorkContext _workContext;
    private readonly RfqSettings _rfqSettings;

    #endregion

    #region Ctor

    public CustomerRfqMenuComponent(ICustomerService customerService, 
        IWorkContext workContext,
        RfqSettings rfqSettings)
    {
        _customerService = customerService;
        _workContext = workContext;
        _rfqSettings = rfqSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Invoke view component
    /// 
    /// Widget zone name
    /// Additional data
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the view component result
    /// 
    public async Task InvokeAsync(string widgetZone, object additionalData)
    {
        if (additionalData is not CustomerNavigationModel model)
            return Content(string.Empty);

        if (await _customerService.IsGuestAsync(await _workContext.GetCurrentCustomerAsync()))
            return Content(string.Empty);

        if (!_rfqSettings.Enabled)
            return Content(string.Empty);

        return View("~/Plugins/Misc.RFQ/Views/Components/CustomerRfqMenu.cshtml", model);
    }

    #endregion
}