Exemple #1
0
 public object Put(int id, [FromBody] RatingPostDto model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Rating rating = _context.Rating.SingleOrDefault(m => m.Id == id);
             if (rating == null)
             {
                 return(NotFound());
             }
             model.UpdateRating(rating);
             _context.Update(rating);
             _context.SaveChanges();
             return(StatusCode(200, rating));
         }
         catch (Exception exception)
         {
             return(BadRequest(new { exception = exception.InnerException.Message }));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemple #2
0
 public object Post([FromBody] RatingPostDto model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Rating rating = model.GetRating();
             _context.Add(rating);
             _context.SaveChanges();
             return(StatusCode(201, rating));
         }
         catch (Exception exception)
         {
             return(BadRequest(new { exception = exception.InnerException.Message }));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }