This commit is contained in:
@@ -79,4 +79,48 @@ namespace _2021_backend.Controllers
|
||||
//return Ok(ApiResponse.Success("报名结束了"));
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("api/postsession")]
|
||||
public class PostsessionController : Controller
|
||||
{
|
||||
private readonly BackendContext Context;
|
||||
public PostsessionController(BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
[HttpPost]
|
||||
|
||||
public async Task<IActionResult> Post([FromQuery] string stuid, [FromQuery] string selection)
|
||||
{
|
||||
Student stu = Context.Students.FirstOrDefault(r => r.Stuid == stuid);
|
||||
if (stu == null)
|
||||
{
|
||||
return StatusCode(400, ApiResponse.Error("INVALID_STUDENT_GUID"));
|
||||
}
|
||||
List<SessionDto> timelist;
|
||||
try
|
||||
{
|
||||
timelist = JsonSerializer.Deserialize<List<SessionDto>>(selection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
return StatusCode(400, ApiResponse.Error("MALFORMED_DATA"));
|
||||
};
|
||||
//get the selected session guids;
|
||||
List<Guid> targetSessions;
|
||||
var sessions = Context.Sessions.ToList();
|
||||
targetSessions = sessions.FindAll((Session s) =>
|
||||
{
|
||||
return timelist.Any(it => it.Day == s.Day && it.BeginTime == s.BeginTime);
|
||||
}).Select(it => it.Guid).ToList();
|
||||
stu.Timelist = targetSessions;
|
||||
stu.Status = status.已选时间;
|
||||
await Context.SaveChangesAsync();
|
||||
return Ok(ApiResponse.Success("success"));
|
||||
//return Ok(ApiResponse.Success("报名结束了"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user