public ActionResult ConfirmReturn(int id) { var item = SupplierReturn.Find (id); var qry = from x in item.Details where x.Order.Id == id group x by x.Warehouse into g select new { Warehouse = g.Key, Details = g.ToList () }; var dt = DateTime.Now; var employee = CurrentUser.Employee; using (var scope = new TransactionScope ()) { foreach (var x in qry) { var master = new InventoryIssue { Return = item, Warehouse = x.Warehouse, CreationTime = dt, ModificationTime = dt, Creator = employee, Updater = employee, Comment = string.Format (Resources.Message_SupplierReturn, item.Supplier.Name, item.PurchaseOrder.Id, item.Id) }; master.Create (); foreach (var y in x.Details) { var detail = new InventoryIssueDetail { Issue = master, Product = y.Product, Quantity = y.Quantity, ProductCode = y.ProductCode, ProductName = y.ProductName }; detail.Create (); } } item.IsCompleted = true; item.UpdateAndFlush (); } return RedirectToAction ("Index"); }