Ejemplo n.º 1
0
        public ActionResult Index(int?page)
        {
            int pageNumber = (page ?? 1);
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.GetProductQuaTang();
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            KhoQuaTangModel model = new KhoQuaTangModel()
            {
                Products = products.ToPagedList(pageNumber, pageSize)
            };

            return(View("Index", model));
        }
        public JsonResult GetDanhSachYeuThich(List <int> IdYeuThics)
        {
            string listids = string.Join(",", IdYeuThics);
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.LaySanPhamYeuThichs(listids);
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.PromotionCheck promotion = _promotionRepository.GetCurrentPromotion();
            foreach (var sp in products)
            {
                if (promotions.Any())
                {
                    foreach (var pr in promotions)
                    {
                        var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == sp.id_);
                        if (promotionDetail != null)
                        {
                            sp.HasPromotion   = true;
                            sp.PricePromotion = (int)promotionDetail.PriceDiscount;
                            sp.Discount       = (short)promotionDetail.Percent;
                            break;
                        }
                    }
                }
            }
            DanhSach model = new DanhSach()
            {
                DanhSachYeuThichs = products
            };

            TempData["DanhSach"] = model;

            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(int?page)
        {
            int          pageNumber   = (page ?? 1);
            IList <int>  productIds   = new List <int>();
            CookieHelper cookieHelper = new CookieHelper("product_watched");

            if (cookieHelper.GetCookie() != null)
            {
                string json = HttpUtility.UrlDecode(cookieHelper.GetCookie().Values["product_watched"]);
                if (!string.IsNullOrEmpty(json))
                {
                    productIds = json.Split(',').Select(o => Convert.ToInt32(o)).ToList();
                }
            }
            IList <ProductFrontPageMapping.ProductBox> products = new List <ProductFrontPageMapping.ProductBox>();

            if (productIds.Any())
            {
                var allMenus = _menuRepository.GetAllMenuCache();
                products = (from m in allMenus
                            where productIds.Contains(m.id_) && m.idControl == 11 && m.ok && m.HasValue
                            select new ProductFrontPageMapping.ProductBox
                {
                    id_ = m.id_,
                    Img = m.Img,
                    NameProduct =
                        m.NameProduct,
                    PricePro = m.PricePro,
                    Link = m.Link,
                    HasOnHand = m.HasOnHand,
                    NgayHetHang = m.NgayHetHang
                }).Take(9).ToList();
            }
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            DanhSach model = new DanhSach()
            {
                SanPhamTheoDanhMucs = products.ToPagedList(pageNumber, pageSize),
            };

            return(View("DanhSach", model));
        }
