public async Task <ApiResponse> addComment([FromForm] ReviewDto dto) { try { //var comment = _mapper.Map<Review>(dto); Review newRe = new Review(); MemoryStream ms = new MemoryStream(); if (dto.Image != null) { dto.Image.CopyTo(ms); newRe.Image = ms.ToArray(); ms.Close(); ms.Dispose(); } newRe.ProductId = dto.ProductId; newRe.UserId = dto.UserId; newRe.Comment = dto.Comment; newRe.Date = DateTime.Now; await _reviewService.AddAsync(newRe); var vm = _mapper.Map <ReviewViewModel>(newRe); return(new ApiResponse("success", vm, 200)); }catch (Exception ex) { return(new ApiResponse($"{ex}", ex, 400)); } }
public async Task <ActionResult> Post([FromBody] AddReviewBindingModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var review = mapper.Map <Services.Dtos.Review>(model); return(this.Ok(await reviewService.AddAsync(review))); }
public async Task <IActionResult> Add([FromBody] AddReviewRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var response = await _reviewService.AddAsync(request); if (!response.IsValid) { return(BadRequest(response.Message)); } return(Ok(response)); }
public async Task HandleAsync(CreateReview command) { Console.WriteLine($"Creating Review: {command.Comment}"); try { await _reviewService.AddAsync(command.Id, command.UserId, command.RestaurantId, command.Comment, command.Rating, command.CreatedAt); await _busClient.PublishAsync(new ReviewCreated(command.Id, command.UserId, command.RestaurantId, command.Comment, command.Rating, command.CreatedAt)); return; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task SeedAsync() { var users = await _userService.BrowseAsync(); if (users.Source.Any()) { return; } var random = new Random(); _logger.LogInformation("Seeding testing data !"); for (var i = 0; i < 10000; i++) { var userId = Guid.NewGuid(); await _userService.RegisterAsync(userId, $"email{i}@gmail.com", $"username{i}", "secret123"); var authorId = Guid.NewGuid(); await _authorService.RegisterAsync(authorId, DataGenerator.GenerateFirstName(), DataGenerator.GenerateFirstName() , DataGenerator.GenerateDescription(), null, DataGenerator.GenerateDate(), null, DataGenerator.GenerateCity(), DataGenerator.GenerateWebsite(), DataGenerator.GenerateWebsite(), userId); var bookId = Guid.NewGuid(); var authorsId = new List <Guid> { authorId }; await _bookService.AddAsync(bookId, DataGenerator.GenerateTitles(), null, DataGenerator.GenerateDescription(), DataGenerator.GenerateRandomIsbn(13), null, 999, DataGenerator.GenerateCity(), DateTime.Now, authorsId, userId); await _reviewService.AddAsync(random.Next(1, 7), DataGenerator.GenerateDescription(), userId, bookId); } for (int i = 0; i < 3; i++) { var adminId = Guid.NewGuid(); await _userService.RegisterAsync(adminId, $"admin{i}@gmail.com", $"admin{i}", "admin123", Role.Admin); var moderatorId = Guid.NewGuid(); await _userService.RegisterAsync(moderatorId, $"moderator{i}@gmail.com", $"moderator{i}", "secret123", Role.Moderator); } }
public async Task <IActionResult> Create([FromBody, CustomizeValidator] ReviewToAdd review, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _reviewService.AddAsync(review, HttpContext.User.Claims.Single(_ => _.Type == "id").Value, cancellationToken); return(result.IsError ? throw new InvalidOperationException(result.Message) : (IActionResult)Ok(result.Data)); } catch (InvalidOperationException ex) { Log.Error(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new CustumResult() { Status = StatusCodes.Status500InternalServerError, Message = ex.Message })); } }
public async Task <IActionResult> Post([FromBody] CreateBookReview command, Guid bookId) { await _reviewService.AddAsync(command.Rating, command.Comment, UserId, bookId); return(Created("", command)); }
public async Task <ActionResult <ReviewViewModel> > CreateReviewAsync([FromQuery] CreateReviewRequest request) { var createdEntity = await _reviewService.AddAsync(request); return(Created(string.Format(CreateEntityPattern, RoutePattern, createdEntity.Id), createdEntity)); }
public async Task <IActionResult> AddOneAsync([FromBody] Review review) { return(ApiOk(await ReviewService.AddAsync(review))); }
public async Task <IActionResult> Add([FromRoute] int id, [FromBody] AddReviewRequestModel model) { SuccessResponseModel result = await _reviewService.AddAsync(User.Identity.Name, id, model); return(Ok(result)); }