public void UpdateShowByMediaId(Guid mediaId, EditShowViewModel show) { try { var result = FilmHausDbContext.Shows.Find(mediaId); if (result == null) { throw new ArgumentNullException(); } result.PosterUri = show.PosterUri; result.MediaName = show.MediaName; result.DateOfRelease = show.DateOfRelease; result.Accolades = show.Accolades; result.NumberOfSeasons = show.NumberOfSeasons; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void UpdateFilmByMediaId(Guid mediaId, EditFilmViewModel film) { try { var result = FilmHausDbContext.Films.Find(mediaId); if (result == null) { throw new ArgumentNullException(); } result.PosterUri = film.PosterUri; result.MediaName = film.MediaName; result.DateOfRelease = film.DateOfRelease; result.Accolades = film.Accolades; result.Runtime = film.Runtime; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }
public void UpdateReviewByReviewId(Guid reviewId, EditReviewViewModel review) { try { var result = FilmHausDbContext.Reviews.Find(reviewId); if (result == null) { throw new ArgumentNullException(); } result.Body = review.Body; if (!result.Flagged) { result.Shared = review.Shared; } FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }
public void DeleteListByListId(Guid listId) { try { var result = FilmHausDbContext.Lists.Find(listId); if (result == null) { throw new KeyNotFoundException($"No entity found for key: {listId}"); } foreach (var lf in FilmHausDbContext.ListFilms.Where(rf => rf.ListId == result.ListId).Select(rf => rf).ToList()) { FilmHausDbContext.ListFilms.Remove(lf); } foreach (var ls in FilmHausDbContext.ListShows.Where(rs => rs.ListId == result.ListId).Select(rs => rs).ToList()) { FilmHausDbContext.ListShows.Remove(ls); } //foreach (var rs in FilmHausDbContext.ListSeasons.Where(rs => rs.ListId == review.ListId).Select(rs => rs).ToList()) // FilmHausDbContext.ListShows.Remove(rs); //foreach (var re in FilmHausDbContext.ListEpisodes.Where(re => re.ListId == review.ListId).Select(re => re).ToList()) // FilmHausDbContext.ListShows.Remove(re); FilmHausDbContext.SaveChanges(); FilmHausDbContext.Lists.Remove(result); FilmHausDbContext.SaveChanges(); } catch { throw; } }
/// <summary> /// Changes a <see cref="int"/> rating by a <see cref="User"/> to a <see cref="Film"/> /// </summary> /// <param name="userId"><see cref="User"/> who made the rating</param> /// <param name="mediaId"><see cref="Film"/> the rating was for</param> /// <param name="rating"><see cref="int"/> representing the rating</param> /// <returns>True on success, False otherwise</returns> public bool ChangeRatingInUserLibrary(string userId, Guid mediaId, int rating) { try { var oldRating = FilmHausDbContext.UserFilmRatings.Where(ufr => ufr.MediaId == mediaId && ufr.Id == userId && ufr.ObsoletedOn == null).FirstOrDefault(); if (oldRating == null) { throw new ArgumentNullException(); } oldRating.ObsoletedOn = DateTime.Now; FilmHausDbContext.UserFilmRatings.Add(new UserFilmRating { UserFilmRatingId = Guid.NewGuid(), Id = oldRating.Id, MediaId = oldRating.MediaId, CreatedOn = DateTime.Now, ObsoletedOn = null, Rating = rating }); FilmHausDbContext.Entry(oldRating).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { return(false); } return(true); }
public void CreateReviewForShow(CreateReviewViewModel review, string userId) { var newReview = CreateReview(review, userId); FilmHausDbContext.Reviews.Add(newReview); FilmHausDbContext.SaveChanges(); ReviewShowService.CreateReviewShow(newReview.ReviewId, review.MediaId); }
public void CreateList(CreateListViewModel list) { FilmHausDbContext.Lists.Add(new List { ListId = Guid.NewGuid(), Id = list.Id, CreatedOn = DateTime.Now, Title = list.Title, Description = list.Description, Shared = list.Shared }); FilmHausDbContext.SaveChanges(); }
public void DeleteReviewByReviewId(Guid reviewId) { try { var review = FilmHausDbContext.Reviews.Find(reviewId); if (review == null) { throw new KeyNotFoundException($"No entity found for key: {reviewId}"); } switch (review.ReviewType) { case ReviewType.Film: foreach (var rf in FilmHausDbContext.ReviewFilms.Where(rf => rf.ReviewId == review.ReviewId).Select(rf => rf).ToList()) { FilmHausDbContext.ReviewFilms.Remove(rf); } break; case ReviewType.Show: foreach (var rs in FilmHausDbContext.ReviewShows.Where(rs => rs.ReviewId == review.ReviewId).Select(rs => rs).ToList()) { FilmHausDbContext.ReviewShows.Remove(rs); } break; case ReviewType.Season: //foreach (var rs in FilmHausDbContext.ReviewSeasons.Where(rs => rs.ReviewId == review.ReviewId).Select(rs => rs).ToList()) // FilmHausDbContext.ReviewShows.Remove(rs); break; case ReviewType.Episode: //foreach (var re in FilmHausDbContext.ReviewEpisodes.Where(re => re.ReviewId == review.ReviewId).Select(re => re).ToList()) // FilmHausDbContext.ReviewShows.Remove(re); break; default: throw new InvalidReviewTypeException($"Invalid Review Type! Given: {review.ReviewType}"); } FilmHausDbContext.SaveChanges(); FilmHausDbContext.Reviews.Remove(review); FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }
public void CreateFilm(CreateFilmViewModel film) { FilmHausDbContext.Films.Add(new Film { MediaId = Guid.NewGuid(), MediaName = film.MediaName, DateOfRelease = film.DateOfRelease, Accolades = film.Accolades, PosterUri = film.PosterUri, Runtime = film.Runtime, CreatedOn = DateTime.Now }); FilmHausDbContext.SaveChanges(); }
public void CreateShow(CreateShowViewModel show) { FilmHausDbContext.Shows.Add(new Show { MediaId = Guid.NewGuid(), MediaName = show.MediaName, DateOfRelease = show.DateOfRelease, Accolades = show.Accolades, PosterUri = show.PosterUri, NumberOfSeasons = show.NumberOfSeasons, CreatedOn = DateTime.Now }); FilmHausDbContext.SaveChanges(); }
public void Create(CreateReportViewModel viewModel) { FilmHausDbContext.Reports.Add(new Report { ReportId = Guid.NewGuid(), ReviewReportedId = viewModel.ReviewReportedId, ReportedOn = DateTime.Now, ResolvedOn = null, ReportStatus = ReportStatus.Unresolved, ReportReason = viewModel.ReportReason, ReportingUserId = viewModel.ReportingUserId, UserReportedId = viewModel.UserReportedId }); FilmHausDbContext.SaveChanges(); ReviewService.FlagReviewByReviewId(viewModel.ReviewReportedId); }
public void BanReviewByReviewId(Guid reviewId, ReportReason reportReason) { try { var review = FilmHausDbContext.Reviews.Find(reviewId); if (review == null) { throw new ArgumentNullException(); } switch (review.ReviewType) { case ReviewType.Film: var reviewFilm = FilmHausDbContext.ReviewFilms.Where(rf => rf.ReviewId == reviewId && rf.ObsoletedOn == null).FirstOrDefault(); ReviewFilmService.ObsoleteReviewFilm(reviewFilm.ReviewId, reviewFilm.MediaId); break; case ReviewType.Show: var reviewShow = FilmHausDbContext.ReviewShows.Where(rf => rf.ReviewId == reviewId && rf.ObsoletedOn == null).FirstOrDefault(); ReviewShowService.ObsoleteReviewShow(reviewShow.ReviewId, reviewShow.MediaId); break; case ReviewType.Season: break; case ReviewType.Episode: break; default: break; } review.ReportReason = reportReason; review.Shared = false; review.IsActive = false; FilmHausDbContext.Entry(review).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void Delete(Guid reportId) { try { var report = FilmHausDbContext.Reports.Find(reportId); if (report == null) { throw new ArgumentNullException(); } FilmHausDbContext.Reports.Remove(report); FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void DeleteShowByMediaId(Guid mediaId) { try { var show = FilmHausDbContext.Shows.Find(mediaId); if (show == null) { throw new ArgumentNullException(); } FilmHausDbContext.Shows.Remove(show); FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void Obsolete(Guid reportId) { try { var result = FilmHausDbContext.Reports.Find(reportId); if (result == null) { throw new ArgumentNullException(); } result.ResolvedOn = DateTime.Now; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void DeleteFilmByMediaId(Guid mediaId) { try { var film = FilmHausDbContext.Films.Find(mediaId); if (film != null) { FilmHausDbContext.Films.Remove(film); FilmHausDbContext.SaveChanges(); } else { throw new ArgumentNullException(); } } catch (InvalidOperationException ex) { throw ex; } }
public void UpdateListByListId(Guid listId, EditListViewModel list) { try { var result = FilmHausDbContext.Lists.Find(listId); if (result == null) { throw new KeyNotFoundException(); } result.Description = list.Description; result.Shared = list.Shared; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } }
public void UnflagReviewByReviewId(Guid reviewId) { try { var result = FilmHausDbContext.Reviews.Find(reviewId); if (result == null) { throw new ArgumentNullException(); } result.Flagged = false; result.Shared = true; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
/// <summary> /// Obsoletes the <see cref="User"/>s current rating of a <see cref="Film"/> /// </summary> /// <param name="userId"><see cref="User"/> who made the rating</param> /// <param name="mediaId"><see cref="Film"/> the rating was made for</param> /// <returns>True on success, False otherwise</returns> public bool ObsoleteRatinginUserLibrary(string userId, Guid mediaId) { try { var result = FilmHausDbContext.UserFilmRatings.Where(ufr => ufr.MediaId == mediaId && ufr.Id == userId && ufr.ObsoletedOn == null).FirstOrDefault(); if (result == null) { throw new ArgumentNullException(); } result.ObsoletedOn = DateTime.Now; FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { return(false); } return(true); }
public void ObsoleteReviewForShow(Guid reviewId, Guid mediaId) { try { ReviewShowService.ObsoleteReviewShow(reviewId, mediaId); var review = FilmHausDbContext.Reviews.Find(reviewId); if (review == null) { throw new ArgumentNullException(); } review.IsActive = false; FilmHausDbContext.Entry(review).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
public void Resolve(Guid reportId, ResolveReportViewModel viewModel) { try { var result = FilmHausDbContext.Reports.Find(reportId); if (result == null) { throw new ArgumentNullException(); } result.ReportStatus = viewModel.ReportStatus; switch (viewModel.ReportStatus) { case ReportStatus.Accepted: ReviewService.BanReviewByReviewId(result.ReviewReportedId, result.ReportReason); result.ResolvedOn = DateTime.Now; break; case ReportStatus.Rejected: ReviewService.UnflagReviewByReviewId(result.ReviewReportedId); result.ResolvedOn = DateTime.Now; break; default: break; } FilmHausDbContext.Entry(result).State = EntityState.Modified; FilmHausDbContext.SaveChanges(); } catch { throw; } }
/// <summary> /// Adds a <see cref="int"/> rating by a <see cref="User"/> to a <see cref="Film"/> /// </summary> /// <param name="userId"><see cref="User"/> who made the rating</param> /// <param name="mediaId"><see cref="Film"/> the rating was for</param> /// <param name="rating"><see cref="int"/> representing the rating</param> /// <returns>True on success, False otherwise</returns> public bool AddRatingToUserLibrary(string userId, Guid mediaId, int rating) { try { if (!UserFilmService.IsFilmInLibrary(mediaId, userId)) { UserFilmService.AddFilmToUserLibrary(mediaId, userId); } var possibleRecord = FilmHausDbContext.UserFilmRatings.Where(ufr => ufr.MediaId == mediaId && ufr.Id == userId && ufr.ObsoletedOn == null).FirstOrDefault(); if (possibleRecord == null) { FilmHausDbContext.UserFilmRatings.Add(new UserFilmRating { UserFilmRatingId = Guid.NewGuid(), Id = userId, MediaId = mediaId, CreatedOn = DateTime.Now, ObsoletedOn = null, Rating = rating }); FilmHausDbContext.SaveChanges(); } else { return(ChangeRatingInUserLibrary(userId, mediaId, rating)); } } catch { return(false); } return(true); }
public ReviewShowService(FilmHausDbContext filmHausDbContext) { FilmHausDbContext = filmHausDbContext; }
/// <summary> /// Constructor for the <see cref="ShowPersonTitleService"/> class /// </summary> /// <param name="filmHausDbContext">Accessor for the Db, used for DI</param> public ShowPersonTitleService(FilmHausDbContext filmHausDbContext) { FilmHausDbContext = filmHausDbContext; }
public ShowService(FilmHausDbContext filmHausDbContext, IUserShowService userShowService, IUserShowRatingService userShowRatingService) { FilmHausDbContext = filmHausDbContext; UserShowService = userShowService; UserShowRatingService = userShowRatingService; }
/// <summary> /// Constructor for the <see cref="ListShowService"/> class /// </summary> /// <param name="filmHausDbContext">Accessor for the Db, used for DI</param> public ListShowService(FilmHausDbContext filmHausDbContext) { FilmHausDbContext = filmHausDbContext; }
/// <summary> /// Constructor for the <see cref="UserFilmRatingService"/> class /// </summary> /// <param name="filmHausDbContext">Accessor for the Db, used for DI</param> /// <param name="userFilmService">Accessor for the <see cref="UserFilmService"/></param> public UserFilmRatingService(FilmHausDbContext filmHausDbContext, IUserFilmService userFilmService) { FilmHausDbContext = filmHausDbContext; UserFilmService = userFilmService; }
public ListService(FilmHausDbContext filmHausDbContext, IListFilmService listFilmService, IListShowService listShowService) { FilmHausDbContext = filmHausDbContext; ListShowService = listShowService; ListFilmService = listFilmService; }
/// <summary> /// Constructor for the <see cref="ListTagService"/> class /// </summary> /// <param name="filmHausDbContext">Accessor for the Db, used for DI</param> public ListTagService(FilmHausDbContext filmHausDbContext) { FilmHausDbContext = filmHausDbContext; }
public ReviewService(FilmHausDbContext filmHausDbContext, IReviewFilmService reviewFilmService, IReviewShowService reviewShowService) { FilmHausDbContext = filmHausDbContext; ReviewShowService = reviewShowService; ReviewFilmService = reviewFilmService; }