public async Task <IActionResult> Create(Comment comment, int PhotoId) { //Save the new comment _context.Comments.Add(comment); await _context.SaveChangesAsync(); //Return the view component with the new list of comments return(ViewComponent("CommentsForPhoto", new { PhotoId = PhotoId })); }
public async Task <IActionResult> Create([Bind("Id,Title,PhotoFile,ImageMimeType,Description,CreatedDate,UserName")] Photo photo) { if (ModelState.IsValid) { _context.Add(photo); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(photo)); }
public async Task <IActionResult> Create([Bind("Id,CreatedDate,Description,ImageMimeType,Title,UserName")] Photo photo, IFormFile image) { photo.CreatedDate = DateTime.Today; if (!ModelState.IsValid) { return(View(nameof(PhotosController.Create), photo)); } else { if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.Length]; await image.OpenReadStream().ReadAsync(photo.PhotoFile, 0, (int)image.Length); } _context.Photos.Add(photo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(PhotosController.Index))); } }