public IHttpActionResult SaveNewPurchase(NewPurchaseRequestModel request) { Purchase purchase = new Purchase(); purchase.InvoiceNo = _service.GetRecordId(); purchase.Amount = request.Total; purchase.Comment = "N/A"; var savedPurchase = _service.AddwithReturnId(purchase); foreach (var item in request.PurchaseItem) { PurchaseDetail purchasDetail = new PurchaseDetail(); purchasDetail.Amount = item.Subtotal; purchasDetail.Quantity = item.Qty; purchasDetail.ProductId = item.Id; purchasDetail.PurchaseId = savedPurchase.Id; _purchaseDetailsService.Add(purchasDetail); _productService.IncreaseStock(purchasDetail.ProductId, purchasDetail.Quantity); } _companyService.DeductBalence(savedPurchase.Amount); return(Ok(purchase.InvoiceNo)); }