Ejemplo n.º 4
0
        public ActionResult SanPhamMoiVeInChiTiet()
        {
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.GetProductNew(5);
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            SanPhamMoiVeModel model = new SanPhamMoiVeModel()
            {
                Products = products,
            };

            return(View("SanPhamMoiVe", model));
        }
        public ActionResult DanhSach(int?page, string linkth)
        {
            int          pageNumber = (page ?? 1);
            int          id         = _menuRepository.GetidDanhMucByLink(linkth);
            IList <Menu> sanPhams   =
                _menuRepository.getSanPhamThuocThuongHieu(linkth).OrderByDescending(o => o.sDate).OrderBy(o => o.SapXepSanPham).Where(o => o.ok && o.HasValue).ToList();
            IList <ProductFrontPageMapping.ProductBox> sanPhamsCuaDanhMuc = new List <ProductFrontPageMapping.ProductBox>();

            //lay duong dan cua san pham
            ViewData["duongdancha"] = _menuRepository.GetTenDanhMucCha(linkth);
            ViewData["duongdancon"] = _menuRepository.GetTenDanhMuc(linkth);
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            foreach (var sanpham in sanPhams)
            {
                ProductFrontPageMapping.ProductBox sp = new ProductFrontPageMapping.ProductBox()
                {
                    Img         = sanpham.Img,
                    NameProduct = sanpham.NameProduct,
                    PricePro    = sanpham.PricePro,
                    id_         = sanpham.id_,
                    Link        = sanpham.Link,
                    HasOnHand   = sanpham.HasOnHand,
                    NgayHetHang = sanpham.NgayHetHang
                };
                #region check promotion
                if (promotions.Any())
                {
                    foreach (var pr in promotions)
                    {
                        var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == sp.id_);
                        if (promotionDetail != null)
                        {
                            sp.HasPromotion   = true;
                            sp.PricePromotion = (int)promotionDetail.PriceDiscount;
                            sp.Discount       = (short)promotionDetail.Percent;
                            break;
                        }
                    }
                }

                #endregion
                sanPhamsCuaDanhMuc.Add(sp);
            }
            DanhSach model = new DanhSach()
            {
                DanhMuc             = _menuRepository.GetById(id),
                SanPhamTheoDanhMucs = sanPhamsCuaDanhMuc.ToPagedList(pageNumber, pageSize),
            };
            return(View(model));
        }
        /// <summary>
        /// Danh sách tag cho sản phẩm
        /// </summary>
        /// <param name="tentag"></param>
        /// <returns></returns>
        public ActionResult DanhSach(string tentag)
        {
            ViewData["tentag"] = tentag.Replace("-", " ");
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.LayTatCaSanphamTheoTag(tentag.Replace("-", " "));
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            DanhSach model = new DanhSach()
            {
                SanPhamTheoTags = products,
                DanhSachTag     = _danhSachTagRepository.GetSeoTag(tentag.Replace("-", " "))
            };

            return(View("DanhSach", model));
        }
        public ActionResult Index()
        {
            IList <CartViewModel.ProductCart> productCarts = new List <CartViewModel.ProductCart>();
            CookieHelper cookieHelper = new CookieHelper("Cart");

            if (cookieHelper.GetCookie() != null)
            {
                string json = HttpUtility.UrlDecode(cookieHelper.GetCookie().Values["Cart"]);
                productCarts = JsonConvert.DeserializeObject <List <CartViewModel.ProductCart> >(json);
            }
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            IList <ProductFrontPageMapping.ProductShowCart> productShowCarts =
                _menuRepository.GetProductShowCartByBarcode(productCarts.Select(o => o.Barcode).ToList());

            IList <CartViewModel.CartItem> cartItems = new List <CartViewModel.CartItem>();
            int         gia       = 0;
            IList <int> productId = new List <int>();

            if (productCarts.Any())
            {
                foreach (var o in productCarts)
                {
                    IList <ProductStockSyncMapping.TonKho> tonKhos = _productStockSyncRepository.GetTonKhoCuaSanPham(o.ProductId);
                    var tonkho = tonKhos.FirstOrDefault(t => t.Barcode.Equals(o.Barcode));
                    var item   = productShowCarts.FirstOrDefault(p => p.Barcode.Equals(o.Barcode));
                    if (item != null)
                    {
                        #region ghép combo < 80K
                        if (item.Price < 80000 && o.Quantity >= 2)
                        {
                            //nếu số lượng > 2  và giá < 80000 bắt đầu tính giá combo
                            int giatru = (item.Price * 10) / 100;
                            gia = item.Price - giatru;
                        }
                        else
                        {
                            gia = item.Price;
                        }
                        #endregion

                        var cartItem = new CartViewModel.CartItem()
                        {
                            ProductId      = o.ProductId,
                            Name           = item.NameProduct,
                            Image          = item.Img,
                            Link           = item.Link,
                            Price          = item.Price,
                            PricePromotion = gia,
                            Barcode        = o.Barcode,
                            Quantity       = o.Quantity <= 0 ? 1 : o.Quantity,
                            AttributeImg   = item.AttributeImg,
                            AttributeName  = item.AttributeName,
                            AttributeFlag  = item.AttributeFlag,
                            Available      = tonkho != null && tonkho.OnHand >= (o.Quantity <= 0 ? 1 : o.Quantity)
                        };

                        #region check promotion
                        if (promotions.Any())
                        {
                            foreach (var pr in promotions)
                            {
                                var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == cartItem.ProductId);
                                if (promotionDetail != null)
                                {
                                    cartItem.HasPromotion   = true;
                                    cartItem.PricePromotion = (int)promotionDetail.PriceDiscount;
                                    cartItem.Discount       = (short)promotionDetail.Percent;
                                    break;
                                }
                            }
                        }
                        #endregion
                        cartItems.Add(cartItem);
                        productId.Add(cartItem.ProductId); // lấy Id để remarketing facebook
                    }
                }
            }
            CartViewModel.CartModel cartModel = new CartViewModel.CartModel()
            {
                CartItems     = cartItems,
                Total         = cartItems.Sum(o => o.Quantity * o.PricePromotion),
                Available     = cartItems.All(o => o.Available),
                ListProductId = productId
            };
            return(View("Index", cartModel));
        }
        public ActionResult Index()
        {
            var allMenus = _menuRepository.GetAllMenuCache();
            //Lấy tất cả danh mục ông nội
            IList <ProductFrontPageMapping.CategoryBoxHomeLv1> categorysAll = allMenus.Any()
                                                                                 ? (from d in
                                                                                    allMenus.Where(
                                                                                        o =>
                                                                                        o.Style ==
                                                                                        "danh-muc-san-pham" &&
                                                                                        o.idControl != 0)
                                                                                    select
                                                                                    new ProductFrontPageMapping.
                                                                                    CategoryBoxHomeLv1
            {
                id_ = d.id_,
                CategoryName =
                    d.NameProduct,
                idControl =
                    d.idControl,
                LevelMenu =
                    d.LevelMenu,
                Link = d.Link,
                IconMenu = d.IconMenu,
                ShowMenuHome =
                    d.ShowMenuHome,
                SapxepDanhMuc =
                    d.SapxepDanhMuc,
                ok = d.ok
            }).ToList()
                                                                                 : new List
                                                                              <
                ProductFrontPageMapping.
                CategoryBoxHomeLv1>();
            // trang điểm, chăm sóc da
            IList <ProductFrontPageMapping.CategoryBoxHomeLv1> Menulevel1 =
                categorysAll.Where(p => p.ok && p.LevelMenu == 1 && p.idControl == 1 && p.id_ != 3351).OrderBy(p => p.SapxepDanhMuc).ToList();

            IList <ProductFrontPageMapping.CategoryBoxHomeChild> childItems = new List <ProductFrontPageMapping.CategoryBoxHomeChild>();

            if (Menulevel1.Any())
            {
                foreach (var boxHomeLv1 in Menulevel1)
                {
                    IList <ProductFrontPageMapping.ProductShow> dataProduct = new List <ProductFrontPageMapping.ProductShow>();
                    childItems.Add(new ProductFrontPageMapping.CategoryBoxHomeChild()
                    {
                        Id       = boxHomeLv1.id_,
                        Link     = boxHomeLv1.Link,
                        Name     = boxHomeLv1.CategoryName,
                        Products = dataProduct
                    });
                }
            }
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.GetProductBestsellerShowHome();
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            SanPhamViewModel.TopSeller model = new SanPhamViewModel.TopSeller()
            {
                MenuAndProducts = childItems,
                Products        = products
            };
            return(View("BestSeller", model));
        }
