//[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult PhotoList(PhotoType photoType) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); int total = 0; List <PictureListDto> PictureListDtos = new List <PictureListDto>(); if (!PictureRedis.GetAll(out List <PictureInfo> Picture)) { Picture = context.PictureInfo.Where(x => x.Disable == false).Include(x => x.Users).ToList(); total = Picture.Count(); if (Picture != null && Picture.Count > 0) { PictureRedis.SaveAll(Picture); } Picture = Picture.Where(x => x.Disable == false && x.PictureType == PictureType.Product && x.PhotoType == photoType).OrderByDescending(x => x.RecommendIndex).ToList(); foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } else { total = Picture.Count(); Picture = Picture.Where(x => x.Disable == false && x.PictureType == PictureType.Product && x.PhotoType == photoType).OrderByDescending(x => x.RecommendIndex).ToList(); foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } return(Ok(new ApiResponse(PictureListDtos, total))); }
[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult PictureInfo(PictureSelectDto body) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); int total = 0; List <PictureListDto> PictureListDtos = new List <PictureListDto>(); if (!PictureRedis.GetAll(out List <PictureInfo> Picture)) { Picture = context.PictureInfo.Where(x => x.Disable == false).Include(x => x.Users).ToList(); total = Picture.Count(); if (Picture != null && Picture.Count > 0) { PictureRedis.SaveAll(Picture); } if (body.StartTime != null) { Picture = Picture.Where(x => x.CreateTime >= body.StartTime).ToList(); } if (body.EndTime != null) { Picture = Picture.Where(x => x.CreateTime <= body.EndTime).ToList(); } if (body.PictureType != null) { Picture = Picture.Where(x => x.PictureType == body.PictureType).ToList(); } Picture = Picture.OrderByDescending(x => x.RecommendIndex).Skip(body.pageSize * (body.pageNum - 1)).Take(body.pageSize).ToList(); foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } else { total = Picture.Count(); if (body.StartTime != null) { Picture = Picture.Where(x => x.CreateTime >= body.StartTime).ToList(); } if (body.EndTime != null) { Picture = Picture.Where(x => x.CreateTime <= body.EndTime).ToList(); } if (body.PictureType != null) { Picture = Picture.Where(x => x.PictureType == body.PictureType).ToList(); } Picture = Picture.OrderByDescending(x => x.RecommendIndex).Skip(body.pageSize * (body.pageNum - 1)).Take(body.pageSize).ToList(); foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } return(Ok(new ApiResponse(PictureListDtos, total))); }
//[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult PictureList() { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); int total = 0; List <PictureListDto> PictureListDtos = new List <PictureListDto>(); if (!PictureRedis.GetAll(out List <PictureInfo> Picture)) { Picture = context.PictureInfo.Where(x => x.Disable == false).OrderByDescending(x => x.RecommendIndex).Include(x => x.Users).ToList(); total = Picture.Count(); if (Picture != null && Picture.Count > 0) { PictureRedis.SaveAll(Picture); } string token = _httpContext.HttpContext.Request.Headers["Authorization"]; if (string.IsNullOrEmpty(token)) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } else { if (!AuthRedis.GetUserByToken(token, out UserInfo userInfo)) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } else { //注册账号时间不能超过俩个小时 if (DateTime.Now.Hour - userInfo.CreateTime.Hour > 2 && userInfo.LoginType.First() != LoginType.FreeWeb) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } } Picture = Picture.Where(x => x.Disable == false && x.PictureType == PictureType.News).ToList(); } foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } else { total = Picture.Count(); string token = _httpContext.HttpContext.Request.Headers["Authorization"]; if (string.IsNullOrEmpty(token)) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } else { if (!AuthRedis.GetUserByToken(token, out UserInfo userInfo)) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } else { //注册账号时间不能超过俩个小时 if (DateTime.Now.Hour - userInfo.CreateTime.Hour > 2 && userInfo.LoginType.First() != LoginType.FreeWeb) { Picture = Picture.Where(x => x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).Skip(0).Take(4).ToList(); } } Picture = Picture.Where(x => x.Disable == false && x.PictureType == PictureType.News).OrderByDescending(x => x.RecommendIndex).ToList(); } foreach (var item in Picture) { PictureListDto PictureListDto = new PictureListDto() { ID = item.Id, CreateTime = item.CreateTime, Index = item.RecommendIndex, UserName = item.Users.UserName, PictureExplain = item.PictureExplain, PictureTitle = item.PictureTitle, PictureUrl = item.PictureContent, PictureType = item.PictureType }; PictureListDtos.Add(PictureListDto); } } return(Ok(new ApiResponse(PictureListDtos, total))); }