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; } /// /// 获取班级列表 /// /// public async Task> 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; } /// /// 获取学生列表 /// /// /// public async Task> 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 { Total = totalCount, Datas = students }; } } }