public ActionResult AddItem(int id, int product) { var p = Product.Find (product); var entity = FiscalDocument.Find (id); int pl = entity.Customer.PriceList.Id; var price = (from x in ProductPrice.Queryable where x.Product.Id == product && x.List.Id == pl select x).SingleOrDefault (); if (entity.IsCompleted || entity.IsCancelled) { Response.StatusCode = 400; return Content (Resources.ItemAlreadyCompletedOrCancelled); } var item = new FiscalDocumentDetail { Document = FiscalDocument.Find (id), Product = p, ProductCode = p.Code, ProductName = p.Name, UnitOfMeasurement = p.UnitOfMeasurement, Discount = 0, TaxRate = p.TaxRate, IsTaxIncluded = p.IsTaxIncluded, Quantity = 1, Price = price.Value, ExchangeRate = entity.ExchangeRate, Currency = entity.Currency }; if (p.Currency != entity.Currency) { item.Price = price.Value * CashHelpers.GetTodayExchangeRate (p.Currency, entity.Currency); } using (var scope = new TransactionScope ()) { item.CreateAndFlush (); } return Json (new { id = item.Id }); }