Пример #1
0
        public ActionResult Create(ComentarioDTO comentario)
        {
            if (ModelState.IsValid)
            {
                var novoNovocomentario = new Comentario { Texto = comentario.Texto,
                Post = db.Posts.Find(comentario.PostId)};
                db.Comentarios.Add(novoNovocomentario);
                db.SaveChanges();
                return RedirectToAction("Details", "Post", new { id = comentario.PostId });
            }

            return View(comentario);
        }
Пример #2
0
        // POST api/Comentario
        public HttpResponseMessage PostComentario(ComentarioDTO comentario)
        {
            if (ModelState.IsValid)
            {
                var novoComentario = new Comentario { Texto = comentario.Texto, Post = db.Posts.Find(comentario.PostId) };
                db.Comentarios.Add(novoComentario);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, novoComentario);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = novoComentario.ComentarioId }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }