Merge branch 'master' of https://dev.azure.com/luolan/ASG/_git/asg_backend
This commit is contained in:
		
						commit
						e2dd47c427
					
				@ -120,10 +120,13 @@ namespace asg_form.Controllers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                try
 | 
					                try
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                TestDbContext ctx = new TestDbContext();
 | 
					               using (TestDbContext ctx = new TestDbContext())
 | 
				
			||||||
                ctx.news.Add(new T_news { Title = req_News.Title, msg = req_News.msg,Type=req_News.Type, FormName = user.UserName ,time=DateTime.Now.ToString()});
 | 
					               {
 | 
				
			||||||
                ctx.SaveChanges();
 | 
					                        ctx.news.Add(new T_news { Title = req_News.Title, msg = req_News.msg, Type = req_News.Type, FormName = user.chinaname, time = DateTime.Now.ToString() });
 | 
				
			||||||
                return "ok!";
 | 
					                        await ctx.SaveChangesAsync();
 | 
				
			||||||
 | 
					                        return Ok(new TReturn() { code=200,msg="添加成功!"});
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					              
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (Exception ex)
 | 
					                catch (Exception ex)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 | 
				
			|||||||
@ -373,26 +373,53 @@ namespace asg_form.Controllers
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 获取我的竞猜
 | 
					        /// 获取我的竞猜
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="page">当前页数,默认为1</param>
 | 
				
			||||||
 | 
					        /// <param name="pageSize">每页显示的记录数,默认为5</param>
 | 
				
			||||||
        /// <returns></returns>
 | 
					        /// <returns></returns>
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [Route("api/v1/game/mylog")]
 | 
					        [Route("api/v1/game/mylog")]
 | 
				
			||||||
        [HttpGet]
 | 
					        [HttpGet]
 | 
				
			||||||
        public async Task<ActionResult<List<schedule_log>>> mylog()
 | 
					        public async Task<ActionResult<PagedResult<schedule_log>>> MyLog(int page = 1, int pageSize = 5)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
					            string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
 | 
					            using (var _context = new TestDbContext())
 | 
				
			||||||
            TestDbContext test = new TestDbContext();
 | 
					 | 
				
			||||||
            var team = test.schlogs.Include(a=>a.team).Where(a=>a.userid==id).Take(5).ToList();
 | 
					 | 
				
			||||||
            foreach(var team_game in team)
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                team_game.team.logs = null;
 | 
					
 | 
				
			||||||
 | 
					                // 查询数据并按时间倒序排列
 | 
				
			||||||
 | 
					                var query = _context.schlogs
 | 
				
			||||||
 | 
					                    .Include(a => a.team)
 | 
				
			||||||
 | 
					                    .Where(a => a.userid == id)
 | 
				
			||||||
 | 
					                    .OrderByDescending(a => a.Id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 计算总记录数
 | 
				
			||||||
 | 
					                int totalItems = await query.CountAsync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 分页查询数据
 | 
				
			||||||
 | 
					                var data = await query
 | 
				
			||||||
 | 
					                    .Skip((page - 1) * pageSize)
 | 
				
			||||||
 | 
					                    .Take(pageSize)
 | 
				
			||||||
 | 
					                    .ToListAsync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 清除不必要的导航属性
 | 
				
			||||||
 | 
					                foreach (var log in data)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    log.team.logs = null;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 返回分页结果
 | 
				
			||||||
 | 
					                return new PagedResult<schedule_log>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Data = data,
 | 
				
			||||||
 | 
					                    Page = page,
 | 
				
			||||||
 | 
					                    PageSize = pageSize,
 | 
				
			||||||
 | 
					                    TotalItems = totalItems,
 | 
				
			||||||
 | 
					                    TotalPages = (int)Math.Ceiling(totalItems / (double)pageSize)
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
       
 | 
					       
 | 
				
			||||||
            return team ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [Route("api/v1/game/final")]
 | 
					        [Route("api/v1/game/final")]
 | 
				
			||||||
        [HttpPost]
 | 
					        [HttpPost]
 | 
				
			||||||
 | 
				
			|||||||
@ -112,11 +112,12 @@ namespace asg_form.Controllers
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
					                string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
                var ouser = userManager.Users.Include(a => a.haveform.role).FirstOrDefault(a => a.Id == id.ToInt64());
 | 
					                var ouser = userManager.Users.Include(a=>a.haveform.events).Include(a => a.haveform.role).FirstOrDefault(a => a.Id == id.ToInt64());
 | 
				
			||||||
                foreach (var role in ouser.haveform.role)
 | 
					                foreach (var role in ouser.haveform.role)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    role.form = null;
 | 
					                    role.form = null;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                ouser.haveform.events.forms=null;
 | 
				
			||||||
                return Ok(ouser.haveform);
 | 
					                return Ok(ouser.haveform);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -2,8 +2,8 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public class TReturn
 | 
					    public class TReturn
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public int Code {  get; set; }
 | 
					        public int code {  get; set; }
 | 
				
			||||||
        public object Msg {  get; set; }
 | 
					        public object msg {  get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public class TReturn_total
 | 
					    public class TReturn_total
 | 
				
			||||||
@ -11,4 +11,12 @@
 | 
				
			|||||||
        public int Total { get; set; }
 | 
					        public int Total { get; set; }
 | 
				
			||||||
        public object Msg { get; set; }
 | 
					        public object Msg { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    public class PagedResult<T>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public List<T> Data { get; set; }
 | 
				
			||||||
 | 
					        public int Page { get; set; }
 | 
				
			||||||
 | 
					        public int PageSize { get; set; }
 | 
				
			||||||
 | 
					        public int TotalItems { get; set; }
 | 
				
			||||||
 | 
					        public int TotalPages { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user