/// <summary> /// Action that lets us update a specific sold product. /// Admin purposes /// </summary> /// <param name="id">id of sold product</param> /// <param name="product">updated sold product</param> /// <returns>Sold product</returns> public async Task <SoldProduct> UpdateSoldProduct(int id, SoldProduct product) { var previousProduct = await _context.SoldProducts.FindAsync(id); if (previousProduct != null) { product.ID = previousProduct.ID; _context.SoldProducts.Update(product); await _context.SaveChangesAsync(); return(product); } return(product); }
/// <summary> /// Action that allows us to create a record of sold items at /// checkout /// </summary> /// <param name="order">Order the items are attached to</param> /// <param name="cartItem">CartItem being recorded</param> /// <returns>StatusCode of Created</returns> public async Task <HttpStatusCode> CreateSoldProduct(Order order, CartItem cartItem) { SoldProduct sold = new SoldProduct { ProductID = cartItem.ProductID, OrderID = order.ID, Quantity = cartItem.Quantity }; await _context.SoldProducts.AddAsync(sold); await _context.SaveChangesAsync(); return(HttpStatusCode.Created); }