internal static void SavePendingRating(RatingInputModel input) { using (var ctx = new DIHMTEntities()) { var pendingRatingObject = new PendingSubmission { GameId = input.Id, RatingExplanation = input.RatingExplanation, Basically = input.Basically, TimeOfSubmission = DateTime.UtcNow, SubmitterIp = input.SubmitterIp, Comment = input.Comment }; ctx.PendingSubmissions.Add(pendingRatingObject); ctx.SaveChanges(); ctx.PendingDbGameRatings.AddRange(input.Flags?.Select(x => new PendingDbGameRating { PendingSubmissionId = pendingRatingObject.Id, RatingId = x }) ?? new List <PendingDbGameRating>()); ctx.PendingGameLinks.AddRange(input.Links?.Select(x => new PendingGameLink { PendingSubmissionId = pendingRatingObject.Id, Link = x }) ?? new List <PendingGameLink>()); ctx.SaveChanges(); } }
public async Task <ActionResult <RatingResponseModel> > Post(RatingInputModel input) { var userId = this.userManager.GetUserId(this.User); var ratingResponseModel = new RatingResponseModel(); if (userId == null) { ratingResponseModel.AuthenticationErrorMessage = "Please log in in order to vote."; ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId); return(ratingResponseModel); } if (input.Rate < 1 || input.Rate > 5) { ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId); return(ratingResponseModel); } await this.ratingsService.RateAsync(input.ProjectId, userId, input.Rate); ratingResponseModel.Rating = this.ratingsService.GetRating(input.ProjectId); return(ratingResponseModel); }
public async Task <ActionResult <StarRatingResponseModel> > Post(RatingInputModel input) { var userId = this.userManager.GetUserId(this.User); var starRatingResponseModel = new StarRatingResponseModel(); if (userId == null) { starRatingResponseModel.AuthenticateErrorMessage = ExceptionMessages.AuthenticatedErrorMessage; starRatingResponseModel.StarRatingsSum = await this.ratingsService.GetStarRatingsAsync(input.ProductId); return(starRatingResponseModel); } try { await this.ratingsService.VoteAsync(input.ProductId, userId, input.Rating); } catch (ArgumentException ex) { starRatingResponseModel.ErrorMessage = ex.Message; return(starRatingResponseModel); } finally { starRatingResponseModel.StarRatingsSum = await this.ratingsService.GetStarRatingsAsync(input.ProductId); starRatingResponseModel.NextVoteDate = await this.ratingsService.GetNextVoteDateAsync(input.ProductId, userId); } return(starRatingResponseModel); }
public static RatingEntity ToBllRating(this RatingInputModel rating) { return(new RatingEntity { Value = rating.Value }); }
public async Task CreateRatingChangesRatingsIfItAlreadyExists() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var creatorId = "2"; var expectedRatingCount = ratingList.Count(); var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new RatingInputModel() { MediaId = "3", Value = 5, }; // Act await reviewService.CreateRating(inputModel.MediaId, creatorId, inputModel.Value); var newValue = ratingMock.Object.All().Where(x => x.MediaId == inputModel.MediaId && x.CreatorId == creatorId).FirstOrDefault().Score; // Assert Assert.Equal(expectedRatingCount, ratingMock.Object.All().Count()); Assert.Equal(inputModel.Value, newValue); }
public async Task CreateRatingAddsNewIfItDoesNotExist() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var expectedRatingCount = ratingList.Count() + 1; var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new RatingInputModel() { MediaId = "4", Value = 5, }; // Act await reviewService.CreateRating(inputModel.MediaId, "2", inputModel.Value); // Assert Assert.Equal(expectedRatingCount, ratingMock.Object.All().Count()); Assert.Contains(ratingMock.Object.All(), x => x.MediaId == inputModel.MediaId && x.Score == inputModel.Value); }
public async Task <IActionResult> AddRating(int score, string comment, int bookID) { //Gets current User. var user = await _userManager.GetUserAsync(User); var userID = user.Id; //Sees if user filled in comment. Avoids null reference error when doing comment.Length. if (comment != null) { //Comment can not exceed 500. if (comment.Length > 500) { //Returns user to the Rating Site to write again. return(RedirectToAction("Rating", "Book", new { id = bookID })); } } //Creates a new Review model. var newReview = new RatingInputModel() { Score = score, Comment = comment, BookID = bookID, UserID = userID, }; //Adds the rating itself. The comment which is at the bottom of the page. _ratingService.AddRating(newReview); //Updates the book star rating. _bookService.AddRating(newReview); //Redirects User to Details. return(RedirectToAction("Details", "Book", new { id = bookID })); }
public async Task <IActionResult> RateProduct(RatingInputModel inputModel) { var userId = this.userManager.GetUserId(this.User); await this.ratingsService.RateProductAsync(inputModel.ProductId, userId, inputModel.Value); return(this.Ok(new { response = "200 OK" })); }
public async Task <ActionResult <RatingResponseModel> > Vote(RatingInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.ratingsService.VoteAsync(userId, input.TripId, input.Value); var averageRating = this.ratingsService.GetAverageRating(input.TripId); return(new RatingResponseModel { AverageRating = averageRating, UserVoteValue = input.Value }); }
public async Task <ActionResult <RatingResponseModel> > Post(RatingInputModel input) { var userId = this.userManager.GetUserId(this.User); await this.ratingsService.RatingAsync(input.RecipeId, userId, input.Stars); var ratings = this.ratingsService.GetRatings(input.RecipeId); return(new RatingResponseModel { Ratings = ratings }); }
public ActionResult SubmitRating(RatingInputModel input) { if (ModelState.Keys.Contains("ReCaptcha") && ModelState["ReCaptcha"].Errors.Any()) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; return(Json("Captcha error - please complete the captcha and try again.")); } if (input.Valid && Request.UserHostAddress != null) { if (!input.Flags.Contains((int)EnumTag.Spotless) && (string.IsNullOrEmpty(input.Basically) || string.IsNullOrEmpty(input.RatingExplanation))) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; return(Json(System.Text.RegularExpressions.Regex.Unescape("When submitting a game without the 'Spotless'-tag, we require that you fill out the 'Basically' and 'Rating Explanation'-fields explaining the game's purchases in some detail. Please fill out those fields and submit again."))); } input.SubmitterIp = string.Empty; if (!Request.IsAuthenticated) { input.SubmitterIp = CryptHelper.Hash(Request.UserHostAddress); var blockStatus = BlockHelpers.GetBlockStatus(input.SubmitterIp); if (blockStatus == BlockType.ExplicitBlocked) { Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; return(Json("We have temporarily stopped your ability to send in submissions - come back tomorrow and you can submit ratings again.")); } if (blockStatus == BlockType.HiddenBlocked) { return(Json("Your submission has been accepted. It will go live as soon as it's been verified. Thank you for helping out!")); } } GameHelpers.SubmitRating(input, Request.IsAuthenticated); if (Request.IsAuthenticated) { return(Json("All clear.")); } return(Json("Your submission has been accepted. It will go live as soon as it's been verified. Thank you for helping out!")); } Response.TrySkipIisCustomErrors = true; Response.StatusCode = 400; // Bad Request return(Json("Something went wrong with your submission - most likely, you have a malformed URL in the \"Links\"-section. Please try again or contact one of the site administrators.")); }
public IActionResult RateAppointment(int id) { var appointment = this._appointmentService .GetAppointmentById(id); var ratingInputModel = new RatingInputModel { DentistId = appointment.DentistID, PatientId = appointment.PatientId, AppointmentId = id, }; return(View(ratingInputModel)); }
public static void SubmitRating(RatingInputModel input, bool isAuthenticated) { input.Flags = input.Flags ?? new List <int>(); input.Flags.Sort(); if (isAuthenticated) { DbAccess.SaveGameRating(input); } else { DbAccess.SavePendingRating(input); } }
public async Task <ActionResult <RatingResponseModel> > Post(RatingInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.reviewService.CreateRating(input.MediaId, userId, input.Value); var ratingService = await this.reviewService.GetRatingAverageCount(input.MediaId); var average = ratingService.Item1; var count = ratingService.Item2; var response = new RatingResponseModel() { TotalVotes = count, AverageVote = average, }; return(response); }
//Updates rating value for the book. public void AddRating(RatingInputModel model) { //Finds the book. var book = (from b in _db.Books where b.ID == model.BookID select b).First(); if (book != null) { //Creates a new rating based on the average of all ratings. double newRating = (((book.Rating * book.NumberOfRatings) + model.Score) / (book.NumberOfRatings + 1)); book.Rating = newRating; book.NumberOfRatings++; //Updates the book. _db.Books.Update(book); _db.SaveChanges(); } }
//Adds new ratings. public void AddRating(RatingInputModel model) { var rating = (from r in _db.Ratings where r.UserID == model.UserID && r.BookID == model.BookID select r).FirstOrDefault(); if (rating == null) { var newRating = new RatingEntityModel() { Score = model.Score, Comment = model.Comment, UserID = model.UserID, BookID = model.BookID, Votes = 1, }; _db.Ratings.Add(newRating); _db.SaveChanges(); } }
public static void SaveGameRating(RatingInputModel input) { lock (Lock) { using (var ctx = new DIHMTEntities()) { var game = ctx.DbGames.FirstOrDefault(x => x.Id == input.Id); 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.Id)); // Add ratings from input ctx.DbGameRatings.AddRange(input.Flags?.Select(x => new DbGameRating { GameId = input.Id, RatingId = x }) ?? new List <DbGameRating>()); // Remove current links ctx.DbGameLinks.RemoveRange(ctx.DbGameLinks.Where(x => x.GameId == input.Id)); // Add links from input ctx.DbGameLinks.AddRange(input.Links?.Select(x => new DbGameLink { GameId = input.Id, Link = x }) ?? new List <DbGameLink>()); ctx.SaveChanges(); } } } }
public KnowledgeSkillViewModel() { ParentFields = new List <FieldViewModel>(); RatingInput = new RatingInputModel(); }
public void AddRating(RatingInputModel model) { _bookRepo.AddRating(model); }
public RatingModel AddRating(RatingInputModel ratingInputModel) { return(Post <RatingModel, RatingInputModel>("core_rating_add_rating", ratingInputModel)); }