Ejemplo n.º 1
0
        public static List <ProductViewModel> GetListNewProducts()
        {
            List <ProductViewModel> result = new List <ProductViewModel>();
            // Lấy danh sách sản phẩm
            List <SANPHAM> ListNewProducts = null;

            using (var db = new BANDONGHOEntities())
            {
                ListNewProducts = (from sp in db.SANPHAMs
                                   orderby sp.MASP descending
                                   select sp).ToList();
            }

            // Lấy promotion của sản phẩm
            foreach (SANPHAM sp in ListNewProducts)
            {
                int Promotion = PromotionService.GetPromotion(sp.MASP);
                ProductViewModel productViewModel = new ProductViewModel {
                    Product = sp, Promotion = Promotion
                };
                result.Add(productViewModel);
            }

            return(result);
        }
        /// <summary>
        /// Service load tất cả sản phẩm
        /// </summary>
        /// <returns></returns>
        public static List <ProductViewModel> LoadProductAll()
        {
            BANDONGHOEntities       db             = new BANDONGHOEntities();
            List <ProductViewModel> result         = new List <ProductViewModel>();
            IEnumerable <SANPHAM>   LoadProductAll = new List <SANPHAM>();

            LoadProductAll = (from sp in db.SANPHAMs
                              orderby sp.MASP descending
                              select sp);
            // Lấy promotion của sản phẩm
            foreach (SANPHAM sp in LoadProductAll)
            {
                int Promotion = PromotionService.GetPromotion(sp.MASP);
                ProductViewModel productViewModel = new ProductViewModel {
                    Product = sp, Promotion = Promotion
                };
                result.Add(productViewModel);
            }
            return(result);
        }
Ejemplo n.º 3
0
        internal static List <ProductViewModel> GetListProductRelative(int idTrademark)
        {
            List <ProductViewModel> result = new List <ProductViewModel>();
            // Lấy danh sách sản phẩm
            List <SANPHAM> ListProducts = new List <SANPHAM>();

            using (var db = new BANDONGHOEntities())
            {
                ListProducts = (from sp in db.SANPHAMs
                                where sp.MATH == idTrademark
                                orderby sp.MASP descending
                                select sp).ToList();
            }
            foreach (SANPHAM sp in ListProducts)
            {
                int Promotion = PromotionService.GetPromotion(sp.MASP);
                ProductViewModel productViewModel = new ProductViewModel {
                    Product = sp, Promotion = Promotion
                };
                result.Add(productViewModel);
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Tìm kiếm theo tên sản phẩm
        /// </summary>
        public static List <ProductViewModel> Search(string keyword)
        {
            using (var db = new BANDONGHOEntities())
            {
                List <ProductViewModel> result      = new List <ProductViewModel>();
                List <SANPHAM>          listProduct = new List <SANPHAM>();

                listProduct = (from sp in db.SANPHAMs
                               where sp.TENSP.Contains(keyword)
                               select sp).ToList();

                // Lấy promotion của sản phẩm
                foreach (SANPHAM sp in listProduct)
                {
                    int Promotion = PromotionService.GetPromotion(sp.MASP);
                    ProductViewModel productViewModel = new ProductViewModel {
                        Product = sp, Promotion = Promotion
                    };
                    result.Add(productViewModel);
                }
                return(result);
            }
        }