Example #1
0
        public void AddSale(Product product, Buyer buyer, History history)
        {
            using (var context = new BlessDiamondContext(_connectionString))
            {
                context.Products.Add(product);
                Buyer b = context.Buyers.FirstOrDefault(i => i.BuyerName == buyer.BuyerName);
                if (b != null)
                {
                    buyer.Id = b.Id;
                }
                else
                {
                    context.Buyers.Add(buyer);
                }
                Sale sale = new Sale
                {
                    DateOfSale = DateTime.Now,
                    BuyerId    = buyer.Id,
                    ProductId  = product.Id
                };
                context.Sales.Add(sale);
                History h = new History
                {
                    Date          = DateTime.Now,
                    Amount        = history.Amount,
                    SaleProductId = product.Id,
                    SaleBuyerId   = buyer.Id
                };
                context.History.Add(h);

                context.SaveChanges();
            }
        }
Example #2
0
 public void AddPayment(int id, decimal amount)
 {
     using (var context = new BlessDiamondContext(_connectionString))
     {
         History h = new History();
         h.Amount        = amount;
         h.Date          = DateTime.Now;
         h.SaleProductId = id;
         context.History.Add(h);
         context.SaveChanges();
     }
 }