This commit is contained in:
王炜翔 2024-10-12 10:35:04 +08:00
parent 19ad65b51a
commit 87e3d2af81

View File

@ -123,7 +123,9 @@ namespace asg_form.Controllers
public class idToString
{
public string invitedName { get; set; }
public string matchName { get; set; }
public string matchTeam1 { get; set; }
public string matchTeam2 { get; set; }
public string openTime { get; set; }
}
[Route("api/v1/myInvitation")]
@ -135,32 +137,45 @@ namespace asg_form.Controllers
var user = await userManager.FindByIdAsync(Forid);
long userId = user.Id;
int wrongPart = -1;
using (TestDbContext sub = new TestDbContext())
{
try
{
wrongPart = 0;
var query = sub.T_Invitation.FirstOrDefault(c => c.user_id == userId);
if (query != null)
{
wrongPart = 1;
List<idRequest> existingPairs = JsonSerializer.Deserialize<List<idRequest>>(json: query.my_request);
var TotalRecords = existingPairs.Count;
var TotalRecords = 0;
int skip = (page - 1) * limit;
List<idToString> Invintors = new List<idToString>();
var queryForMatchName = sub.team_Games;
wrongPart = 2;
idToString dataAdd=new idToString();
wrongPart = 3;
foreach (var pair in existingPairs)
{
var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id ==pair.invited_id);
wrongPart = 5;
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();
wrongPart = 6;
var matchFind = sub.team_Games.FirstOrDefault(c => c.id == pair.match_id);
wrongPart = 7;
if (matchFind == null || matchFind.team1_name == null || matchFind.team2_name == null) continue;
dataAdd.matchTeam1 = matchFind.team1_name;
dataAdd.matchTeam2 = matchFind.team2_name;
wrongPart = 8;
dataAdd.openTime = matchFind.opentime.ToString();
Invintors.Add(dataAdd);
TotalRecords++;
}
wrongPart = 4;
Invintors
.Skip(skip)
.Take(limit)
@ -174,15 +189,15 @@ namespace asg_form.Controllers
return Ok(new
{
code = 200,
message = "成功获取邀请",
message = "成功获取邀请列表",
result
});
}
return Ok(new { code = 200, message = "没有收到邀请" });
return Ok(new { code = 200, message = "没有收到邀请" });
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", details = ex.Message});
return Ok(new { code = 500, message = "服务器错误", details = ex.Message,wrongPart});
}
}
}