1
This commit is contained in:
parent
3fd3bf346b
commit
19ad65b51a
@ -3,10 +3,12 @@ using Masuit.Tools;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace asg_form.Controllers
|
namespace asg_form.Controllers
|
||||||
{
|
{
|
||||||
@ -46,7 +48,7 @@ namespace asg_form.Controllers
|
|||||||
[Route("api/v1/Invite")]
|
[Route("api/v1/Invite")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<object>> GetReferee([FromBody] inv msg)
|
public async Task<ActionResult<object>> Toinvite([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);
|
||||||
@ -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<ActionResult<object>> 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<idRequest> existingPairs = JsonSerializer.Deserialize<List<idRequest>>(json: query.my_request);
|
||||||
|
|
||||||
|
var TotalRecords = existingPairs.Count;
|
||||||
|
int skip = (page - 1) * limit;
|
||||||
|
|
||||||
|
List<idToString> Invintors = new List<idToString>();
|
||||||
|
|
||||||
|
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<ActionResult<object>> 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 = "没有完成的功能" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user