コード例 #1
0
ファイル: ManageController.cs プロジェクト: ThePaperFish/DDAC
        public async Task <IActionResult> Edit(int id, int ID, string Title, IFormFile CoverPhoto, string Content, DateTime PublishedDate, string Tag)
        {
            var post = new Post
            {
                ID            = ID,
                Title         = Title,
                CoverPhoto    = Title,
                Content       = Content,
                PublishedDate = PublishedDate,
                EditedDate    = DateTime.Now,
                Tag           = Tag
            };

            if (id != post.ID)
            {
                return(NotFound());
            }

            if (CoverPhoto != null)
            {
                BlobsController blobsController = new BlobsController();
                if (!blobsController.UploadBlobFunction(post.Title, CoverPhoto.OpenReadStream()))
                {
                    ModelState.AddModelError(string.Empty, "The image file failed to upload.");
                    return(View(post));
                }
                post.CoverPhoto = post.Title;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(post);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostExists(post.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
コード例 #2
0
ファイル: ManageController.cs プロジェクト: ThePaperFish/DDAC
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var post = await _context.Post.FindAsync(id);

            BlobsController blobsController = new BlobsController();

            if (!blobsController.DeleteBlobFunction(post.CoverPhoto))
            {
            }

            _context.Post.Remove(post);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
ファイル: ManageController.cs プロジェクト: ThePaperFish/DDAC
        public async Task <IActionResult> Create(int id, int ID, string Title, IFormFile CoverPhoto, string Content, string Tag)
        {
            var post = new Post
            {
                ID            = ID,
                Title         = Title,
                CoverPhoto    = Title,
                Content       = Content,
                PublishedDate = DateTime.Now,
                EditedDate    = DateTime.Now,
                Tag           = Tag
            };

            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            Post existingPost = await _context.Post.SingleOrDefaultAsync(
                m => m.Title == post.Title
                );

            if (existingPost != null)
            {
                ModelState.AddModelError(string.Empty, "This blog title is already exists.");
                return(View(post));
            }

            BlobsController blobsController = new BlobsController();

            if (!blobsController.UploadBlobFunction(post.Title, CoverPhoto.OpenReadStream()))
            {
                ModelState.AddModelError(string.Empty, "The image file failed to upload.");
                return(View(post));
            }
            post.CoverPhoto = post.Title;

            _context.Add(post);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }