예제 #1
0
        public List <Product> getCartItem1(int id)
        {
            List <Product> list = new List <Product>();

            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                var product = db.Products.Where(x => x.Id == id).Select(x => new { x.Id, x.ProductName, x.ProductCategory, x.ProductPrice, x.ProductQuantity, x.ImageUrl, x.Detail }).ToList();
                if (product.Count() > 0)
                {
                    foreach (var i in product)
                    {
                        Product p = new Product();
                        p.Id              = i.Id;
                        p.ProductName     = i.ProductName;
                        p.ProductCategory = i.ProductCategory;
                        p.ProductPrice    = i.ProductPrice;
                        p.ProductQuantity = i.ProductQuantity;
                        p.ImageUrl        = i.ImageUrl;
                        p.Detail          = i.Detail;
                        list.Add(p);
                    }
                    return(list);
                }
            }
            return(null);
        }
예제 #2
0
        public List <User> logIn(User u)
        {
            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                List <User> list = new List <User>();
                var         user = db.Users.Where(x => x.UserName == u.UserName && x.Password == u.Password).Select(x => new { x.Name, x.Password, x.Address, x.Number, x.Email }).ToList();
                if (user.Count() > 0)
                {
                    foreach (var i in user)
                    {
                        User us = new User();
                        us.Name     = i.Name;
                        us.Number   = i.Number;
                        us.Address  = i.Address;
                        us.Email    = i.Email;
                        us.Password = i.Password;
                        us.UserName = u.UserName;
                        list.Add(us);
                    }

                    return(list);
                }
            }
            return(null);
        }
예제 #3
0
        ////////////Get OrederItem From Product/////////////
        public Item getCartItem(int id)
        {
            Item item = new Item();

            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                var product = db.Products.Where(x => x.Id == id).Select(x => new { x.Id, x.ProductName, x.ProductCategory, x.ProductPrice, x.ProductQuantity, x.ImageUrl, x.Detail }).ToList();
                if (product.Count() > 0)
                {
                    foreach (var i in product)
                    {
                        Product p = new Product();
                        p.Id              = i.Id;
                        p.ProductName     = i.ProductName;
                        p.ProductCategory = i.ProductCategory;
                        p.ProductPrice    = i.ProductPrice;
                        p.ProductQuantity = i.ProductQuantity;
                        p.ImageUrl        = i.ImageUrl;
                        item.Product      = p;
                        item.quantity     = 1;
                    }
                    return(item);
                }
            }
            return(null);
        }
예제 #4
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();
                }
            }
        }
예제 #5
0
 public void save(User u)
 {
     using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
     {
         db.Users.Add(u);
         db.SaveChanges();
     }
 }
예제 #6
0
 public Product ProductDetail(int id)
 {
     using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
     {
         Product i = db.Products.Find(id);
         return(i);
     }
 }
예제 #7
0
 public void SaveProduct(Product p)
 {
     using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
     {
         db.Products.Add(p);
         db.SaveChanges();
     }
 }
예제 #8
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();
                }
            }
        }
예제 #9
0
        public User getUser(String user1)
        {
            using (ShoppingDatabaseEntities1 db = new ShoppingDatabaseEntities1())
            {
                var user = db.Users.Where(x => x.UserName == user1).Select(x => new { x.Name, x.Password, x.Address, x.Number, x.Email }).ToList();
                if (user.Count() > 0)
                {
                    User us = new User();
                    foreach (var i in user)
                    {
                        us.Name     = i.Name;
                        us.Number   = i.Number;
                        us.Address  = i.Address;
                        us.Email    = i.Email;
                        us.Password = i.Password;
                        us.UserName = user1;
                    }

                    return(us);
                }
            }
            return(null);
        }