Webiant Logo Webiant Logo
  1. No results found.

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

NopCommerceNewsViewComponent.cs

using Microsoft.AspNetCore.Mvc;
using Nop.Web.Areas.Admin.Factories;
using Nop.Web.Framework.Components;

namespace Nop.Web.Areas.Admin.Components;

/// 
/// Represents a view component that displays the nopCommerce news
/// 
public partial class NopCommerceNewsViewComponent : NopViewComponent
{
    #region Fields

    protected readonly IHomeModelFactory _homeModelFactory;

    #endregion

    #region Ctor

    public NopCommerceNewsViewComponent(IHomeModelFactory homeModelFactory)
    {
        _homeModelFactory = homeModelFactory;
    }

    #endregion

    #region Methods

    /// 
    /// Invoke view component
    /// 
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the view component result
    /// 
    public async Task InvokeAsync()
    {
        try
        {
            //prepare model
            var model = await _homeModelFactory.PrepareNopCommerceNewsModelAsync();

            return View(model);
        }
        catch
        {
            return Content(string.Empty);
        }
    }

    #endregion
}