Exemple #1
0
        public async Task <ActionResult> Upload(IFormFile file, UploadType uploadType, int postId = 0)
        {
            var author = await _authorProvider.FindByEmail(User.Identity.Name);

            var post = postId == 0 ? new Post() : await _postProvider.GetPostById(postId);

            var path     = $"{author.Id}/{DateTime.Now.Year}/{DateTime.Now.Month}";
            var fileName = $"data/{path}/{file.FileName}";

            if (await _storageProvider.UploadFormFile(file, path))
            {
                var blog = await _blogProvider.GetBlog();

                switch (uploadType)
                {
                case UploadType.Avatar:
                    author.Avatar = fileName;
                    return((await _authorProvider.Update(author)) ? new JsonResult(fileName) : BadRequest());

                case UploadType.AppLogo:
                    blog.Logo = fileName;
                    return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest());

                case UploadType.AppCover:
                    blog.Cover = fileName;
                    return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest());

                case UploadType.PostCover:
                    post.Cover = fileName;
                    return((await _postProvider.Update(post)) ? new JsonResult(fileName) : BadRequest());

                case UploadType.PostImage:
                    return(new JsonResult(fileName));
                }
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
 public async Task <ActionResult <bool> > UpdatePost(Post post)
 {
     return(await _postProvider.Update(post));
 }