Ejemplo n.º 1
0
        /// <summary>
        /// Post posts
        /// </summary>
        /// <returns>posts</returns>
        public async Task <IActionResult> OnPost()
        {
            var post = await _post.FindPost(ID.GetValueOrDefault()) ?? new Post();

            post.Author = Post.Author;
            //post.ImageURL = Post.ImageURL;
            post.Details = Post.Details;

            if (Image != null)
            {
                ///create temp file to hold image
                var filePath = Path.GetTempFileName();
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await Image.CopyToAsync(stream); ///copy image to file
                }

                var container = await BlobImage.GetContainer("images");

                BlobImage.UploadFile(Image.FileName, filePath, container);

                CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name);

                post.ImageURL = blob.Uri.ToString();
            }

            await _post.SaveAsync(post);

            return(RedirectToPage("/Posts/Index", new { id = post.ID }));
        }