public async Task <ActionResult> Upload(IFormFile file)
        {
            if (!FeatureFlags.IsEnabled(FeatureFlags.ImageUpload, _hostingEnv))
            {
                return(NotFound());
            }

            if (!ImagesController.IsImage(file))
            {
                return(ErrorResult("The file should be an image"));
            }
            else
            {
                string fileName = Path.GetRandomFileName();
                string filePath = await SaveImageAsync(
                    file,
                    fileName,
                    _hostingEnv);

                if (filePath == null)
                {
                    return(ErrorResult("Image is null"));
                }

                return(Json(filePath));
            }
        }
Exemple #2
0
        public async Task <ActionResult <Post> > DeletePost(int id)
        {
            var post = await _context.Posts.FindAsync(id);

            if (post == null)
            {
                return(NotFound());
            }

            if (!IsAuthenticatedUser(post.ApplicationUserId))
            {
                return(Forbid());
            }

            ImagesController.DeleteImage(post.ImageLink, _hostingEnv);

            _context.Posts.Remove(post);

            await _context.SaveChangesAsync();

            return(post);
        }