private static Ratings MapRatings(RatingResource rating) { if (rating == null) { return(new Ratings()); } return(new Ratings { Votes = rating.Count, Value = rating.Value }); }
private static Ratings MapRatings(RatingResource ratings) { if (ratings == null) { return(new Ratings()); } var mappedRatings = new Ratings(); if (ratings.Tmdb != null) { mappedRatings.Tmdb = new RatingChild { Type = (RatingType)Enum.Parse(typeof(RatingType), ratings.Tmdb.Type), Value = ratings.Tmdb.Value, Votes = ratings.Tmdb.Count }; } if (ratings.Imdb != null) { mappedRatings.Imdb = new RatingChild { Type = (RatingType)Enum.Parse(typeof(RatingType), ratings.Imdb.Type), Value = ratings.Imdb.Value, Votes = ratings.Imdb.Count }; } if (ratings.Metacritic != null) { mappedRatings.Metacritic = new RatingChild { Type = (RatingType)Enum.Parse(typeof(RatingType), ratings.Metacritic.Type), Value = ratings.Metacritic.Value, Votes = ratings.Metacritic.Count }; } if (ratings.RottenTomatoes != null) { mappedRatings.RottenTomatoes = new RatingChild { Type = (RatingType)Enum.Parse(typeof(RatingType), ratings.RottenTomatoes.Type), Value = ratings.RottenTomatoes.Value, Votes = ratings.RottenTomatoes.Count }; } return(mappedRatings); }
public RatingResource AddRating([FromBody] RatingResource ratingResource) { var entity = new Rating { BookId = ratingResource.BookId, Comment = ratingResource.Comment, RatingGiven = ratingResource.RatingGiven, User = User.Identity.Name }; _dataBeastContext.Ratings.Add(entity); _dataBeastContext.SaveChanges(); return(new RatingResource(entity)); }