1
This commit is contained in:
		
							parent
							
								
									3f4572dd1f
								
							
						
					
					
						commit
						6ce23b1857
					
				@ -22,15 +22,21 @@ namespace asg_form.Controllers
 | 
				
			|||||||
        public class InviteBg
 | 
					        public class InviteBg
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            public int id { get; set; }
 | 
					            public int id { get; set; }
 | 
				
			||||||
            public int userId { get; set; }
 | 
					            public int user_id { get; set; }
 | 
				
			||||||
            public List<int> myRequest { get; set; }
 | 
					            public List<(int invitor_id, int match_id)>? my_request { get; set; } = new List<(int, int)>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public class inv
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public int invitedId { get; set; }
 | 
				
			||||||
 | 
					            public int matchId { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        [Route("api/v1/Invite")]
 | 
					        [Route("api/v1/Invite")]
 | 
				
			||||||
        [HttpGet]
 | 
					        [HttpPost]
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        public async Task<ActionResult<object>> GetReferee([FromBody] long Inviteeid)
 | 
					        public async Task<ActionResult<object>> GetReferee([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);
 | 
				
			||||||
@ -40,16 +46,28 @@ namespace asg_form.Controllers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                try
 | 
					                try
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    //var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == Inviteeid);
 | 
					                    var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == msg.invitedId);
 | 
				
			||||||
                    //if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" });
 | 
					                    if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" });
 | 
				
			||||||
                    var query = await sb.T_Invitation.FindAsync(Inviteeid);
 | 
					
 | 
				
			||||||
 | 
					                    var invitationRecord = await sb.T_Invitation.FindAsync(msg.invitedId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (invitationRecord != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        if (invitationRecord.my_request.Any(req => req.invitor_id == userId && req.match_id == msg.matchId))
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                        return Ok(new { code = 409, message = "邀请已存在" }); 
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                }catch (Exception ex)
 | 
					                    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (Exception ex)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
 | 
					                    return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                return Ok();
 | 
					                return Ok(new { code = 200, message = "邀请成功" });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,7 @@ using System.Security.Claims;
 | 
				
			|||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
using NPOI.OpenXmlFormats.Spreadsheet;
 | 
					using NPOI.OpenXmlFormats.Spreadsheet;
 | 
				
			||||||
using Castle.Components.DictionaryAdapter;
 | 
					using Castle.Components.DictionaryAdapter;
 | 
				
			||||||
 | 
					using Flandre.Core.Messaging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace asg_form.Controllers
 | 
					namespace asg_form.Controllers
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -33,8 +34,10 @@ namespace asg_form.Controllers
 | 
				
			|||||||
            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
					            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
				
			||||||
            if (a)
 | 
					            if (a)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                TestDbContext testDb = new TestDbContext();
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    using (TestDbContext testDb = new TestDbContext())
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                    var game = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameid);
 | 
					                    var game = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameid);
 | 
				
			||||||
                    game.team1_name = req.team1_name;
 | 
					                    game.team1_name = req.team1_name;
 | 
				
			||||||
                    game.team2_name = req.team2_name;
 | 
					                    game.team2_name = req.team2_name;
 | 
				
			||||||
@ -45,12 +48,15 @@ namespace asg_form.Controllers
 | 
				
			|||||||
                    game.belong = req.belong;
 | 
					                    game.belong = req.belong;
 | 
				
			||||||
                    game.tag=req.tag;
 | 
					                    game.tag=req.tag;
 | 
				
			||||||
                    await testDb.SaveChangesAsync();
 | 
					                    await testDb.SaveChangesAsync();
 | 
				
			||||||
                return "ok";
 | 
					                    return Ok(new { code = 200, message = "加入成功" });
 | 
				
			||||||
             
 | 
					                    }
 | 
				
			||||||
 | 
					                }catch (Exception ex)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return BadRequest(new error_mb { code = 400, message = "无权访问" });
 | 
					            return Ok(new error_mb { code = 401, message = "无权访问" });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,26 +82,33 @@ namespace asg_form.Controllers
 | 
				
			|||||||
            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
					            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
				
			||||||
            if (a)
 | 
					            if (a)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                TestDbContext testDb = new TestDbContext();
 | 
					                try
 | 
				
			||||||
                testDb.team_Games.Add(new team_game { 
 | 
					                {
 | 
				
			||||||
 | 
					                    using (TestDbContext testDb = new TestDbContext())
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        testDb.team_Games.Add(new team_game
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
                        team1_name = req.team1_name,
 | 
					                        team1_name = req.team1_name,
 | 
				
			||||||
                        team2_name = req.team2_name,
 | 
					                        team2_name = req.team2_name,
 | 
				
			||||||
                        opentime = req.opentime,
 | 
					                        opentime = req.opentime,
 | 
				
			||||||
                        team1_piaoshu = 0,
 | 
					                        team1_piaoshu = 0,
 | 
				
			||||||
                    team2_piaoshu = 0 ,
 | 
					                        team2_piaoshu = 0,
 | 
				
			||||||
                commentary=req.commentary,
 | 
					                        commentary = req.commentary,
 | 
				
			||||||
                referee=req.referee,
 | 
					                        referee = req.referee,
 | 
				
			||||||
                belong=req.belong,
 | 
					                        belong = req.belong,
 | 
				
			||||||
                tag=req.tag
 | 
					                        tag = req.tag
 | 
				
			||||||
                        });
 | 
					                        });
 | 
				
			||||||
                        await testDb.SaveChangesAsync();
 | 
					                        await testDb.SaveChangesAsync();
 | 
				
			||||||
                return "ok";
 | 
					                        return Ok(new { code = 200, message = "加入成功" });
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
            else
 | 
					                        
 | 
				
			||||||
 | 
					                }catch (Exception ex)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                return BadRequest(new error_mb { code = 400, message = "无权访问" });
 | 
					                    return Ok(new { code = 500, message = "服务器错误", details = ex.Message });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            return BadRequest(new error_mb { code = 401, message = "无权访问" });            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user