コード例 #1
0
ファイル: CommentRepository.cs プロジェクト: evgeniia242/Blog
        public bool AddComment(Comment comment)
        {
            comment.Date = DateTime.Now;
            context.Comments.Add(comment);

            context.SaveChanges();

            return true;
        }
コード例 #2
0
ファイル: DefaultController.cs プロジェクト: evgeniia242/Blog
 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);
 }