changed into single selection
continuous-integration/drone/push Build is passing Details

master
ceruIean 2021-12-09 14:23:20 +08:00
parent e6def6d600
commit a0975cf083
1 changed files with 23 additions and 9 deletions

View File

@ -70,7 +70,7 @@ namespace _2021_backend.Controllers
public IActionResult GetSessions()
{
var query = _context.Sessions.OrderBy(r => r.Day).ThenBy(r => r.BeginTime).ThenBy(r => r.Place).Where(e => e.Capacity > e.Students.Count + 1).Select(r => new SessionDto
var query = _context.Sessions.OrderBy(r => r.Day).ThenBy(r => r.BeginTime).ThenBy(r => r.Place).Where(e => e.Capacity > e.Students.Count).Select(r => new SessionDto
{
BeginTime = r.BeginTime,
Day = r.Day,
@ -98,10 +98,10 @@ namespace _2021_backend.Controllers
{
return StatusCode(400, ApiResponse.Error("INVALID_STUDENT_GUID"));
}
List<SessionDto> timelist;
SessionDto time;
try
{
timelist = JsonSerializer.Deserialize<List<SessionDto>>(selection);
time = JsonSerializer.Deserialize<SessionDto>(selection);
}
catch (Exception ex)
{
@ -109,15 +109,29 @@ namespace _2021_backend.Controllers
return StatusCode(400, ApiResponse.Error("MALFORMED_DATA"));
};
//get the selected session guids;
List<Guid> targetSessions;
Guid targetSession = Guid.Empty;
var sessions = Context.Sessions.ToList();
targetSessions = sessions.FindAll((Session s) =>
var s = sessions.Find((Session s) =>
{
return timelist.Any(it => it.Day == s.Day && it.BeginTime == s.BeginTime);
}).Select(it => it.Guid).ToList();
stu.Timelist = targetSessions;
return time.Day == s.Day && time.BeginTime == s.BeginTime;
});
var overwritten = false;
if (s.Students.Count >= s.Capacity) return Ok(ApiResponse.Error("OUT_OF_CAPACITY"));
if (Context.Sessions.Find(stu.InterviewTime) != null)
{
var olds = Context.Sessions.Find(stu.InterviewTime);
olds.Students.Remove(stu.Guid);
Context.SaveChanges();
overwritten = true;
}
targetSession = s.Guid;
s.Students.Add(stu.Guid);
stu.Timelist = new List<Guid> { targetSession};
stu.Status = status.;
await Context.SaveChangesAsync();
stu.InterviewTime = s.Guid;
await TencentSMS.Send(Context, SMSType.TimeSet, stu, "smsbot");
Context.SaveChanges();
if (overwritten) return Ok(ApiResponse.Success("overwritten"));
return Ok(ApiResponse.Success("success"));
//return Ok(ApiResponse.Success("报名结束了"));