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.Marketing.Courses;
using Grand.Data;
using Grand.Domain.Courses;
using Grand.Infrastructure.Extensions;
using Grand.Mediator;
namespace Grand.Business.Marketing.Services.Courses;
public class CourseActionService : ICourseActionService
{
private readonly IRepository<CourseAction> _courseActionRepository;
private readonly IMediator _mediator;
public CourseActionService(IRepository<CourseAction> courseActionRepository, IMediator mediator)
{
_courseActionRepository = courseActionRepository;
_mediator = mediator;
}
public virtual Task<CourseAction> GetById(string id)
{
return _courseActionRepository.GetByIdAsync(id);
}
public virtual async Task<CourseAction> GetCourseAction(string customerId, string lessonId)
{
var query = from a in _courseActionRepository.Table
where a.CustomerId == customerId && a.LessonId == lessonId
select a;
return await _courseActionRepository.FirstOrDefaultAsync(query);
}
public virtual async Task<bool> CustomerLessonCompleted(string customerId, string lessonId)
{
var query = await _courseActionRepository.FirstOrDefaultAsync(from a in _courseActionRepository.Table
where a.CustomerId == customerId && a.LessonId == lessonId
select a);
return query is { Finished: true };
}
public virtual async Task<CourseAction> InsertAsync(CourseAction courseAction)
{
ArgumentNullException.ThrowIfNull(courseAction);
await _courseActionRepository.InsertAsync(courseAction);
//event notification
await _mediator.EntityInserted(courseAction);
return courseAction;
}
public virtual async Task<CourseAction> Update(CourseAction courseAction)
{
ArgumentNullException.ThrowIfNull(courseAction);
await _courseActionRepository.UpdateAsync(courseAction);
//event notification
await _mediator.EntityUpdated(courseAction);
return courseAction;
}
}