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 CourseLessonService : ICourseLessonService
{
private readonly IRepository<CourseLesson> _courseLessonRepository;
private readonly IMediator _mediator;
public CourseLessonService(IRepository<CourseLesson> courseLessonRepository, IMediator mediator)
{
_courseLessonRepository = courseLessonRepository;
_mediator = mediator;
}
public virtual async Task Delete(CourseLesson courseLesson)
{
ArgumentNullException.ThrowIfNull(courseLesson);
await _courseLessonRepository.DeleteAsync(courseLesson);
//event notification
await _mediator.EntityDeleted(courseLesson);
}
public virtual async Task<IList<CourseLesson>> GetByCourseId(string courseId)
{
ArgumentNullException.ThrowIfNullOrEmpty(courseId);
var query = from c in _courseLessonRepository.Table
where c.CourseId == courseId
select c;
return await _courseLessonRepository.ToListAsync(query);
}
public virtual Task<CourseLesson> GetById(string id)
{
return _courseLessonRepository.GetByIdAsync(id);
}
public virtual async Task<CourseLesson> Insert(CourseLesson courseLesson)
{
ArgumentNullException.ThrowIfNull(courseLesson);
await _courseLessonRepository.InsertAsync(courseLesson);
//event notification
await _mediator.EntityInserted(courseLesson);
return courseLesson;
}
public virtual async Task<CourseLesson> Update(CourseLesson courseLesson)
{
ArgumentNullException.ThrowIfNull(courseLesson);
await _courseLessonRepository.UpdateAsync(courseLesson);
//event notification
await _mediator.EntityUpdated(courseLesson);
return courseLesson;
}
}