public ActionResult AddComment(string text, string userId, Guid photoId) { var user = Session.Query<User>().Where(x => x.Id == SecurityManager.AuthenticatedUser.Id).FirstOrDefault(); if (user == null) { throw new InvalidOperationException(); } var photo = Session.Query<Photo>().Where(x => x.Id == photoId).FirstOrDefault(); if (photo == null) { throw new InvalidOperationException(); } var model = new PreviewViewModel(); model.Photo = photo; model.CanLike = !model.Photo.Likes.Any(x => x.Liker.Id == SecurityManager.AuthenticatedUser.Id); if (string.IsNullOrEmpty(text.Trim())) { return Redirect("/Preview/?id=" + photoId.ToString()); } var comment = new Comment(Guid.NewGuid(), text.Trim(), DateTime.Now, user, photo); Session.Save(comment); photo.Comments.Add(comment); return Redirect("/Preview/?id=" + photoId.ToString()); }
public ActionResult Index(Guid id) { var model = new PreviewViewModel(); model.Photo = Session.Query<Photo>().Where(x => x.Id == id).FirstOrDefault(); model.CanLike = SecurityManager.AuthenticatedUser != null && !model.Photo.Likes.Any(x => x.Liker.Id == SecurityManager.AuthenticatedUser.Id); if (model.Photo == null) { return RedirectToAction("Index", "Home"); } return View(model); }