public IHttpActionResult SaveSale(NewSaleRequestModel request) { Sale sale = new Sale(); sale.InvoiceNo = _service.GetRecordId(); sale.Amount = request.Total; sale.Discount = request.TotalDiscount; sale.Due = request.Due; sale.Profit = request.Profit; sale.DiscountPercent = 0; sale.CustomerId = request.CustomerId; if (request.TotalDiscount > 0) { sale.DiscountPercent = (request.TotalDiscount / request.Total) * 100; } sale.Commint = "N/A"; var savedSale = _service.AddwithReturnId(sale); foreach (var item in request.SalesItem) { SalesDetail salesDetail = new SalesDetail(); salesDetail.Amount = item.Subtotal - (item.Discount * item.Qty); salesDetail.Discount = item.Discount; salesDetail.DiscountPercent = item.DiscountPer; salesDetail.Quantity = item.Qty; salesDetail.ProductId = item.Id; salesDetail.SalesId = savedSale.Id; _salesDetailsService.Add(salesDetail); _productService.DecreaseStock(salesDetail.ProductId, salesDetail.Quantity); } _companyService.AddBalence(savedSale.Amount); return(Ok(savedSale.InvoiceNo)); }