public PartialViewResult _CommentsForPhoto(Comment comment, int PhotoId) { //The comment comes from the currently authenticated user comment.UserName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(User.Identity.Name); //Save the new comment db.Comments.Add(comment); db.SaveChanges(); //Get the updated list of comments var comments = from c in db.Comments where c.PhotoID == PhotoId select c; //Save the PhotoID in the ViewBag because we'll need it in the view ViewBag.PhotoId = PhotoId; //Return the view with the new list of comments return(PartialView("_CommentsForPhoto", comments.ToList())); }
public ActionResult Create(Photo photo, HttpPostedFileBase image) { photo.UserName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(User.Identity.Name); photo.CreatedDate = DateTime.Today; photo.ModifiedDate = DateTime.Today; if (ModelState.IsValid) { //Is there a photo? If so save it if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } //Add the photo to the database and save it db.Photos.Add(photo); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(photo)); }