using AlibabaCloud.SDK.Vod20170321.Models; using Learn.Archives.API.Controllers.Dto; using Learn.Archives.API.Expand; using Learn.Archives.Core.Common; using Learn.Archives.Core.Model; using Learn.Archives.Core.Model.Dto; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using System.Security.Claims; using UserCenter.Model; using UserCenter.Model.Common; namespace Learn.Archives.API.Controllers { /// /// 年级控制器 /// public class ExamController : BackController { readonly Repository baseService; readonly Repository schoolService; readonly Repository tagService; readonly Repository examClassInfoService; readonly Repository examUserInfoService; readonly LiveUserInfo userInfo; public ExamController(Repository baseService, LiveUserInfo userInfo, Repository examClassInfoService, Repository examUserInfoService, Repository schoolService, Repository tagService) : base(baseService) { this.baseService = baseService; this.userInfo = userInfo; this.examClassInfoService = examClassInfoService; this.examUserInfoService = examUserInfoService; this.schoolService = schoolService; this.tagService = tagService; } public override Task PageList([FromBody] QueryRequestBase model) { var c = model.Conditions.FirstOrDefault(s => s.FieldName == "Grade"); if (c != null) { var gInfo = GradeHelper.GetStudentGradeBaseByGrade(c.FieldValue); if (gInfo != null) { model.Conditions = model.Conditions.Where(s => s != c).ToList(); model.Conditions.Add(new SqlSugar.ConditionalModel() { FieldName = "GradeLevel", FieldValue = gInfo.GradeLevel, }); model.Conditions.Add(new SqlSugar.ConditionalModel() { FieldName = "GradeYear", FieldValue = gInfo.GradeYear.ToString(), CSharpTypeName = "int" }); } else { Oh.ModelError($"传入了无法识别的 年级 => {c.FieldValue}"); } } return base.PageList(model); } public override async Task Edit([FromBody] Exam model) { if (!string.IsNullOrEmpty(model._grade)) { var g = GradeHelper.GetStudentGradeBaseByGrade(model._grade); model.GradeLevel = g.GradeLevel; model.GradeYear = g.GradeYear; } var res =await base.Edit(model); if (res) await ExamClassInfoController.CalculatingTestResults(model, examUserInfoService, schoolService, tagService); return res ; } public override async Task Del([FromBody] params long[] ids) { if (ids.Length > 1) Oh.ModelError("同时只允许删除一场考试"); var id= ids.First(); var dCount = await examClassInfoService.AsDeleteable().Where(s => s.ExamId == id) .ExecuteCommandAsync(); var dCount1 = await examUserInfoService.AsDeleteable().Where(s => s.ExamId == id) .ExecuteCommandAsync(); return await base.Del(ids); } } }