public IActionResult PictureUpload(PictureDto body) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); if (!string.IsNullOrEmpty(body.PictureTitle) && !string.IsNullOrEmpty(body.PictureExplain)) { string token = _httpContext.HttpContext.Request.Headers["Authorization"]; AuthRedis.GetUserByToken(token, out UserInfo userInfo); PictureInfo PictureInfos = new PictureInfo() { Id = SequenceID.GetSequenceID(), CreateTime = DateTime.Now, Disable = false, PictureContent = body.url, UserID = userInfo.id, LastModifiedTime = DateTime.Now, PictureExplain = body.PictureExplain, PictureTitle = body.PictureTitle, RecommendIndex = body.Index, PictureType = body.PictureType, PhotoType = body.PhotoType }; context.Add(PictureInfos); context.SaveChanges(); PictureRedis.Del(); } return(Ok(new ApiResponse())); }
[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult PictureDel(long id) { using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); var PictureInfo = context.PictureInfo.Single(x => x.Id == id); var WordInfo = context.WordInfo.Where(x => x.PictureID == id); PictureInfo.Disable = true; foreach (var item in WordInfo) { item.Disable = true; } context.SaveChanges(); WordRedis.Del(); PictureRedis.Del(); return(Ok(new ApiResponse())); }