public async Task AddRating(long id, RatePriceSubmissionModel model) { var priceSubmission = await dbContext.PriceSubmissions.GetAsync(id); var rating = new Entities.PriceSubmissionRating( priceSubmissionId: priceSubmission.Id, userId: userContext.Id.Value, value: model.Value, submitedAt: DateTime.Now); await dbContext.UpsertAsync(new[] { rating }, options => options .SelectValues(x => new object[] { (int)x.Value, x.PriceSubmissionId, $"'{x.SubmitedAt.ToString(CultureInfo.InvariantCulture)}'", x.UserId }) .WithColumns( x => x.Value, x => x.PriceSubmissionId, x => x.SubmitedAt, x => x.UserId ) .ConflictOn( x => x.UserId, x => x.PriceSubmissionId )); }
public async Task NoRatings_Add_RatingIsAddedSuccessfully() { // given var submissionId = await CreatePriceSumission(); // when var ratingModel = new RatePriceSubmissionModel { Value = PriceSubmissionRatingValue.Positive }; await fixture.HttpClient.PutJsonAsync($"{ Routes.PriceSubmissions }/{ submissionId}/rate", ratingModel); // then var submission = await fixture.HttpClient.GetJsonAsync <PriceSubmission>($"{ Routes.PriceSubmissions }/{ submissionId }"); submission.Ratings.Should().ContainSingle().Which.Value.Should().Be(PriceSubmissionRatingValue.Positive); }
public async Task PositiveSubmissionRating_AddPositiveRate_UserRatingIsUnchanged() { // given var submissionId = await CreatePriceSumission(); var positiveRatingModel = new RatePriceSubmissionModel { Value = PriceSubmissionRatingValue.Positive }; await fixture.HttpClient.PutJsonAsync($"{ Routes.PriceSubmissions }/{ submissionId}/rate", positiveRatingModel); // when await fixture.HttpClient.PutJsonAsync($"{ Routes.PriceSubmissions }/{ submissionId}/rate", positiveRatingModel); // then var submission = await fixture.HttpClient.GetJsonAsync <PriceSubmission>($"{ Routes.PriceSubmissions }/{ submissionId }"); submission.Ratings.Should().ContainSingle().Which.Value.Should().Be(PriceSubmissionRatingValue.Positive); }
public async Task <IActionResult> Rate(long id, [FromBody] RatePriceSubmissionModel model) { await priceSubmissionsService.AddRating(id, model); return(NoContent()); }
public Task Rate(long id, RatePriceSubmissionModel model) { return(httpClient.SendJsonAsync(HttpMethod.Put, $"{Route}/{id}/rate", model)); }