public ActionResult PostComment(Business.Models.Comment model) { ViewBag.ArticleId = model.ArticleId; try { if (ModelState.IsValid) { model.Created = DateTime.Now; model.UserName = User.Identity.Name; var newComment = this.commentService.Create(model); if (newComment != null && newComment.Id != Guid.Empty) { return(RedirectToAction("Details", "Article", new { id = model.ArticleId })); } ModelState.AddModelError(null, "Unable to create a new comment. Please try again."); return(RedirectToAction("Details", "Article", new { id = model.ArticleId })); } else { // Si entra acá es porque alguno de los campos requeridos no está presente // entonces volvemos a mostrar la vista y pasamos el modelo. return(RedirectToAction("Details", "Article", new { id = model.ArticleId })); } } catch (Exception e) { return(RedirectToAction("Details", "Article", new { id = model.ArticleId })); } }
public static Business.Models.Comment Convert(Services.Comment origin) { Business.Models.Comment destiny = new Business.Models.Comment { ArticleId = origin.ArticleId, UserName = origin.UserName, Id = origin.Id, Created = origin.Created, Content = origin.Content }; return(destiny); }
/// <summary> /// /// </summary> /// <returns></returns> private TecnoBlog.Business.Models.Comment GenerateCommentModel() { var model = new Business.Models.Comment { UserName = "******", Content = "Test Content", Created = new DateTime(2018, 1, 1), Id = Guid.Parse("c23f5a47-5256-4a2d-9748-3b50eeb1a5d8"), ArticleId = Guid.Parse("e605822e-d4c0-4b4c-929e-09628573485f") }; return(model); }
public ActionResult Edit(Guid id, Business.Models.Comment model) { try { if (ModelState.IsValid) { this.commentService.Update(id, model); return(RedirectToAction("Index")); } return(View(model)); } catch { return(View()); } }
public ActionResult Create(Guid articleId) { Business.Models.Comment model = new Business.Models.Comment(); model.ArticleId = articleId; return(View(model)); }