You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.7 KiB
46 lines
1.7 KiB
using System.Linq;
|
|
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace StudyCenter.Controllers
|
|
{
|
|
public class CourseController : BaseController
|
|
{
|
|
private readonly IRepository<CourseCategory> _courseCategoryRepo;
|
|
private readonly IRepository<Course> _courseRepo;
|
|
|
|
public CourseController(IRepository<CourseCategory> courseCategoryRepo, IRepository<Course> courseRepo)
|
|
{
|
|
this._courseCategoryRepo = courseCategoryRepo;
|
|
this._courseRepo = courseRepo;
|
|
}
|
|
|
|
public IActionResult Index(CourseModel model)
|
|
{
|
|
var categoyies = this._courseCategoryRepo.ReadOnlyTable().Include(o => o.Parent).ToList();
|
|
model.Categories = categoyies;
|
|
var query = this._courseRepo.ReadOnlyTable();
|
|
if (model.CategoryId.HasValue)
|
|
{
|
|
var category = categoyies.FirstOrDefault(o => o.Id == model.CategoryId.Value);
|
|
query = query.Where(o => o.Category.Path.StartsWith(category.Path));
|
|
}
|
|
query = query.OrderBy(o => o.Category.DisplayOrder)
|
|
.ThenBy(o => o.Category.Number)
|
|
.ThenBy(o => o.DisplayOrder)
|
|
.ThenBy(o => o.Number);
|
|
model.TotalCount = query.Count();
|
|
model.List = query.Paged(model.PageIndex, model.PageSize);
|
|
foreach (var item in model.List)
|
|
{
|
|
item.Category = categoyies.FirstOrDefault(o => o.Id == item.CategoryId);
|
|
}
|
|
return View(model);
|
|
}
|
|
}
|
|
} |