Пример #1
0
        public bool AddComment(Comment comment)
        {
            comment.Date = DateTime.Now;
            context.Comments.Add(comment);

            context.SaveChanges();

            return true;
        }
Пример #2
0
 public ActionResult Add(Comment comment)
 {
     if (ModelState.IsValid)
     {
         repository.AddComment(comment);
         return RedirectToAction("Index", new { id = comment.Post.PostId});
     }
     else
         return View("Index", new { id = comment.Post.PostId });
 }
Пример #3
0
 public HttpResponseMessage PostComment(Comment comment)
 {
     comment.Owner = manager.FindById(User.Identity.GetUserId());
     if (ModelState.IsValid && repository.AddComment(comment))
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, comment);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = comment.CommentId }));
         return response;
     }
     else
         return Request.CreateResponse(HttpStatusCode.BadRequest);
 }