public async Task <IActionResult> Rate([FromBody] RateViewModel model) { var user = await userManager.GetUserAsync(HttpContext.User); if (user == null) { return(Unauthorized()); } if (model == null) { return(NotFound()); } UserRate userRate = await userRateRep.GetUserRateByUserAndTitleAsync(user.Id, model.TitleId); if (userRate == null || userRate?.Id == 0) { await userRateRep.AddAsync(user.Id, model.TitleId, model.Score); } else { userRate.Score = model.Score; await userRateRep.UpdateAsync(userRate); } return(NoContent()); }
public async Task <IActionResult> Title(int titleId) { var movie = await movieRep.Movies.FirstOrDefaultAsync(m => m.Id == titleId); UserRate userRate = await userRateRep.GetUserRateByUserAndTitleAsync(User.GetUserId(), movie.Id); if (movie == null) { return(NotFound()); } return(View(new UserMovie(movie, userRate?.Score ?? 0))); }