1
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TechHelper.Server.Services;
|
||||
using System.Security.Claims;
|
||||
using TechHelper.Services;
|
||||
|
||||
|
||||
namespace TechHelper.Server.Controllers
|
||||
@@ -31,7 +32,7 @@ namespace TechHelper.Server.Controllers
|
||||
[FromBody] AssignmentDto examDto)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(User.Identity?.Name ?? "");
|
||||
if(user == null) return BadRequest("无效的用户");
|
||||
if (user == null) return BadRequest("无效的用户");
|
||||
|
||||
examDto.CreatorId = user.Id;
|
||||
var result = await _examService.CreateExamAsync(examDto);
|
||||
@@ -45,6 +46,29 @@ namespace TechHelper.Server.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("submission")]
|
||||
public async Task<IActionResult> SubmissionAssignment(
|
||||
[FromBody] SubmissionDto submissionDto)
|
||||
{
|
||||
if (User == null) return BadRequest("无效的用户");
|
||||
if (User.IsInRole("Teacher"))
|
||||
{
|
||||
var result = await _examService.SubmissionAssignment(submissionDto);
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("你没有权限修改");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("get")]
|
||||
public async Task<IActionResult> GetExamById(Guid id)
|
||||
{
|
||||
@@ -58,16 +82,26 @@ namespace TechHelper.Server.Controllers
|
||||
|
||||
|
||||
[HttpGet("getAllPreview")]
|
||||
public async Task<IActionResult> GetAllExamPreview(string user)
|
||||
public async Task<IActionResult> GetAllExamPreview()
|
||||
{
|
||||
string? userId = User.Identity.Name;
|
||||
if (User == null) return BadRequest("用户验证失败, 无效用户");
|
||||
|
||||
var userid = await _userManager.FindByEmailAsync(user);
|
||||
if (userid == null) return BadRequest("用户验证失败, 无效用户");
|
||||
var userid = await _userManager.FindByEmailAsync(User.Identity.Name);
|
||||
|
||||
|
||||
|
||||
var result = await _examService.GetAllExamPreviewsAsync(userid.Id);
|
||||
var result = new ApiResponse();
|
||||
if (User.IsInRole("Teacher"))
|
||||
{
|
||||
result = await _examService.GetAllExamPreviewsAsync(userid.Id);
|
||||
}
|
||||
else if (User.IsInRole("Student"))
|
||||
{
|
||||
result = await _examService.GetAllSubmissionAsync(userid.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("你没有相应的权限");
|
||||
}
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
@@ -76,5 +110,34 @@ namespace TechHelper.Server.Controllers
|
||||
return BadRequest(result);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("getAllSubmission")]
|
||||
public async Task<IActionResult> GetAllSubmission()
|
||||
{
|
||||
if (User == null) return BadRequest("用户验证失败, 无效用户");
|
||||
|
||||
var userid = await _userManager.FindByEmailAsync(User.Identity.Name);
|
||||
|
||||
var result = await _examService.GetAllSubmissionAsync(userid.Id);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
return BadRequest(result);
|
||||
}
|
||||
|
||||
|
||||
[Authorize(Roles = "Teacher")]
|
||||
[HttpDelete("{guid}")]
|
||||
public async Task<IActionResult> DeleteAsync(Guid guid)
|
||||
{
|
||||
var deleteResult = await _examService.DeleteAsync(guid);
|
||||
if (deleteResult.Status)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user