2025-01-13 21:06:59 +08:00

48 lines
1.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using YD_XinWei.Api.Context;
using YD_XinWei.Api.Services.Interface;
using YD_XinWei.Api.SmartSportsEntitys;
using YD_XinWei.Commons.Dto.School;
namespace YD_XinWei.Api.Services.Impl
{
public class StudentService : IStudentService
{
public SmartSportsContext _sportsContext;
public StudentService(SmartSportsContext sportsContext)
{
_sportsContext = sportsContext;
}
public async Task<List<ClassListDto>> ClassListbyTeacher(string teacherPhoneNo)
{
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()
{
ClassId = c.Id,
Name = $"{c.GradeName}-{c.ClassName}"
}).ToListAsync();
return classList;
}
public async Task<List<StudentListDto>> StudentListByClassId(int classId)
{
var students = await _sportsContext.Student.Where(x => x.ClassId == classId).Select(x => new StudentListDto()
{
StudentNo = x.StudentNo,
StudentName = x.StudentName,
Sex = x.Sex,
Photo = x.Photo
}).ToListAsync();
return students;
}
}
}