From 19ad65b51aa99e30fa56862335014c4d1520b90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=82=9C=E7=BF=94?= <2307953404@qq.com> Date: Fri, 11 Oct 2024 21:28:37 +0800 Subject: [PATCH] 1 --- asg_form/Controllers/InviteReferee.cs | 82 ++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/asg_form/Controllers/InviteReferee.cs b/asg_form/Controllers/InviteReferee.cs index a0e5660..c69280a 100644 --- a/asg_form/Controllers/InviteReferee.cs +++ b/asg_form/Controllers/InviteReferee.cs @@ -3,10 +3,12 @@ using Masuit.Tools; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.EntityFrameworkCore; using System; using System.Security.Claims; using System.Text.Json; +using System.Threading.Tasks; namespace asg_form.Controllers { @@ -46,7 +48,7 @@ namespace asg_form.Controllers [Route("api/v1/Invite")] [HttpPost] [Authorize] - public async Task> GetReferee([FromBody] inv msg) + public async Task> Toinvite([FromBody] inv msg) { string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; var user = await userManager.FindByIdAsync(Invitorid); @@ -117,5 +119,83 @@ namespace asg_form.Controllers } } + + public class idToString + { + public string invitedName { get; set; } + public string matchName { get; set; } + } + + [Route("api/v1/myInvitation")] + [HttpGet] + [Authorize] + public async Task> GetMyInvitor([FromQuery]short page = 1, short limit = 6) + { + string Forid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; + var user = await userManager.FindByIdAsync(Forid); + long userId = user.Id; + + using (TestDbContext sub = new TestDbContext()) + { + try + { + var query = sub.T_Invitation.FirstOrDefault(c => c.user_id == userId); + if (query != null) + { + List existingPairs = JsonSerializer.Deserialize>(json: query.my_request); + + var TotalRecords = existingPairs.Count; + int skip = (page - 1) * limit; + + List Invintors = new List(); + + var queryForMatchName = sub.team_Games; + idToString dataAdd=new idToString(); + + foreach (var pair in existingPairs) + { + var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id ==pair.invited_id); + dataAdd.invitedName = userInvited.chinaname; + var matchFind = queryForMatchName.FirstOrDefault(c => c.id == pair.match_id); + dataAdd.matchName = matchFind.team1_name + "VS" + matchFind.team2_name + " " + matchFind.opentime.ToString(); + Invintors.Add(dataAdd); + } + + Invintors + .Skip(skip) + .Take(limit) + .ToList(); + + var result = new + { + rows = Invintors, + total = TotalRecords, + }; + return Ok(new + { + code = 200, + message = "成功获取邀请", + result + }); + } + return Ok(new { code = 200, message = "没有收到邀请" }); + } + catch (Exception ex) + { + return Ok(new { code = 500, message = "服务器错误", details = ex.Message}); + } + } + } + + [Route("api/v1/toInvite")] + [HttpGet] + [Authorize] + public async Task> ToInvite() + { + string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; + var user = await userManager.FindByIdAsync(Myid); + long userId = user.Id; + return Ok(new { code = 200, message = "没有完成的功能" }); + } } }