1
This commit is contained in:
		
							parent
							
								
									3f4572dd1f
								
							
						
					
					
						commit
						6ce23b1857
					
				@ -22,15 +22,21 @@ namespace asg_form.Controllers
 | 
			
		||||
        public class InviteBg
 | 
			
		||||
        {
 | 
			
		||||
            public int id { get; set; }
 | 
			
		||||
            public int userId { get; set; }
 | 
			
		||||
            public List<int> myRequest { get; set; }
 | 
			
		||||
            public int user_id { 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")]
 | 
			
		||||
        [HttpGet]
 | 
			
		||||
        [HttpPost]
 | 
			
		||||
        [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;
 | 
			
		||||
            var user = await userManager.FindByIdAsync(Invitorid);
 | 
			
		||||
@ -40,16 +46,28 @@ namespace asg_form.Controllers
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    //var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == Inviteeid);
 | 
			
		||||
                    //if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" });
 | 
			
		||||
                    var query = await sb.T_Invitation.FindAsync(Inviteeid);
 | 
			
		||||
                    var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id == msg.invitedId);
 | 
			
		||||
                    if (userInvited != null) return Ok(new { code = 404, message = "用户未找到" });
 | 
			
		||||
 | 
			
		||||
                    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();
 | 
			
		||||
                return Ok(new { code = 200, message = "邀请成功" });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ using System.Security.Claims;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
using NPOI.OpenXmlFormats.Spreadsheet;
 | 
			
		||||
using Castle.Components.DictionaryAdapter;
 | 
			
		||||
using Flandre.Core.Messaging;
 | 
			
		||||
 | 
			
		||||
namespace asg_form.Controllers
 | 
			
		||||
{
 | 
			
		||||
@ -33,8 +34,10 @@ namespace asg_form.Controllers
 | 
			
		||||
            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
			
		||||
            if (a)
 | 
			
		||||
            {
 | 
			
		||||
                TestDbContext testDb = new TestDbContext();
 | 
			
		||||
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    using (TestDbContext testDb = new TestDbContext())
 | 
			
		||||
                    {
 | 
			
		||||
                    var game = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameid);
 | 
			
		||||
                    game.team1_name = req.team1_name;
 | 
			
		||||
                    game.team2_name = req.team2_name;
 | 
			
		||||
@ -45,12 +48,15 @@ namespace asg_form.Controllers
 | 
			
		||||
                    game.belong = req.belong;
 | 
			
		||||
                    game.tag=req.tag;
 | 
			
		||||
                    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,8 +82,12 @@ namespace asg_form.Controllers
 | 
			
		||||
            bool a = await userManager.IsInRoleAsync(user, "admin");
 | 
			
		||||
            if (a)
 | 
			
		||||
            {
 | 
			
		||||
                TestDbContext testDb = new TestDbContext();
 | 
			
		||||
                testDb.team_Games.Add(new team_game { 
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    using (TestDbContext testDb = new TestDbContext())
 | 
			
		||||
                    {
 | 
			
		||||
                        testDb.team_Games.Add(new team_game
 | 
			
		||||
                        {
 | 
			
		||||
                        team1_name = req.team1_name,
 | 
			
		||||
                        team2_name = req.team2_name,
 | 
			
		||||
                        opentime = req.opentime,
 | 
			
		||||
@ -89,13 +99,16 @@ namespace asg_form.Controllers
 | 
			
		||||
                        tag = req.tag
 | 
			
		||||
                        });
 | 
			
		||||
                        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