Beispiel #1
0
        public IHttpActionResult PostComment(Comment comment)
        {
            string currentUserId = User.Identity.GetUserId();
            if (currentUserId == null)
                return Unauthorized();
            /*if(VideoId == null)
                return BadRequest(ModelState);
            comment.VideoId = (int)VideoId;*/
            comment.User = db.Users.FirstOrDefault(x => x.Id == currentUserId);
            comment.PostedDate = DateTime.Now;
            ModelState.Clear();
            TryValidateModel(comment);
            if (!TryValidateModel(comment))
            {
                return BadRequest(ModelState);
            }

            db.Comments.Add(comment);
            db.SaveChanges();

            return Ok(new
            {
                success=true, result = comment

            });
            //return CreatedAtRoute("DefaultApi", new { id = comment.CommentId }, comment);
        }
Beispiel #2
0
        public IHttpActionResult PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != comment.CommentId)
            {
                return BadRequest();
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }