Example #1
0
 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 }));
     }
 }
Example #2
0
 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);
 }
Example #3
0
        /// <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);
        }
Example #4
0
 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());
     }
 }
Example #5
0
 public ActionResult Create(Guid articleId)
 {
     Business.Models.Comment model = new Business.Models.Comment();
     model.ArticleId = articleId;
     return(View(model));
 }