public async Task <JsonNetResult> GetRatings(GetRatingsViewModel model) { // We definitely want the overall rating info, so start there Task <VideoRating> ratingTask = _ratings.GetRating(model.VideoId); // If a user is logged in, we also want their rating Guid?userId = User.GetCurrentUserId(); Task <UserVideoRating> userRatingTask = null; if (userId.HasValue) { userRatingTask = _ratings.GetRatingFromUser(model.VideoId, userId.Value); } // Await data appropriately VideoRating ratingData = await ratingTask; UserVideoRating userRating = null; if (userRatingTask != null) { userRating = await userRatingTask; } return(JsonSuccess(new RatingsViewModel { VideoId = ratingData.VideoId, CurrentUserLoggedIn = userId.HasValue, CurrentUserRating = userRating == null ? 0 : userRating.Rating, RatingsCount = ratingData.RatingsCount, RatingsSum = ratingData.RatingsTotal })); }
/// <summary> /// Renders the Event page /// </summary> /// <param name="model"></param> /// <returns></returns> public override ActionResult Index(RenderModel model) { var typedModel = model.As <EventDetail>(); if (ratingsService != null) { typedModel.EventRating = ratingsService.GetRating(typedModel.Id); } return(CurrentTemplate(typedModel)); }
public async Task <ActionResult> UpdateRatingAsync([FromBody] RateModel model) { var ratingDto = new UpdateRatingDTO() { FilmId = model.FilmId, Rating = model.Rating, UserId = HttpContext.GetCurrentUserId() }; try { await _ratingsService.AddRatingAsync(ratingDto); await _FilmsService.UpdateRatingAsync(model.FilmId); return(Ok(_ratingsService.GetRating(model.FilmId, ratingDto.UserId))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult <int> GetRating(int recipeId) { return(_ratingsService.GetRating(recipeId, GetUserId())); }