Beispiel #1
0
        public static void CreateCheck(Dictionary<int, int> productsInCheck)
        {
            List<Product> allProducts = db.Products.ToList();
            var check = new ChecksRecord();
            decimal priceForAll = 0;

            foreach (var productInCheck in productsInCheck)
            {
                Product product = allProducts.FirstOrDefault(p => p.ProductId == productInCheck.Key);
                ProductsRecord soldProduct = new ProductsRecord { ProductId = productInCheck.Key, Quantity = productInCheck.Value, Price = product.Price * productInCheck.Value };
                db.AddToProductsRecords(soldProduct);
                priceForAll += product.Price * productInCheck.Value;
                check.ProductsRecords.Add(soldProduct);
            }

            DateTime theDate = DateTime.UtcNow;
            check.TimeOfSelling = theDate;
            check.PriceForAll = priceForAll;
            db.AddToChecksRecords(check);

            db.SaveChanges();
        }
 /// <summary>
 /// Create a new ChecksRecord object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="timeOfSelling">Initial value of the TimeOfSelling property.</param>
 /// <param name="priceForAll">Initial value of the PriceForAll property.</param>
 public static ChecksRecord CreateChecksRecord(global::System.Int32 id, global::System.DateTime timeOfSelling, global::System.Decimal priceForAll)
 {
     ChecksRecord checksRecord = new ChecksRecord();
     checksRecord.id = id;
     checksRecord.TimeOfSelling = timeOfSelling;
     checksRecord.PriceForAll = priceForAll;
     return checksRecord;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the ChecksRecords EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToChecksRecords(ChecksRecord checksRecord)
 {
     base.AddObject("ChecksRecords", checksRecord);
 }