public static void CreateSupplyRecord(Dictionary<int, int> productsInSupplyCart) { List<Product> allProducts = db.Products.ToList(); var supplyRecord = new SuppliesRecord(); decimal priceForAll = 0; foreach (var productInCheck in productsInSupplyCart) { Product product = allProducts.FirstOrDefault(p => p.ProductId == productInCheck.Key); ProductsRecord suppliedProduct = new ProductsRecord { ProductId = productInCheck.Key, Quantity = productInCheck.Value, Price = product.SupplierPrice * productInCheck.Value }; db.AddToProductsRecords(suppliedProduct); priceForAll += product.Price * productInCheck.Value; supplyRecord.ProductsRecords.Add(suppliedProduct); } DateTime theDate = DateTime.UtcNow; supplyRecord.TimeOfSupplying = theDate; supplyRecord.PriceForAll = priceForAll; db.AddToSuppliesRecords(supplyRecord); db.SaveChanges(); }
/// <summary> /// Deprecated Method for adding a new object to the SuppliesRecords EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSuppliesRecords(SuppliesRecord suppliesRecord) { base.AddObject("SuppliesRecords", suppliesRecord); }
/// <summary> /// Create a new SuppliesRecord object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="timeOfSupplying">Initial value of the TimeOfSupplying property.</param> /// <param name="priceForAll">Initial value of the PriceForAll property.</param> public static SuppliesRecord CreateSuppliesRecord(global::System.Int32 id, global::System.DateTime timeOfSupplying, global::System.Decimal priceForAll) { SuppliesRecord suppliesRecord = new SuppliesRecord(); suppliesRecord.id = id; suppliesRecord.TimeOfSupplying = timeOfSupplying; suppliesRecord.PriceForAll = priceForAll; return suppliesRecord; }