public HttpResponseMessage PlaceOrder(PlaceOrderDto placeOrderDto) { var orderRepo = new OrderRepository(); if (placeOrderDto.OrderId == null) { throw new NotImplementedException(); } var getProductQuantity = orderRepo.GetProductQuantity(placeOrderDto.ProductId); if (getProductQuantity.Quantity < placeOrderDto.Quantity) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "You are being greedy...we don't have that many!")); } var addToOrderResult = orderRepo.AddProductToOrder(placeOrderDto); if (addToOrderResult) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Sorry about your luck.")); }
public async Task <IActionResult> PlaceOrder([FromBody] PlaceOrderDto orderToPlace) { var targetUser = _userManager.Users .FirstOrDefault(x => x.Id == orderToPlace.UserId); if (orderToPlace == null || orderToPlace.OrderId <= 0 || targetUser == null) { return(BadRequest("Invalid place order object")); } var orderToUpdate = _repositoryManager.Order.FindAll() .Include(x => x.OrderItems) .FirstOrDefault(x => x.Id == orderToPlace.OrderId); if (orderToUpdate == null || orderToUpdate.OrderItems == null || !orderToUpdate.OrderItems.Any()) { return(BadRequest("Order has no items")); } orderToUpdate.IsFinalized = true; orderToUpdate.TargetUser = targetUser; _repositoryManager.Order.Update(orderToUpdate); await _repositoryManager.SaveAsync(); return(Ok()); }
public async Task <IActionResult> PlaceOrder([FromBody] PlaceOrderDto request) { await bus.Send(new PlaceOrder.Command { CustomerCode = User.CompanyCode(), SuperpowerCode = request.SuperpowerCode, OrderFrom = request.OrderFrom, OrderTo = request.OrderTo }); return(Ok()); }
public bool AddProductToOrder(PlaceOrderDto placeOrderDto) { using (var db = CreateConnection()) { db.Open(); var orderPlaced = db.Execute(@"INSERT into OrderLine (OrderId, ProductId, Quantity) Values (@OrderId, @ProductId, @Quantity)", placeOrderDto); return(orderPlaced == 1); } }
public async Task <IActionResult> PlaceOrder([FromBody] PlaceOrderDto placeOrder) { var orderId = _identityProvider.Next(); await _commandBus.SendAsync(new PlaceOrder { Id = orderId, Value = placeOrder.Value, DiscountCode = placeOrder.DiscountCode }); return(CreatedAtAction(nameof(GetOrder), "orders", new { id = orderId }, null )); }