public async Task Consume(ConsumeContext <IAddReviewCommand> context) { var addedReview = await ReviewService.AddNewReview(context.Message.Review); await Console.Out.WriteLineAsync($"Review {addedReview.Id} was added."); await context.Publish(CreateProductRatingUpdatedEvent(ReviewService.GetProductRating(addedReview.ProductId), addedReview.ProductId)); }
public ActionResult OrderNewOrEditing(MenuForUserDTO model) { var user = userService.GetUser(User.Identity.Name); var menu = menuService.GetMenu(model.MenuId); if (model.NewReview != null) { reviewService.AddNewReview(user.Id, model.MenuId, model.NewReview); } decimal money = user.LastScore.Money; var order = orderService.GetUserOrderByDateAndUserId(menu.Date, user.Id); if (order == null && (model.OrderWithFirst != 0 && user.LastScore.Money - model.WithFirst > 0 || model.OrderWithoutFirst != 0 && user.LastScore.Money - model.WithoutFirst > 0)) { var change = model.OrderWithFirst != 0 ? menu.PriceWithFirst : menu.PriceWithoutFirst; if (orderService.AddNewOrder(model, user.Id)) { var id = scoreService.ChangeScoreByUserId(user.Id, user.LastScore.Money - change); userService.SetUserLastScore(user.Id, id.Value); } } else if (order != null && order.Menu.Date > DateTime.Now.AddHours(9) && (order.WithoutFirst != (model.OrderWithoutFirst != 0) || order.WithFirst != (model.OrderWithFirst != 0))) { if (order.WithoutFirst) { money += menu.PriceWithoutFirst; } if (order.WithFirst) { money += menu.PriceWithFirst; } if (model.OrderWithFirst != 0) { money -= menu.PriceWithFirst; } if (model.OrderWithoutFirst != 0) { money -= menu.PriceWithoutFirst; } if (money > 0) { if (orderService.UpdateUserOrder(model, user.Id)) { var newScoreId = scoreService.ChangeScoreByUserId(user.Id, money); userService.SetUserLastScore(user.Id, newScoreId.Value); } } } return(RedirectToAction("Index")); }
public IActionResult AddNewReview(int userId, int bookId, [FromBody] ReviewViewModel newReview) { if (newReview == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(StatusCode(412)); } var review = _reviewService.AddNewReview(bookId, userId, newReview); if (review == null) { return(NotFound()); } return(Ok(review)); }
public IHttpActionResult Post(ReviewDto review) { _reviewService.AddNewReview(review); return(Ok()); }