Skip to content

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.

1.8 KB
Raw Blame
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 CourseLevelService : ICourseLevelService
{
    private readonly IRepository<CourseLevel> _courseLevelRepository;
    private readonly IMediator _mediator;

    public CourseLevelService(IRepository<CourseLevel> courseLevelRepository, IMediator mediator)
    {
        _courseLevelRepository = courseLevelRepository;
        _mediator = mediator;
    }

    public virtual async Task Delete(CourseLevel courseLevel)
    {
        ArgumentNullException.ThrowIfNull(courseLevel);

        await _courseLevelRepository.DeleteAsync(courseLevel);

        //event notification
        await _mediator.EntityDeleted(courseLevel);
    }

    public virtual async Task<IList<CourseLevel>> GetAll()
    {
        var query = from l in _courseLevelRepository.Table
            orderby l.DisplayOrder
            select l;

        return await _courseLevelRepository.ToListAsync(query);
    }

    public virtual Task<CourseLevel> GetById(string id)
    {
        return _courseLevelRepository.GetByIdAsync(id);
    }

    public virtual async Task<CourseLevel> Insert(CourseLevel courseLevel)
    {
        ArgumentNullException.ThrowIfNull(courseLevel);

        await _courseLevelRepository.InsertAsync(courseLevel);

        //event notification
        await _mediator.EntityInserted(courseLevel);

        return courseLevel;
    }

    public virtual async Task<CourseLevel> Update(CourseLevel courseLevel)
    {
        ArgumentNullException.ThrowIfNull(courseLevel);

        await _courseLevelRepository.UpdateAsync(courseLevel);

        //event notification
        await _mediator.EntityUpdated(courseLevel);

        return courseLevel;
    }
}