public async Task <ActionResult> PostRatings(RatingsDto rating) { var conf = await _videosRepo.RateVideo(rating); if (!conf) { _logger.LogError("In videos controller, post ratings, no ratings returned from repo."); return(NotFound("Rating failed")); } var resp = _confirmResp.ConfirmResponse(true, "Rating Submitted"); return(Ok(resp)); }
public async Task <ActionResult <RatingsDto> > AddRatings(int restaurantId, RatingsDto ratingsDto) { if (await _restaurantRepository.RestaurantExists(restaurantId) == false) { return(NotFound()); } var ratings = _mapper.Map <Ratings>(ratingsDto); ratings = _restaurantRepository.AddRating(restaurantId, ratings); var _ratingsDto = _mapper.Map <RatingsDto>(ratings); return(CreatedAtRoute("GetRatings", new { restaurantId = _ratingsDto.Id }, _ratingsDto)); }
public async Task <bool> RateVideo(RatingsDto ratingsObject) { var video = await _context.MissionVideos.FindAsync(ratingsObject.VideoId); video.RatingsCount += 1; video.Rating = ratingsObject.Rating / video.RatingsCount; _context.Update(video); var numbr = await _context.SaveChangesAsync(); if (numbr.Equals(0)) { return(false); } return(true); }
public async Task <ActionResult> UpdateRatings(int restaurantId, int ratingId, RatingsDto ratings) { if (await _restaurantRepository.RestaurantExists(restaurantId) == false && _restaurantRepository.GetRatings(restaurantId, ratingId) == null) { return(NotFound()); } await _restaurantRepository.UpdateRatings(restaurantId, ratingId, ratings); _restaurantRepository.Save(); return(Ok()); }
public async Task UpdateRatings(int restaurantId, int ratingId, RatingsDto ratings) { var ratingOfRestaurant = await GetRatings(restaurantId, ratingId); ratingOfRestaurant.Rating = ratings.Rating; }