update timeselect message sending
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-22 19:45:19 +08:00
parent 98d51d1417
commit b427969501
8 changed files with 75 additions and 3 deletions
+44
View File
@@ -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("报名结束了"));
}
}
}