/// <summary> /// Try to publish <see cref="ReviewForm"/> to the database. /// </summary> private async Task PublishReviewAsync() { IsPublishingReview = true; // make the button to catch up await Task.Delay(1); var review = new Review { Title = ReviewForm.Title, Text = ReviewForm.Text, Rating = (byte)ReviewForm.RatingProduct, PublishDate = DateTime.Now, User = AuthUser, ProductId = ProductId }; if (await Mediator.Send(new AddReview.Command { Review = review })) { Product.Reviews.Add(review); ReviewForm.Clear(); PublicationMessage = "¡Reseña publicada con éxito!"; } else { PublicationMessage = "Lo sentimos, tu reseña no pudo ser publicada :("; } IsPublishingReview = false; }
public async Task <IActionResult> AddReview(ReviewForm model) { if (ModelState.IsValid) { var user = await _workContext.GetCurrentUser(); model.ReviewerName = user.FullName; // Otherwise ReviewerName is null var review = new Review { Rating = model.Rating, Title = model.Title, Comment = model.Comment, ReviewerName = user.FullName, EntityId = model.EntityId, EntityTypeId = model.EntityTypeId, UserId = user.Id, }; _reviewRepository.Add(review); _reviewRepository.SaveChanges(); return(PartialView("_ReviewFormSuccess", model)); } return(PartialView("_ReviewForm", model)); }
public async Task UpdateReview(string userId, string recipeId, ReviewForm reviewForm) { try { Review review = new Review { UserId = userId, RecipeId = recipeId, Content = reviewForm.Content, Rating = reviewForm.Rating, Timestamp = DateTime.Now }; // Update to rating must be performed before update to review. The database will be left in an inconsistent state otherwise. await _dbClient.UpdateUserRatingAsync(userId, review.RecipeId, review.Rating); await _dbClient.UpdateReviewAsync(review); } catch (Exception) { //RollbackUpdateReview(); throw; } }
public async Task <IActionResult> Review(int id, [FromBody] ReviewForm reviewForm, [FromServices] VersionMigrationContext migrationContext) { var modItem = _ctx.ModerationItems .Include(x => x.Reviews) .FirstOrDefault(x => x.Id == id); if (modItem == null) { return(NoContent()); } if (modItem.Deleted) { return(BadRequest("Moderation item no longer exists.")); } // todo make this async safe var review = _ctx.Reviews.FirstOrDefault(x => x.ModerationItemId == id && x.UserId == UserId); if (review == null) { review = new Review { ModerationItemId = id, Comment = reviewForm.Comment, Status = reviewForm.Status, UserId = UserId, }; _ctx.Add(review); } else { review.Comment = reviewForm.Comment; review.Status = reviewForm.Status; } // todo use configuration replace the magic '3' try { if (modItem.Reviews.Count >= 3) { migrationContext.Migrate(modItem); modItem.Deleted = true; } modItem.Updated = DateTime.UtcNow; await _ctx.SaveChangesAsync(); } catch (VersionMigrationContext.InvalidVersionException e) { return(BadRequest(e.Message)); } return(Ok()); }
public async Task <IActionResult> UpdateReview(string recipeId, [FromBody] ReviewForm review) { var authHeaderContents = Request.Headers["Authorization"]; var accessToken = authHeaderContents.ToString().Split(' ')[1]; var uid = await _authClient.GetUid(accessToken); await _reviewClient.UpdateReview(uid, recipeId, review); return(NoContent()); }
public IActionResult Reviewform(string studentId) { ReviewForm r = new ReviewForm(); r.studentID = HttpContext.Request.Form["id"]; r.teacherName = HttpContext.Request.Form["teacher"]; r.feedback = HttpContext.Request.Form["feedback"]; ReviewDAO.save(r); return(View()); }
public static void EditReview(ReviewForm form) { using (var _context = new DiemServiceDB()) { string caller = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value; Review found = _context.ReviewDbSet.Where(u => u.Id == form.ReviewId).Include(u => u.User).FirstOrDefault(); if (found == null || found.User.Username != caller) { throw new Exception(""); } found.Stars = form.Rating; found.Comment = form.Comment; _context.SaveChanges(); } }
public IActionResult PostReview(ReviewForm form, int bookId) { Review review = new Review(); int id = Convert.ToInt32(Request.Cookies["Id"]); review.UserId = id; User user = db.Users.FirstOrDefault(u => u.Id == id); review.UserName = user.Name; review.Comment = form.Comment; review.Rating = form.Rating; review.BookId = bookId; db.Reviews.Add(review); db.SaveChanges(); return(RedirectToAction("Details", new { Id = bookId })); }
public static void save(ReviewForm r) { string path = @".\reviews.csv"; if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { //adding titles sw.Write("ReviewID,"); sw.Write("StudentID,"); // sw.Write("StudentName,"); // sw.Write("TeacherID,"); sw.Write("TeacherName,"); sw.Write("DateOfReview,"); sw.WriteLine("Feedback"); //adding values sw.Write(r.reviewID + ","); sw.Write(r.studentID + ","); //sw.Write(r.studentName + ","); // sw.Write(r.teacherID + ","); sw.Write(r.teacherName + ","); sw.Write(r.date_of_review + ","); sw.WriteLine(r.feedback); } } else { using (StreamWriter sw = File.AppendText(path)) { sw.Write(r.reviewID + ","); sw.Write(r.studentID + ","); //sw.Write(r.studentName + ","); //sw.Write(r.teacherID + ","); sw.Write(r.teacherName + ","); sw.Write(r.date_of_review + ","); sw.WriteLine(r.feedback); } } }
public static void AddReview(ReviewForm form) { using (var _context = new DiemServiceDB()) { string caller = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value; User found = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault(); FlightReservation wanted = _context.FlightReservationDbSet.Where(u => u.Id == form.ReservationId).Include(u => u.User).Include(u => u.Flight).Include(u => u.Review).FirstOrDefault(); if (wanted == null || wanted.Flight.Flight_Departure_Time.Date > DateTime.Today) { throw new Exception(""); } if (wanted.User.Username != caller) { throw new Exception(""); } wanted.Review = _context.ReviewDbSet.Add(new Review(found, form.Rating, form.Comment)); _context.SaveChanges(); } }
public async Task AddReviewAsync(string userId, string recipeId, ReviewForm reviewForm) { try { Review review = new Review { UserId = userId, RecipeId = recipeId, Content = reviewForm.Content, Rating = reviewForm.Rating, Timestamp = DateTime.Now }; //int? existingRating = await _dbClient.GetUserRatingAsync(userId, recipeId); //if (existingRating == null) //{ // await _dbClient.AddUserRatingAsync(userId, review.RecipeId, review.Rating); //} int existingRating = await _dbClient.GetUserRatingAsync(userId, recipeId); if (existingRating == 0) { await _dbClient.AddUserRatingAsync(userId, review.RecipeId, review.Rating); } else { await _dbClient.UpdateUserRatingAsync(userId, review.RecipeId, review.Rating); } await _dbClient.AddReviewAsync(review); } catch (Exception) { //RollbackAddReview(); throw; } }
public async Task Review(int moderationItemId, string userId, ReviewForm form) { using var scope = _serviceProvider.CreateScope(); var ctx = scope.ServiceProvider.GetRequiredService <AppDbContext>(); var migrationContext = scope.ServiceProvider.GetRequiredService <VersionMigrationContext>(); var setting = _moderationOptionsMonitor.CurrentValue; await _semaphore.WaitAsync(); var modItem = ctx.ModerationItems .Include(mi => mi.Reviews) .FirstOrDefault(x => x.Id == moderationItemId && !x.Deleted); if (modItem == null) { throw new ModerationItemNotFound(); } var review = modItem.Reviews.FirstOrDefault(x => x.UserId == userId); if (review == null) { modItem.Reviews.Add(new Review { Comment = form.Comment, Status = form.Status, UserId = userId, }); } else { review.Comment = form.Comment; review.Status = form.Status; } int goal = setting.GoalCount, score = 0, wait = 0; foreach (var r in modItem.Reviews) { if (r.Status == ReviewStatus.Approved) { score++; } else if (r.Status == ReviewStatus.Rejected) { score--; } else if (r.Status == ReviewStatus.Waiting) { wait++; } } if (score >= goal + wait) { migrationContext.Setup(modItem).Migrate(); modItem.Deleted = true; } else if (score <= -goal - wait) { // todo cleanup target modItem.Deleted = true; modItem.Rejected = true; } modItem.Updated = DateTime.UtcNow; await ctx.SaveChangesAsync(); _semaphore.Release(); }
public HttpResponseMessage EditReview(ReviewForm reviewForm) { ReviewDbManager.EditReview(reviewForm); return(Request.CreateResponse(HttpStatusCode.OK)); }
private void SetBindingContextToReviewForm() { reviewForm = new ReviewForm(); BindingContext = reviewForm; }