public List <ShoppingCartDto> GetOrderDetail(long orderId)
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var order = (from od in dbContext.OrderDetails
                             join o in dbContext.Orders on od.OrderID equals o.OrderID
                             join p in dbContext.Products on od.ProductID equals p.ProductID
                             where od.OrderID == orderId
                             select new ShoppingCartDto()
                {
                    OrderId = o.OrderID,
                    CustomerId = o.CustomerID,
                    ProductId = p.ProductID,
                    ProductName = p.ProductName,
                    Quantity = od.Quantity,
                    Price = p.Price,
                    TotalPrice = od.Price,
                    Image = p.Image,
                    CustomerName = o.ShipName,
                    Address = o.ShipAddress,
                    Phone = o.ShipMobile,
                    Email = o.ShipEmail,
                    CreatedDate = o.CreatedDate
                }).ToList();

                return(order);
            }
        }
 public List <Order> GetOrder(User user)
 {
     using (var dbContext = new OnlineShoppingSystemEntities())
     {
         return((from o in dbContext.Orders
                 where user.UserID == o.CustomerID
                 select o).ToList());
     }
 }
 public void EditAccount(User user)
 {
     using (var dbContext = new OnlineShoppingSystemEntities())
     {
         var newUser = user;
         newUser.ModifiedDate           = DateTime.Now;
         dbContext.Entry(newUser).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Beispiel #4
0
 public User GetUser(string userName, string password)
 {
     using (var dbContext = new OnlineShoppingSystemEntities())
     {
         var account = (from a in dbContext.Users
                        where a.UserName == userName && a.Password == password
                        select a).FirstOrDefault();
         return(account);
     }
 }
 public List <Product> SearchProduct(string searchKeyword)
 {
     using (var dbContext = new OnlineShoppingSystemEntities())
     {
         var listSearchProduct = (from p in dbContext.Products
                                  where p.ProductName.Contains(searchKeyword) || p.Manufacturer.Equals(searchKeyword)
                                  select p).ToList();
         return(listSearchProduct);
     }
 }
 public void CreateAccount(User user)
 {
     using (var dbContext = new OnlineShoppingSystemEntities())
     {
         var newUser = user;
         newUser.UserID      = GetLastUserId() + 1;
         newUser.Role        = false;
         newUser.CreatedDate = DateTime.Now;
         dbContext.Users.Add(newUser);
         dbContext.SaveChanges();
     }
 }
        public List <Product> GetListProducts()
        {
            List <Product> listProducts = new List <Product>();

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                listProducts = (from p in dbContext.Products
                                select p).ToList();
            }

            return(listProducts);
        }
        public List <Category> GetListCategories()
        {
            List <Category> listCategories = new List <Category>();

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                listCategories = (from c in dbContext.Categories
                                  select c).ToList();
            }

            return(listCategories);
        }
Beispiel #9
0
        public string GetName(User user)
        {
            string name = "";

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                name = (from a in dbContext.Users
                        where a.UserName == user.UserName && a.Password == user.Password
                        select a.Name).FirstOrDefault();
            }

            return(name);
        }
        public Product GetDetailProduct(long productId)
        {
            Product product = new Product();

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                product = (from p in dbContext.Products
                           where p.ProductID == productId
                           select p).FirstOrDefault();
            }

            return(product);
        }
        public List <Product> GetProductsByCategory(long id)
        {
            List <Product> listProducts = new List <Product>();

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                listProducts = (from p in dbContext.Products
                                join c in dbContext.Categories on p.CategoryID equals c.CategoryID
                                where p.CategoryID == id
                                select p).ToList();
            }

            return(listProducts);
        }
        public string GetSpecificCategory(long id)
        {
            string categoryName = "";

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                categoryName = (from p in dbContext.Products
                                join c in dbContext.Categories on p.CategoryID equals c.CategoryID
                                where p.CategoryID == id
                                select c.CategoryName).FirstOrDefault();
            }

            return(categoryName);
        }
        public long GetLastUserId()
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var  listUserId = (from u in dbContext.Users select u.UserID).ToList();
                long lastUserId = 0;
                foreach (var item in listUserId)
                {
                    lastUserId = item;
                }

                return(lastUserId);
            }
        }
Beispiel #14
0
        public bool CheckLogin(User user)
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var account = (from a in dbContext.Users
                               where a.UserName == user.UserName && a.Password == user.Password
                               select a).FirstOrDefault();
                if (account != null)
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool CheckDuplicatedUserName(string username)
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var existedAccount = (from u in dbContext.Users
                                      where u.UserName == username
                                      select u).FirstOrDefault();
                if (existedAccount != null)
                {
                    return(true);
                }

                return(false);
            }
        }
        public List <Product> GetRandomProductByCategory(long id)
        {
            List <Product> listProducts = new List <Product>();

            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                long categoryId = (from p in dbContext.Products
                                   join c in dbContext.Categories on p.CategoryID equals c.CategoryID
                                   where p.ProductID == id
                                   select c.CategoryID).FirstOrDefault();
                listProducts = (from p in dbContext.Products
                                join c in dbContext.Categories on p.CategoryID equals c.CategoryID
                                where p.CategoryID == categoryId && p.ProductID != id
                                select p).OrderBy(x => Guid.NewGuid()).ToList();
            }

            return(listProducts);
        }
        public long GetOrderId()
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var  order   = (from o in dbContext.Orders select o.OrderID).ToList();
                long orderId = 0;
                if (order.Count == 0)
                {
                    return(0);
                }

                foreach (var item in order)
                {
                    orderId = item;
                }

                return(orderId);
            }
        }
        public void AddOrder(List <ShoppingCartDto> cart)
        {
            using (var dbContext = new OnlineShoppingSystemEntities())
            {
                var   tempOrder = (from c in cart select c).Distinct().ToList();
                Order order     = new Order();
                foreach (var item in tempOrder)
                {
                    order.OrderID     = item.OrderId;
                    order.CreatedDate = DateTime.Now;
                    order.CustomerID  = item.CustomerId;
                    order.ShipName    = item.CustomerName;
                    order.ShipAddress = item.Address;
                    order.ShipMobile  = item.Phone;
                    order.ShipEmail   = item.Email;
                }

                dbContext.Orders.Add(order);;
                dbContext.SaveChanges();

                List <OrderDetail> listOrderDetails = new List <OrderDetail>();
                OrderDetail        orderDetail;
                foreach (var item in cart)
                {
                    orderDetail           = new OrderDetail();
                    orderDetail.ProductID = item.ProductId;
                    orderDetail.OrderID   = item.OrderId;
                    orderDetail.Quantity  = item.Quantity;
                    orderDetail.Price     = item.TotalPrice;
                    listOrderDetails.Add(orderDetail);
                }

                foreach (var item in listOrderDetails)
                {
                    dbContext.OrderDetails.Add(item);
                }

                dbContext.SaveChanges();
            }
        }