Example #1
0
 public IHttpActionResult Post([FromBody] Recommendation recommendation)
 {
     try
     {
         int newId = RecommendationDB.InsertNewRecommendation(recommendation);
         recommendation.RecoId = newId;
         return(Created(new Uri(Request.RequestUri.AbsoluteUri + $"/GetRecommendationById/{recommendation.RecoId}"), recommendation));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
Example #2
0
        public IHttpActionResult Delete(int id)
        {
            int val = RecommendationDB.DeleteRecommendation(id);

            if (val > 0)
            {
                return(Ok($"Recommendation with id {id} Successfully deleted!"));
            }
            else
            {
                return(Content(HttpStatusCode.NotFound, $"Recommendation with id {id}  was not found to delete!!!"));
            }
        }
Example #3
0
 public IHttpActionResult Get(int id)
 {
     try
     {
         Recommendation r = RecommendationDB.GetRecommendationById(id);
         if (r != null)
         {
             return(Ok(r));
         }
         else
         {
             return(Content(HttpStatusCode.NotFound, "Post dont found!"));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
Example #4
0
 public IHttpActionResult GetAllFullRecommendationsById(int id)
 {
     try
     {
         ExtendedRecommendation[] temp = RecommendationDB.GetAllFullRecommendationsById(id).ToArray();
         if (temp != null)
         {
             return(Ok(temp));
         }
         else
         {
             return(Content(HttpStatusCode.NotFound, "Recommendations cannot be found!"));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
Example #5
0
        public IHttpActionResult Put([FromBody] Recommendation recommendation)
        {
            try
            {
                int val = RecommendationDB.UpdateRecommendation(recommendation);

                if (val > 0)
                {
                    return(Content(HttpStatusCode.OK, recommendation));
                }
                else
                {
                    return(Content(HttpStatusCode.NotFound, $"Recommendation with id {recommendation.RecoId} was not found to update!"));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }