public async Task <ActionResult <Product_Purchase> > Get(int id)
        {
            Product_Purchase product_purchase = await db.Product_Purchases.FirstOrDefaultAsync(x => x.PurchaseId == id);

            if (product_purchase == null)
            {
                return(NotFound());
            }
            return(new ObjectResult(product_purchase));
        }
        public async Task <ActionResult <Product_Purchase> > Post(Product_Purchase product_purchase)
        {
            if (product_purchase == null)
            {
                return(BadRequest());
            }

            db.Product_Purchases.Add(product_purchase);
            await db.SaveChangesAsync();

            return(Ok(product_purchase));
        }
        public async Task <ActionResult <Product_Purchase> > Delete(int id)
        {
            Product_Purchase product_purchase = db.Product_Purchases.FirstOrDefault(x => x.Id == id);

            if (product_purchase == null)
            {
                return(NotFound());
            }
            db.Product_Purchases.Remove(product_purchase);
            await db.SaveChangesAsync();

            return(Ok(product_purchase));
        }
        public async Task <ActionResult <Product_Purchase> > Put(Product_Purchase product_purchase)
        {
            if (product_purchase == null)
            {
                return(BadRequest());
            }
            if (!db.Product_Purchases.Any(x => x.Id == product_purchase.Id))
            {
                return(NotFound());
            }

            db.Update(product_purchase);
            await db.SaveChangesAsync();

            return(Ok(product_purchase));
        }
        public async Task <ActionResult <Purchase> > Post(Purchase purchase)
        {
            if (purchase == null)
            {
                return(BadRequest());
            }

            db.Purchases.Add(purchase);
            foreach (var item in purchase.LineItems)
            {
                Product_Purchase Toinser = new Product_Purchase {
                    ProductId = item.ProductId, PurchaseId = purchase.PurchaseId
                };
                db.Product_Purchases.Add(Toinser);
            }
            await db.SaveChangesAsync();

            return(Ok(purchase));
        }