Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Vendors;
using Grand.Infrastructure;
using Grand.Web.Common.Components;
using Grand.Web.Features.Models.Vendors;
using Grand.Mediator;
using Microsoft.AspNetCore.Mvc;
namespace Grand.Web.Components;
public class VendorReviewsViewComponent : BaseViewComponent
{
#region Constructors
public VendorReviewsViewComponent(
IVendorService vendorService,
IGroupService groupService,
IContextAccessor contextAccessor,
IMediator mediator,
VendorSettings vendorSettings)
{
_vendorService = vendorService;
_groupService = groupService;
_contextAccessor = contextAccessor;
_mediator = mediator;
_vendorSettings = vendorSettings;
}
#endregion
#region Invoker
public async Task<IViewComponentResult> InvokeAsync(string vendorId)
{
var vendor = await _vendorService.GetVendorById(vendorId);
if (vendor is not { Active: true } || !vendor.AllowCustomerReviews)
return Content("");
var model = await _mediator.Send(new GetVendorReviews { Vendor = vendor });
//only registered users can leave reviews
if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) &&
!_vendorSettings.AllowAnonymousUsersToReviewVendor)
model.AddVendorReview.NotAllowAnonymousUsersToReviewVendor = true;
//default value
model.AddVendorReview.Rating = _vendorSettings.DefaultVendorRatingValue;
return View(model);
}
#endregion
#region Fields
private readonly IVendorService _vendorService;
private readonly IGroupService _groupService;
private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly VendorSettings _vendorSettings;
#endregion
}