Ejemplo n.º 9
0
        public ActionResult Index(string linkspamp)
        {
            using (var context = new ShopDataContex())
            {
                context.Database.ExecuteSqlCommand("update Menu set GiaThiTruong = CASE WHEN GiaThiTruong IS NULL OR GiaThiTruong = 0 THEN (ISNULL(PricePro, 0) +(ISNULL(PricePro, 0) * (ABS(Checksum(NewID()) % 10)+ 10)/100)) WHEN GiaThiTruong < PricePro THEN (ISNULL(PricePro, 0) +(ISNULL(PricePro, 0) * (ABS(Checksum(NewID()) % 10)+ 10)/100)) ELSE GiaThiTruong END  where idControl=11 and Link ={0}", linkspamp);
            }
            ProductFrontPageMapping.ProductForViewDetail product = _menuRepository.GetForViewDetailByLink(linkspamp);
            ProductFrontPageMapping.Brand brand = _menuRepository.GetBrandById(product.BrandId);
            product.BrandName = brand != null ? brand.Name : "";

            IList <ProductFrontPageMapping.Attribute> attributes =
                _menuRepository.GetAttributeByProductId(product.ProductId);

            if (!attributes.Any())
            {
                attributes = new List <ProductFrontPageMapping.Attribute>();
            }

            IList <ProductStockSyncMapping.TonKho> tonKhos = _stockSyncRepository.GetTonKhoCuaSanPham(product.ProductId);

            #region lay ton kho trong chi nhanh

            IList <SanPhamViewModel.BranchItem> branchItems = GetBrands();

            if (attributes.Any())
            {
                attributes[0].Selected = true;
                string firstBarcode = attributes[0].Barcode;
                foreach (var b in branchItems)
                {
                    var item = tonKhos.FirstOrDefault(o => o.Barcode.Equals(firstBarcode) && o.Idbranch == b.Id);
                    if (item != null)
                    {
                        b.Quantity = item.OnHand;
                    }
                }
            }
            #endregion

            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            if (promotions.Any())
            {
                foreach (var pr in promotions)
                {
                    var promotionDetail = pr.PromotionDetails.FirstOrDefault(dt => dt.ProductId == product.ProductId);
                    if (promotionDetail != null)
                    {
                        product.HasPromotion   = true;
                        product.PricePromotion = (int)promotionDetail.PriceDiscount;
                        product.Discount       = (short)promotionDetail.Percent;
                        break;
                    }
                }
            }

            var selected = attributes.FirstOrDefault(o => o.Selected);

            SanPhamViewModel.DetailPageViewModel model = new SanPhamViewModel.DetailPageViewModel()
            {
                Product          = product,
                Attributes       = attributes,
                BranchItems      = branchItems,
                ProductAvailable = branchItems.Any(o => o.Quantity > 0),
                CurrentBarcode   = selected != null ? selected.Barcode : "",
                ThietLap         = _ThietLapRepository.GetAll().FirstOrDefault(),
                LuotDanhGia      = _userRatingRepository.GetLuotReView(linkspamp) < 200 ? _userRatingRepository.GetLuotReView(linkspamp) + 200 : _userRatingRepository.GetLuotReView(linkspamp),
                DanhSachTags     = _danhSachTagRepository.GetTenTagViewDetail(linkspamp)
            };


            //chi co admin đăng nhập mới thấy đc số lượng còn hàng
            ShopUser efmvcUser = _httpContext.User.GetShopUser();
            model.IsAdmin = efmvcUser != null && efmvcUser.UserId != 0;

            ViewData["sao"] = _userRatingRepository.GetSao(linkspamp);

            //dung de xai data-src cho hinh anh trong chi tiet
            return(View("Detail", model));
        }
