public async Task AddOrUpdateReviewAsync(AddReviewFilmProductionModel addReviewModel, string userId) { IQueryable <ReviewFilmProduction> qr = _mySerialListDBContext.FilmProductionReviews .Where(r => r.UserId == userId) .Where(r => r.FilmProductionId == addReviewModel.FilmProductionId); if (await qr.AnyAsync()) { ReviewFilmProduction model = await qr.FirstAsync(); model.Grade = addReviewModel.Grade; _mySerialListDBContext.FilmProductionReviews.Update(model); } else { await _mySerialListDBContext.FilmProductionReviews.AddAsync(new ReviewFilmProduction { FilmProductionId = addReviewModel.FilmProductionId, Grade = addReviewModel.Grade, UserId = userId }); } await _mySerialListDBContext.SaveChangesAsync(); }
public async Task AddOrUpdateReviewAsync(AddReviewFilmProductionModel addReviewModel, string userId) { await CheckFilmProductionExist(addReviewModel.FilmProductionId); if (!await _userFilmProductionsRepository.IsFilmProductionAddedAsync(addReviewModel.FilmProductionId, userId)) { throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "Dodaj produkcję filmową do listy aby móc ją ocenić"); } await _reviewFilmProductionRepository.AddOrUpdateReviewAsync(addReviewModel, userId); }
public async Task <ActionResult> AddOrUpdateReviewAsync([FromBody] AddReviewFilmProductionModel addReviewModel) { await _reviewFilmProductionService.AddOrUpdateReviewAsync(addReviewModel, User.Identity.Name); return(Ok()); }