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,