From f878d849f80e7282556cc496aa482b03243f601b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C=E7=BF=94?= <2307953404@qq.com> Date: Thu, 10 Oct 2024 22:42:58 +0800 Subject: [PATCH] 1 --- asg_form/Controllers/InviteReferee.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/asg_form/Controllers/InviteReferee.cs b/asg_form/Controllers/InviteReferee.cs index 4d77afc..be14bdd 100644 --- a/asg_form/Controllers/InviteReferee.cs +++ b/asg_form/Controllers/InviteReferee.cs @@ -50,23 +50,29 @@ namespace asg_form.Controllers var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == msg.invitedId); if (userInvited == null) return Ok(new { code = 404, message = "用户未找到" }); - var invitationRecord = await sb.T_Invitation.FindAsync(msg.invitedId); - + var invitationRecord = sb.T_Invitation.FirstOrDefault(c => c.user_id == msg.invitedId); + if (invitationRecord != null) { if (invitationRecord.my_request.Any(req => req.invitor_id == userId && req.match_id == msg.matchId)) { return Ok(new { code = 409, message = "邀请已存在" }); } + invitationRecord.my_request.Add((invitor_id: (int)userId, match_id: msg.matchId)); + await sb.SaveChangesAsync(); } - invitationRecord = new InviteBg + else { - user_id = msg.invitedId, - my_request = new List<(int, int)>() - }; - invitationRecord.my_request.Add((invitor_id: (int)userId, match_id: msg.matchId)); - - await sb.SaveChangesAsync(); + invitationRecord = new InviteBg + { + user_id = msg.invitedId, + my_request = new List<(int, int)>() + }; + invitationRecord.my_request.Add((invitor_id: (int)userId, match_id: msg.matchId)); + sb.T_Invitation.Add(invitationRecord); + await sb.SaveChangesAsync(); + } + var data = new { invitedId = (int)userId,