Esempio n. 1
0
        public ActionResult Get(int id)
        {
            RecipeapiContext con     = new RecipeapiContext();
            ExComment        comment = con.Comment.Where(com => com.Id == id).Select(com => new ExComment {
                Id          = com.Id,
                Comment     = com.Comment1,
                User        = com.UserNavigation.Name,
                RecipeTitle = com.RecipeNavigation.Name,
                Rating      = com.Rating
            }).FirstOrDefault();

            if (comment != null)
            {
                return(Ok(comment));
            }
            return(NotFound());
        }
Esempio n. 2
0
        public ActionResult Post(ExComment commentObj)
        {
            RecipeapiContext con        = new RecipeapiContext();
            Comment          newComment = new Comment();

            newComment.Rating   = commentObj.Rating;
            newComment.Comment1 = commentObj.Comment;
            newComment.User     = commentObj.UserID;
            newComment.Recipe   = commentObj.RecipeId;
            con.Comment.Add(newComment);
            int result = con.SaveChanges();

            if (result > 0)
            {
                return(Ok(newComment));
            }
            return(BadRequest("Could not save"));
        }