88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 年级控制器
|
|
/// </summary>
|
|
public class ExamController : BackController<Exam>
|
|
{
|
|
readonly Repository<Exam> baseService;
|
|
readonly Repository<School> schoolService;
|
|
readonly Repository<ExamClassInfo> examClassInfoService;
|
|
readonly Repository<ExamUserInfo> examUserInfoService;
|
|
readonly LiveUserInfo userInfo;
|
|
public ExamController(Repository<Exam> baseService, LiveUserInfo userInfo,
|
|
Repository<ExamClassInfo> examClassInfoService, Repository<ExamUserInfo> examUserInfoService,
|
|
Repository<School> schoolService) : base(baseService)
|
|
{
|
|
this.baseService = baseService;
|
|
this.userInfo = userInfo;
|
|
this.examClassInfoService = examClassInfoService;
|
|
this.examUserInfoService = examUserInfoService;
|
|
this.schoolService = schoolService;
|
|
}
|
|
public override Task<dynamic> 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"
|
|
});
|
|
}
|
|
}
|
|
|
|
return base.PageList(model);
|
|
}
|
|
public override async Task<bool> 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);
|
|
return res ;
|
|
}
|
|
public override async Task<bool> 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);
|
|
}
|
|
}
|
|
}
|