75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using YD_WeChatApplet.Api.SmartSportsEntitys;
|
|
using YD_WeChatApplet.Api.Utilities;
|
|
using YD_WeChatApplet.Commons.Dto;
|
|
using YD_WeChatApplet.Commons.Dto.HomeWork;
|
|
using YD_WeChatApplet.Commons.Dto.School;
|
|
using YD_WeChatApplet.Context;
|
|
using YD_WeChatApplet.Services;
|
|
|
|
namespace YD_WeChatApplet.Api.Services.Impl
|
|
{
|
|
public class StudentService : IStudentService
|
|
{
|
|
public SmartSportsContext _sportsContext;
|
|
|
|
public StudentService(SmartSportsContext sportsContext)
|
|
{
|
|
_sportsContext = sportsContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取班级列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ClassListDto>> ClassListbyTeacher()
|
|
{
|
|
string teacherPhoneNo = UserLoginContext.Current.PhoneNo;
|
|
|
|
var classList = await (
|
|
from t in _sportsContext.Teacher
|
|
join a in _sportsContext.ClassAssocTeacher on t.Id equals a.TeacherId
|
|
join c in _sportsContext.Class on a.ClassId equals c.Id
|
|
where t.TeacherPhoneNo == teacherPhoneNo
|
|
select new ClassListDto()
|
|
{
|
|
GradeId = c.GradeId,
|
|
ClassId = c.Id,
|
|
Name = $"{c.GradeName ?? ""}-{c.ClassName ?? ""}"
|
|
}).ToListAsync();
|
|
|
|
return classList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取学生列表
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageDataDto<StudentListDto>> StudentListByClassId(StudentListByClassIdDto dto)
|
|
{
|
|
var query = _sportsContext.Student.Where(x => x.ClassId == dto.ClassId);
|
|
|
|
var totalCount = await query.CountAsync();
|
|
|
|
var students = await query
|
|
.Select(x => new StudentListDto()
|
|
{
|
|
StudentNo = x.StudentNo,
|
|
StudentName = x.StudentName,
|
|
Sex = x.Sex,
|
|
Photo = x.Photo
|
|
})
|
|
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
|
.Take(dto.PageSize)
|
|
.ToListAsync();
|
|
|
|
return new PageDataDto<StudentListDto>
|
|
{
|
|
Total = totalCount,
|
|
Datas = students
|
|
};
|
|
}
|
|
}
|
|
}
|