111
This commit is contained in:
		
							parent
							
								
									9f8d579e8e
								
							
						
					
					
						commit
						8bac48a736
					
				@ -44,8 +44,10 @@ namespace asg_form.Controllers
 | 
			
		||||
 | 
			
		||||
        public class InviteForUsers
 | 
			
		||||
        {
 | 
			
		||||
            public int id { get; set; }
 | 
			
		||||
            public string invitedChinaname { get; set; }
 | 
			
		||||
            public schedule.team_game match { get; set; }
 | 
			
		||||
            public int status { get; set; }
 | 
			
		||||
 | 
			
		||||
            public string? create_time { get; set; }
 | 
			
		||||
        }
 | 
			
		||||
@ -56,16 +58,23 @@ namespace asg_form.Controllers
 | 
			
		||||
            public int matchId { get; set; }
 | 
			
		||||
        }
 | 
			
		||||
            
 | 
			
		||||
        bool outOfTime(DateTime d)
 | 
			
		||||
        {
 | 
			
		||||
            DateTime currentTime = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
            if (currentTime > d.AddDays(1)) return true; else return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Route("api/v1/Invite")]
 | 
			
		||||
        [HttpPost]
 | 
			
		||||
        [Authorize]
 | 
			
		||||
        public async Task<ActionResult<object>> Toinvite([FromBody] inv msg)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
            string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
			
		||||
            var user = await userManager.FindByIdAsync(Invitorid);
 | 
			
		||||
            long userId = user.Id;
 | 
			
		||||
 | 
			
		||||
            if (user.officium != "Commentator" || !this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin")) return Ok(new error_mb { code = 401, message = "您不是解说无法完成邀请" });
 | 
			
		||||
            using (TestDbContext sb = new TestDbContext())
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
@ -122,7 +131,7 @@ namespace asg_form.Controllers
 | 
			
		||||
                {
 | 
			
		||||
                    var query = sub.T_Invitation
 | 
			
		||||
                        .AsQueryable();
 | 
			
		||||
                    var TotalRecords = await query.CountAsync();
 | 
			
		||||
                    var TotalRecords = 0;
 | 
			
		||||
                    var invitationRecordId = query
 | 
			
		||||
                        .Where(x => x.user_id == userId)
 | 
			
		||||
                        .OrderByDescending(t => t.status)
 | 
			
		||||
@ -134,14 +143,25 @@ namespace asg_form.Controllers
 | 
			
		||||
                    List<InviteForUsers> invitationRecord = new List<InviteForUsers>();
 | 
			
		||||
                    foreach (var record in invitationRecordId)
 | 
			
		||||
                    {
 | 
			
		||||
                        
 | 
			
		||||
                        var invited = await userManager.Users.FirstOrDefaultAsync(u => u.Id == record.invited_id);
 | 
			
		||||
                        var theGame = sub.team_Games.FirstOrDefault(i => i.id == record.match_id);
 | 
			
		||||
                        if (outOfTime(theGame.opentime))
 | 
			
		||||
                        {
 | 
			
		||||
                            sub.team_Games.Remove(theGame);
 | 
			
		||||
                            sub.SaveChanges();
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                        var addData = new InviteForUsers
 | 
			
		||||
                        {
 | 
			
		||||
                            id = record.id,
 | 
			
		||||
                            invitedChinaname = invited.chinaname,
 | 
			
		||||
                            match = sub.team_Games.FirstOrDefault(i => i.id == record.match_id),
 | 
			
		||||
                            match = theGame,
 | 
			
		||||
                            create_time = record.create_time,
 | 
			
		||||
                            status = record.status,
 | 
			
		||||
                        };
 | 
			
		||||
                        invitationRecord.Add(addData);
 | 
			
		||||
                        TotalRecords++;
 | 
			
		||||
                    }                    
 | 
			
		||||
                    var data = new
 | 
			
		||||
                    {
 | 
			
		||||
@ -159,6 +179,7 @@ namespace asg_form.Controllers
 | 
			
		||||
 | 
			
		||||
        public class BeInviteForUsers
 | 
			
		||||
        {
 | 
			
		||||
            public int id { get; set; }
 | 
			
		||||
            public string invitorChinaname { get; set; }
 | 
			
		||||
            public schedule.team_game match { get; set; }
 | 
			
		||||
 | 
			
		||||
@ -180,7 +201,7 @@ namespace asg_form.Controllers
 | 
			
		||||
                    {
 | 
			
		||||
                        var query = sub.T_Invitation
 | 
			
		||||
                            .AsQueryable();
 | 
			
		||||
                        var TotalRecords = await query.CountAsync();
 | 
			
		||||
                        var TotalRecords = 0;
 | 
			
		||||
                        var invitationRecordId = query
 | 
			
		||||
                            .Where(x => x.invited_id == userId && x.status==0)
 | 
			
		||||
                            .OrderBy(t => t.create_time)
 | 
			
		||||
@ -189,15 +210,24 @@ namespace asg_form.Controllers
 | 
			
		||||
                            .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 theGame = sub.team_Games.FirstOrDefault(i => i.id == record.match_id);
 | 
			
		||||
                        if (outOfTime(theGame.opentime))
 | 
			
		||||
                        {
 | 
			
		||||
                            sub.team_Games.Remove(theGame);
 | 
			
		||||
                            sub.SaveChanges();
 | 
			
		||||
                            continue;
 | 
			
		||||
                        }
 | 
			
		||||
                        var addData = new BeInviteForUsers
 | 
			
		||||
                        {
 | 
			
		||||
                            id = record.id,
 | 
			
		||||
                            invitorChinaname = invitor.chinaname,
 | 
			
		||||
                            match = sub.team_Games.FirstOrDefault(i => i.id == record.match_id),
 | 
			
		||||
                            match = theGame,
 | 
			
		||||
                            create_time = record.create_time,
 | 
			
		||||
                        };
 | 
			
		||||
                        invitationRecord.Add(addData);
 | 
			
		||||
                        TotalRecords++;
 | 
			
		||||
                    }
 | 
			
		||||
                    var data = new
 | 
			
		||||
                        {
 | 
			
		||||
@ -250,5 +280,30 @@ namespace asg_form.Controllers
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Route("api/v1/delRecord")]
 | 
			
		||||
        [HttpDelete]
 | 
			
		||||
        [Authorize]
 | 
			
		||||
        public async Task<ActionResult<object>> DelAssign([FromQuery] int id)
 | 
			
		||||
        {
 | 
			
		||||
            using (TestDbContext sub = new TestDbContext())
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
			
		||||
                    var user = await userManager.FindByIdAsync(Myid);
 | 
			
		||||
                    long userId = user.Id;
 | 
			
		||||
                    var query = sub.T_Invitation.Where(n => n.id == id).FirstOrDefault();
 | 
			
		||||
                    if(query.user_id != (int)userId) return Ok(new error_mb { code = 200, message = "非法操作!" });
 | 
			
		||||
                    sub.T_Invitation.Remove(query);
 | 
			
		||||
                    await sub.SaveChangesAsync();
 | 
			
		||||
                    return Ok(new error_mb { code = 200, message = "成功删除" });
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception ex)
 | 
			
		||||
                {
 | 
			
		||||
                    return Ok(new { code = 500, message = "服务器错误", details = ex });
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user