public async Task <IActionResult> PostProductOrdered([FromBody] ProductOrdered productOrdered) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.ProductsOrdered.Add(productOrdered); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ProductOrderedExists(productOrdered.OrderId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetProductOrdered", new { id = productOrdered.OrderId }, productOrdered)); }
public async Task <IActionResult> PutProductOrdered([FromRoute] Guid id, [FromBody] ProductOrdered productOrdered) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productOrdered.OrderId) { return(BadRequest()); } _context.Entry(productOrdered).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductOrderedExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public OrderDetails(ProductOrdered productOrdered, decimal unitPrice, int amount) { // TODO: Validate parameters. ProductOrdered = productOrdered; UnitPrice = unitPrice; Amount = amount; }
public CommandHandlingResult OrderProduct(string productNumber) { if (this.Status != OrderStatus.InProgress) { return(CommandHandlingResult.Fail("Error: products can only be added to in progress orders.")); } var e = new ProductOrdered(this.OrderNumber, productNumber, GetProductPrice(productNumber)); Handle(e); return(CommandHandlingResult.Success(e)); }
public async Task <Order> CreateOrder(string customerEmail, int deliveryMethodId, string cartId, Address shippingAddress) { var cart = await _cartRepo.GetCustomerCart(cartId); //get items from the product repo var items = new List <OrderItem>(); foreach (var item in cart.CartItems) { var productItem = await _unitOfWork.Repository <Product>().GetById(item.Id); if (productItem != null) { var itemOrdered = new ProductOrdered(productItem.Id, productItem.Name, productItem.ImageUrl); var orderItem = new OrderItem(itemOrdered, productItem.Price, item.Quantity); items.Add(orderItem); } else { throw new ArgumentNullException(productItem.GetType().Name, "product item with Id " + item.Id + " does not exist"); } } // delivery method var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>().GetById(deliveryMethodId); // calc subtotal var subtotal = items.Sum(item => item.Price * item.Quantity); // create order var order = new Order(items, customerEmail, shippingAddress, deliveryMethod, subtotal); _unitOfWork.Repository <Order>().Add(order); // save to db var result = await _unitOfWork.Complete(); if (result <= 0) { return(null); } // delete cart await _cartRepo.DeleteCustomerCart(cartId); return(order); }
private async void Handle(ProductOrdered e) { Console.WriteLine($"Product #{e.ProductNumber} added to order #{e.OrderNumber}."); using (var dbContext = new StoreDBContext()) { var order = dbContext.Orders.FirstOrDefault(o => o.OrderNumber == e.OrderNumber); if (order != null) { order.Products.Add(new OrderedProduct { Id = Guid.NewGuid().ToString("N"), ProductNumber = e.ProductNumber }); await dbContext.SaveChangesAsync(); } } }
public async Task AddCustomerItems(int id, Order order) { // commit each item to the sql file. foreach (var trans in order.Items) { ProductOrdered newItem = new ProductOrdered() { TransactionNumber = id, ProductId = trans.ProductID, Quantity = trans.Quantity }; await _context.AddAsync(newItem); // update inventory var dbInvetory = _context.Inventories.First(i => i.ProductId == trans.ProductID && i.StoreId == order.StoreId); dbInvetory.Quantity -= trans.Quantity; } await _context.SaveChangesAsync(); }
public async Task CreateOrderAsync(int basketId, Address shippingAddress) { var basket = await basketRepository.SelectByIdAsync(basketId); if (basket == null) { return; // TODO: Maybe throw an exception here? } var items = new List <OrderDetails>(); foreach (var item in basket.Details) { var product = await productRepository.SelectByIdAsync(item.ProductId); var productOrdered = new ProductOrdered(product.Id, product.Name, product.PictureUri); var orderDetails = new OrderDetails(productOrdered, item.UnitPrice, item.Quantity); items.Add(orderDetails); } var order = new Order(basket.CustomerId, shippingAddress, items); await orderRepository.AddAsync(order); }
private void Handle(ProductOrdered e) { Products.Add(new OrderedProduct(e.ProductNumber, e.Price)); }
public NotifyCustomerOfPaymentCommand() { Products = new ProductOrdered[0]; }
public OrderSubmittedEvent() { Products = new ProductOrdered[0]; }
public OrderItem(ProductOrdered itemOrdered, decimal price, int quantity) { ItemOrdered = itemOrdered; Price = price; Quantity = quantity; }
public void Update(ProductOrdered entity) { context.Entry(entity).State = EntityState.Modified; }
public void Remove(ProductOrdered entity) { context.ProductOrdered.Remove(entity); }
public void Add(ProductOrdered entity) { context.ProductOrdered.Add(entity); }