This commit is contained in:
王炜翔 2024-10-10 16:08:18 +08:00
parent 3f4572dd1f
commit 6ce23b1857
2 changed files with 76 additions and 45 deletions

View File

@ -22,15 +22,21 @@ namespace asg_form.Controllers
public class InviteBg public class InviteBg
{ {
public int id { get; set; } public int id { get; set; }
public int userId { get; set; } public int user_id { get; set; }
public List<int> myRequest { get; set; } public List<(int invitor_id, int match_id)>? my_request { get; set; } = new List<(int, int)>();
} }
public class inv
{
public int invitedId { get; set; }
public int matchId { get; set; }
}
[Route("api/v1/Invite")] [Route("api/v1/Invite")]
[HttpGet] [HttpPost]
[Authorize] [Authorize]
public async Task<ActionResult<object>> GetReferee([FromBody] long Inviteeid) public async Task<ActionResult<object>> GetReferee([FromBody] inv msg)
{ {
string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(Invitorid); var user = await userManager.FindByIdAsync(Invitorid);
@ -40,16 +46,28 @@ namespace asg_form.Controllers
{ {
try try
{ {
//var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == Inviteeid); var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == msg.invitedId);
//if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" }); if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" });
var query = await sb.T_Invitation.FindAsync(Inviteeid);
var invitationRecord = await sb.T_Invitation.FindAsync(msg.invitedId);
}catch (Exception ex) if (invitationRecord != null)
{
if (invitationRecord.my_request.Any(req => req.invitor_id == userId && req.match_id == msg.matchId))
{
return Ok(new { code = 409, message = "邀请已存在" });
}
}
}
catch (Exception ex)
{ {
return Ok(new { code = 500, message = "服务器错误", details = ex.Message }); return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
} }
return Ok(); return Ok(new { code = 200, message = "邀请成功" });
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Security.Claims;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NPOI.OpenXmlFormats.Spreadsheet; using NPOI.OpenXmlFormats.Spreadsheet;
using Castle.Components.DictionaryAdapter; using Castle.Components.DictionaryAdapter;
using Flandre.Core.Messaging;
namespace asg_form.Controllers namespace asg_form.Controllers
{ {
@ -33,24 +34,29 @@ namespace asg_form.Controllers
bool a = await userManager.IsInRoleAsync(user, "admin"); bool a = await userManager.IsInRoleAsync(user, "admin");
if (a) if (a)
{ {
TestDbContext testDb = new TestDbContext(); try
{
var game = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameid); using (TestDbContext testDb = new TestDbContext())
game.team1_name = req.team1_name; {
game.team2_name = req.team2_name; var game = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameid);
game.opentime = req.opentime; game.team1_name = req.team1_name;
game.commentary = req.commentary; game.team2_name = req.team2_name;
game.bilibiliuri = req.bilibiliuri; game.opentime = req.opentime;
game.referee = req.referee; game.commentary = req.commentary;
game.belong = req.belong; game.bilibiliuri = req.bilibiliuri;
game.tag=req.tag; game.referee = req.referee;
await testDb.SaveChangesAsync(); game.belong = req.belong;
return "ok"; game.tag=req.tag;
await testDb.SaveChangesAsync();
return Ok(new { code = 200, message = "加入成功" });
}
}catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
}
} }
return BadRequest(new error_mb { code = 400, message = "无权访问" }); return Ok(new error_mb { code = 401, message = "无权访问" });
} }
@ -76,26 +82,33 @@ namespace asg_form.Controllers
bool a = await userManager.IsInRoleAsync(user, "admin"); bool a = await userManager.IsInRoleAsync(user, "admin");
if (a) if (a)
{ {
TestDbContext testDb = new TestDbContext(); try
testDb.team_Games.Add(new team_game { {
team1_name = req.team1_name, using (TestDbContext testDb = new TestDbContext())
team2_name = req.team2_name, {
opentime = req.opentime, testDb.team_Games.Add(new team_game
team1_piaoshu = 0, {
team2_piaoshu = 0 , team1_name = req.team1_name,
commentary=req.commentary, team2_name = req.team2_name,
referee=req.referee, opentime = req.opentime,
belong=req.belong, team1_piaoshu = 0,
tag=req.tag team2_piaoshu = 0,
}); commentary = req.commentary,
await testDb.SaveChangesAsync(); referee = req.referee,
return "ok"; belong = req.belong,
} tag = req.tag
else });
{ await testDb.SaveChangesAsync();
return BadRequest(new error_mb { code = 400, message = "无权访问" }); return Ok(new { code = 200, message = "加入成功" });
}
}catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
}
} }
return BadRequest(new error_mb { code = 401, message = "无权访问" });
} }