www
This commit is contained in:
parent
87e3d2af81
commit
ca474d7aee
@ -1,4 +1,5 @@
|
|||||||
using Manganese.Array;
|
using AngleSharp.Text;
|
||||||
|
using Manganese.Array;
|
||||||
using Masuit.Tools;
|
using Masuit.Tools;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
@ -9,6 +10,7 @@ using System;
|
|||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace asg_form.Controllers
|
namespace asg_form.Controllers
|
||||||
{
|
{
|
||||||
@ -33,9 +35,19 @@ namespace asg_form.Controllers
|
|||||||
{
|
{
|
||||||
public int id { get; set; }
|
public int id { get; set; }
|
||||||
public int user_id { get; set; }
|
public int user_id { get; set; }
|
||||||
public string? my_request { get; set; }
|
public int invited_id { get; set; }
|
||||||
|
public int match_id { get; set; }
|
||||||
|
public int status { get; set; }
|
||||||
|
|
||||||
|
public string? create_time { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InviteForUsers
|
||||||
|
{
|
||||||
|
public string invitedChinaname { get; set; }
|
||||||
|
public schedule.team_game match { get; set; }
|
||||||
|
|
||||||
|
public string? create_time { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class inv
|
public class inv
|
||||||
@ -56,77 +68,42 @@ namespace asg_form.Controllers
|
|||||||
|
|
||||||
using (TestDbContext sb = new TestDbContext())
|
using (TestDbContext sb = new TestDbContext())
|
||||||
{
|
{
|
||||||
int wrong_part = -1;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == msg.invitedId);
|
var invited = await userManager.Users.FirstOrDefaultAsync(u => u.Id == msg.invitedId);
|
||||||
if (userInvited == null) return Ok(new { code = 404, message = "用户未找到" });
|
if (invited != null) return Ok(new { code = 404, message = "用户未找到" });
|
||||||
|
var isInvited = await sb.T_Invitation.AnyAsync(i => i.user_id == userId && i.invited_id==msg.invitedId && i.match_id==msg.matchId);
|
||||||
|
if (!isInvited)
|
||||||
var invitationRecord = sb.T_Invitation.FirstOrDefault(c => c.user_id == msg.invitedId);
|
|
||||||
wrong_part = 0;
|
|
||||||
|
|
||||||
string updatedJson;
|
|
||||||
|
|
||||||
|
|
||||||
if (invitationRecord != null)
|
|
||||||
{
|
{
|
||||||
List<idRequest> existingPairs = JsonSerializer.Deserialize<List<idRequest>>(json: invitationRecord.my_request);
|
string createTime = DateTime.Now.ToString();
|
||||||
wrong_part = 1;
|
var invitation = new InviteBg
|
||||||
//if (!string.IsNullOrEmpty(invitationRecord.my_request))
|
|
||||||
//{
|
|
||||||
// existingPairs = JsonSerializer.Deserialize<List<idRequest>>(invitationRecord.my_request) ?? new List<idRequest>();
|
|
||||||
//}
|
|
||||||
if (existingPairs.Any(req => req.invited_id == userId && req.match_id == msg.matchId))
|
|
||||||
{
|
{
|
||||||
return Ok(new { code = 409, message = "邀请已存在" });
|
user_id = (int)userId,
|
||||||
}
|
invited_id = msg.invitedId,
|
||||||
wrong_part=2;
|
match_id = msg.matchId,
|
||||||
existingPairs.Add(new idRequest { invited_id=(int)userId,match_id=msg.matchId });
|
status = 0,
|
||||||
updatedJson = JsonSerializer.Serialize(existingPairs);
|
create_time = createTime,
|
||||||
invitationRecord.my_request = updatedJson;
|
|
||||||
//sb.T_Invitation.Update(invitationRecord);
|
|
||||||
wrong_part =3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
wrong_part = 4;
|
|
||||||
updatedJson = "["+JsonSerializer.Serialize(new idRequest { invited_id = (int)userId, match_id = msg.matchId })+"]";
|
|
||||||
wrong_part = 5;
|
|
||||||
invitationRecord = new InviteBg
|
|
||||||
{
|
|
||||||
user_id = msg.invitedId,
|
|
||||||
my_request = updatedJson
|
|
||||||
};
|
};
|
||||||
sb.T_Invitation.Add(invitationRecord);
|
sb.Add(invitation);
|
||||||
|
sb.SaveChanges();
|
||||||
|
var match = sb.team_Games.FirstOrDefault(n => n.id == msg.matchId);
|
||||||
|
var data = new
|
||||||
|
{
|
||||||
|
userName = user.chinaname,
|
||||||
|
invitedName = invited.chinaname,
|
||||||
|
match
|
||||||
|
};
|
||||||
|
return Ok(new { code = 200, message = "成功发送邀请" ,data});
|
||||||
}
|
}
|
||||||
wrong_part = 6;
|
return Ok(new { code = 200, message = "已经在本场次邀请过这个人" });
|
||||||
await sb.SaveChangesAsync();
|
}
|
||||||
var data = new
|
|
||||||
{
|
|
||||||
invitedId = (int)userId,
|
|
||||||
matchId = msg.matchId,
|
|
||||||
jsonId = updatedJson
|
|
||||||
};
|
|
||||||
return Ok(new { code = 200, message = "邀请成功", data });
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return Ok(new { code = 500, message = "服务器错误", details = ex.Message ,wrong_part});
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class idToString
|
|
||||||
{
|
|
||||||
public string invitedName { get; set; }
|
|
||||||
public string matchTeam1 { get; set; }
|
|
||||||
public string matchTeam2 { get; set; }
|
|
||||||
public string openTime { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("api/v1/myInvitation")]
|
[Route("api/v1/myInvitation")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -143,74 +120,133 @@ namespace asg_form.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wrongPart = 0;
|
var query = sub.T_Invitation
|
||||||
var query = sub.T_Invitation.FirstOrDefault(c => c.user_id == userId);
|
.AsQueryable();
|
||||||
if (query != null)
|
var TotalRecords = await query.CountAsync();
|
||||||
|
var invitationRecordId = query
|
||||||
|
.Where(x => x.user_id == userId)
|
||||||
|
.OrderByDescending(t => t.status)
|
||||||
|
.ThenBy(t => t.create_time)
|
||||||
|
.Skip((page - 1) * limit)
|
||||||
|
.Take(limit)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
List<InviteForUsers> invitationRecord = new List<InviteForUsers>();
|
||||||
|
foreach (var record in invitationRecordId)
|
||||||
{
|
{
|
||||||
wrongPart = 1;
|
var invited = await userManager.Users.FirstOrDefaultAsync(u => u.Id == record.invited_id);
|
||||||
List<idRequest> existingPairs = JsonSerializer.Deserialize<List<idRequest>>(json: query.my_request);
|
var addData = new InviteForUsers
|
||||||
|
|
||||||
var TotalRecords = 0;
|
|
||||||
int skip = (page - 1) * limit;
|
|
||||||
|
|
||||||
List<idToString> Invintors = new List<idToString>();
|
|
||||||
|
|
||||||
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);
|
invitedChinaname = invited.chinaname,
|
||||||
wrongPart = 5;
|
match = sub.team_Games.FirstOrDefault(i => i.id == record.match_id),
|
||||||
dataAdd.invitedName = userInvited.chinaname;
|
create_time = record.create_time,
|
||||||
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)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var result = new
|
|
||||||
{
|
|
||||||
rows = Invintors,
|
|
||||||
total = TotalRecords,
|
|
||||||
};
|
};
|
||||||
return Ok(new
|
}
|
||||||
{
|
var data = new
|
||||||
code = 200,
|
{
|
||||||
message = "成功获取邀请列表",
|
rows = invitationRecord,
|
||||||
result
|
total = TotalRecords,
|
||||||
});
|
};
|
||||||
}
|
return Ok(new { code = 200, message = "邀请记录如下", data });
|
||||||
return Ok(new { code = 200, message = "没有收到过邀请" });
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return Ok(new { code = 500, message = "服务器错误", details = ex.Message,wrongPart});
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BeInviteForUsers
|
||||||
|
{
|
||||||
|
public string invitorChinaname { get; set; }
|
||||||
|
public schedule.team_game match { get; set; }
|
||||||
|
|
||||||
|
public string? create_time { get; set; }
|
||||||
|
}
|
||||||
[Route("api/v1/toInvite")]
|
[Route("api/v1/toInvite")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<object>> ToInvite()
|
public async Task<ActionResult<object>> ToInvite([FromQuery]short page = 1, short limit = 6)
|
||||||
{
|
{
|
||||||
string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
||||||
var user = await userManager.FindByIdAsync(Myid);
|
var user = await userManager.FindByIdAsync(Myid);
|
||||||
long userId = user.Id;
|
long userId = user.Id;
|
||||||
return Ok(new { code = 200, message = "没有完成的功能" });
|
|
||||||
|
int wrongPart = -1;
|
||||||
|
using (TestDbContext sub = new TestDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = sub.T_Invitation
|
||||||
|
.AsQueryable();
|
||||||
|
var TotalRecords = await query.CountAsync();
|
||||||
|
var invitationRecordId = query
|
||||||
|
.Where(x => x.invited_id == userId && x.status==0)
|
||||||
|
.OrderBy(t => t.create_time)
|
||||||
|
.Skip((page - 1) * limit)
|
||||||
|
.Take(limit)
|
||||||
|
.ToList();
|
||||||
|
List<BeInviteForUsers> invitationRecord = new List<BeInviteForUsers>();
|
||||||
|
foreach (var record in invitationRecordId)
|
||||||
|
{
|
||||||
|
var invitor = await userManager.Users.FirstOrDefaultAsync(u => u.Id == record.user_id);
|
||||||
|
var addData = new BeInviteForUsers
|
||||||
|
{
|
||||||
|
invitorChinaname = invitor.chinaname,
|
||||||
|
match = sub.team_Games.FirstOrDefault(i => i.id == record.match_id),
|
||||||
|
create_time = record.create_time,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var data = new
|
||||||
|
{
|
||||||
|
rows = invitationRecord,
|
||||||
|
total = TotalRecords,
|
||||||
|
};
|
||||||
|
return Ok(new { code = 200, message = "收到的未处理的邀请如下", data });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class msg2
|
||||||
|
{
|
||||||
|
public int id { get; set; }
|
||||||
|
public int status { get; set; }
|
||||||
|
}
|
||||||
|
[Route("api/v1/recordAgreeOrDisagree")]
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<object>> PassAssign([FromBody] msg2 askMsg)
|
||||||
|
{
|
||||||
|
using (TestDbContext sub = new TestDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = sub.T_Invitation.FirstOrDefault(n => n.id == askMsg.id);
|
||||||
|
if (query != null)
|
||||||
|
{
|
||||||
|
string message = "无效操作";
|
||||||
|
query.status = askMsg.status;
|
||||||
|
if(askMsg.status == 1)
|
||||||
|
{
|
||||||
|
message = "你同意了邀请,记得及时到位哦~";
|
||||||
|
}else if (askMsg.status == 2)
|
||||||
|
{
|
||||||
|
message = "你拒绝了邀请";
|
||||||
|
}
|
||||||
|
sub.SaveChanges();
|
||||||
|
return Ok(new { code = 200, message});
|
||||||
|
}
|
||||||
|
return Ok(new { code = 404, message = "没有对应记录" });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user