Ejemplo n.º 1
0
        public void addProd(List <Item> li, string name, double t)
        {
            Order o = new Order();

            o.OrderAmount = li.Count();
            o.OrderPrice  = t;
            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                var user = db.Users.Where(x => x.UserName == name).Select(x => new { x.Id, x.Name, x.Password, x.Address, x.Number, x.Email }).ToList();
                if (user.Count() > 0)
                {
                    User us = new User();
                    foreach (var i in user)
                    {
                        o.UserId = i.Id;
                    }
                }
                db.Orders.Add(o);
                db.SaveChanges();
                int orderid = 0;
                var order   = db.Orders.Where(x => x.UserId == o.UserId).Select(x => new { x.Id }).ToList();
                foreach (var i in order)
                {
                    orderid = i.Id;
                }
                foreach (var i in li)
                {
                    ProductDetail d = new ProductDetail();
                    d.OrderId = orderid;
                    d.ProdId  = i.Product.Id;
                    db.ProductDetails.Add(d);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
 public void save(User u)
 {
     using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
     {
         db.Users.Add(u);
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void SaveProduct(Product p)
 {
     using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
     {
         db.Products.Add(p);
         db.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public void UpdateProduct(Product p)
        {
            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                Product i = db.Products.Find(p.Id);

                if (i != null)
                {
                    //i.Id = p.Id;
                    i.ProductName     = p.ProductName;
                    i.ProductCategory = p.ProductCategory;
                    i.ProductPrice    = p.ProductPrice;
                    i.ProductQuantity = p.ProductQuantity;
                    i.Detail          = p.Detail;
                    db.SaveChanges();
                }
            }
        }