public static void HandlePostPending(PendingDisplayModel input) { if (input.SubmitAction == "Approve") { DbAccess.ApprovePendingRating(input); } else { DbAccess.RejectPendingRating(input); } }
/// <summary> /// Returns a Tuple containing a pending rating, as well as the current entry /// of the game that the pending rating is for /// </summary> /// <param name="id">Id of the pending rating to get</param> /// <returns> /// A Tuple - Item1 is the entry as it exists now on the public-facing site, /// Item2 is the requested pending rating as a PendingDisplayModel /// </returns> internal static Tuple <DisplayGame, PendingDisplayModel> GetPendingSubmissionWithCurrentRating(int id) { var pendingRaw = DbAccess.GetPendingSubmission(id); if (pendingRaw == null) { return(null); } var pending = new PendingDisplayModel(pendingRaw); var currentRating = CreateDisplayGameObject(pendingRaw.GameId); return(new Tuple <DisplayGame, PendingDisplayModel>(currentRating, pending)); }
public static void ApprovePendingRating(PendingDisplayModel input) { lock (Lock) { using (var ctx = new DIHMTEntities()) { var game = ctx.DbGames.FirstOrDefault(x => x.Id == input.GameId); if (game != null) { // Set IsRated + RatingLastUpdated & update explanation game.IsRated = true; game.RatingLastUpdated = input.QuietUpdate ? game.RatingLastUpdated : DateTime.UtcNow; game.Basically = input.Basically; game.RatingExplanation = input.RatingExplanation; // Remove current ratings ctx.DbGameRatings.RemoveRange(ctx.DbGameRatings.Where(x => x.GameId == input.GameId)); // Remove current links ctx.DbGameLinks.RemoveRange(ctx.DbGameLinks.Where(x => x.GameId == input.GameId)); // Add ratings from input ctx.DbGameRatings.AddRange(input.RatingModel.Flags?.Select(x => new DbGameRating { GameId = input.GameId, RatingId = x }) ?? new List <DbGameRating>()); // Add links from input ctx.DbGameLinks.AddRange(input.RatingModel.Links?.Select(x => new DbGameLink { GameId = input.GameId, Link = x }) ?? new List <DbGameLink>()); // Remove pending ratings ctx.PendingDbGameRatings.RemoveRange(ctx.PendingDbGameRatings.Where(x => x.RatingId == input.Id)); // Remove pending links ctx.PendingGameLinks.RemoveRange(ctx.PendingGameLinks.Where(x => x.PendingSubmissionId == input.Id)); // Remove pending submission ctx.PendingSubmissions.Remove(ctx.PendingSubmissions.First(x => x.Id == input.Id)); ctx.SaveChanges(); } } } }
public static void RejectPendingRating(PendingDisplayModel input) { lock (Lock) { using (var ctx = new DIHMTEntities()) { // Remove pending ratings ctx.PendingDbGameRatings.RemoveRange(ctx.PendingDbGameRatings.Where(x => x.RatingId == input.Id)); // Remove pending links ctx.PendingGameLinks.RemoveRange(ctx.PendingGameLinks.Where(x => x.PendingSubmissionId == input.Id)); // Remove pending submission ctx.PendingSubmissions.Remove(ctx.PendingSubmissions.First(x => x.Id == input.Id)); ctx.SaveChanges(); } } }