Ejemplo n.º 10
0
        public ActionResult Index()
        {
            //danh sach san pham xem cung duoc code theo thuat toan
            //step 1: lay cookie cua san pham da xem chay for tach ra tung id va luu vao db
            //chu y: lan xem dau tien khong xay ra su kien gi: tuc la khong luu vao db hay update
            IList <int> productIds     = new List <int>();
            IList <int> DanhsachSpGoiY = new List <int>();
            IList <ProductFrontPageMapping.ProductBox> products = new List <ProductFrontPageMapping.ProductBox>();
            CookieHelper cookieHelper = new CookieHelper("product_xemcung");

            if (cookieHelper.GetCookie() != null)
            {
                string json = HttpUtility.UrlDecode(cookieHelper.GetCookie().Values["product_xemcung"]);
                if (!string.IsNullOrEmpty(json))
                {
                    productIds = json.Split(',').Select(o => Convert.ToInt32(o)).ToList();
                }
            }

            if (productIds.Any() && productIds.Count >= 2)
            {
                int idsp = 0, idsptiep = 0;
                //san pham xem dau tien khong xu ly, bat dau xu ly tu san pham thu 2
                for (int i = 0; i < productIds.Count; i++)
                {
                    idsp     = productIds[productIds.Count - 2];
                    idsptiep = productIds[productIds.Count - 1];
                }
                SanPhamXemCung sanPham = new SanPhamXemCung()
                {
                    IdSanPham         = idsp,
                    IdSanPhamTiepTheo = idsptiep,
                    SoLanXem          = 1
                };

                //kiem tra neu nhu idsp cua dong nay = idsp cua dong kia, idsptiep cua dong nay bang idsptiep cua dong kia
                //==> thi update so lan xem len chứ không lưu
                SanPhamXemCung dataXemCung = _phamXemCungRepository.Getdatatrung(idsp, idsptiep);
                int            sltrung = _phamXemCungRepository.GetslTrung(idsp, idsptiep);
                if (sltrung != 0)
                {
                    //neu trung thi update dong do len
                    using (var context = new ShopDataContex())
                    {
                        context.Database.ExecuteSqlCommand("update SanPhamXemCungs set SoLanXem=SoLanXem+1 where SanPhamXemCungId={0}", dataXemCung.SanPhamXemCungId);
                    }
                }
                else
                {
                    //them moi
                    _phamXemCungRepository.Add(sanPham);
                    _unitOfWork.Commit();
                }
                //lay danh sach id cua idsanpham va idsanphamtieptheo kiem tra voi thang idsptiep khi nguoi dung xem
                //neu id duoi DB co chua thang nguoi dung xem thi lay danh sach id theo thuat toan

                DanhsachSpGoiY = _phamXemCungRepository.danhsachIds(idsptiep);
                if (DanhsachSpGoiY.Any())
                {
                    var allMenus = _menuRepository.GetAllMenuCache();
                    products = (from m in allMenus
                                where DanhsachSpGoiY.Contains(m.id_) && m.idControl == 11 && m.ok && m.HasValue
                                select new ProductFrontPageMapping.ProductBox
                    {
                        id_ = m.id_,
                        Img = m.Img,
                        NameProduct = m.NameProduct,
                        PricePro = m.PricePro,
                        Link = m.Link,
                        HasOnHand = m.HasOnHand,
                        NgayHetHang = m.NgayHetHang
                    }).Take(8).ToList();
                }
            }

            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

            PromotionMapping.GetPromotion(promotions, products);
            SanPhamCungXemModel model = new SanPhamCungXemModel()
            {
                Products = products,
            };

            return(View("sanphamxemcung", model));
        }