Exemplo n.º 1
0
        /// <summary>
        /// qua tang duoc khi chosen-select chon
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public ActionResult QuaTang(int productId)
        {
            var idquatang = _khoQuaTangRepository.Get(o => o.IdMenu == productId).IdSanPhamTang;
            IList <ProductFrontPageMapping.ProductBox>     products   = _menuRepository.GetProductQuaTangByproductId(int.Parse(idquatang));
            IList <PromotionMapping.PromotionCheckProduct> promotions = _promotionRepository.GetActives();

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

            return(View("quatang", model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id) //idsanpham
        {
            IList <ProductGiftSelect> models = new List <ProductGiftSelect>();
            //tu id san pham xún db khoquatangs lay dc idsanpham qua tang va load len
            var         layDlcu   = _khoQuaTangRepository.Get(o => o.IdMenu == id);
            IList <int> idsDaChon = new List <int>();

            if (layDlcu != null && !string.IsNullOrEmpty(layDlcu.IdSanPhamTang))
            {
                idsDaChon = layDlcu.IdSanPhamTang.Split(',').Select(o => Convert.ToInt32(o)).ToList();
            }
            //lay tat ca sp
            IList <Menu> menus = _menuRepository.GetMany(o => o.idControl == 11 && o.ok && o.HasOnHand && o.HasValue)
                                 .ToList();

            foreach (var menu in menus)
            {
                models.Add(new ProductGiftSelect()
                {
                    Name      = menu.NameProduct,
                    ProductId = menu.id_,
                    Selected  = idsDaChon.Contains(menu.id_)
                });
            }
            return(View("Edit", models));
        }
        public ActionResult SaveEdit(SaveProductFormModel model)
        {
            #region san pham
            //SaveProductFormModel
            Menu dlcu = _menuRepository.GetById(model.id_);
            dlcu.NameProduct   = model.NameProduct;
            dlcu.Img           = (model.Img).Replace("/files/", "");
            dlcu.IdNhaCungCap  = model.IdNhaCungCap;
            dlcu.id_           = model.id_;
            dlcu.Option1       = model.Option1;
            dlcu.Option5       = model.Option5;
            dlcu.Option6       = model.Option6;
            dlcu.ContentLabel  = model.ContentLabel;
            dlcu.ContentLabel1 = model.ContentLabel1;
            dlcu.ContentLabel2 = model.ContentLabel2;
            dlcu.ContentLabel3 = model.ContentLabel3;
            dlcu.ContentLabel4 = model.ContentLabel4;
            //dlcu.Content = ChangeImageSEO(model.Content, model.NameProduct, ConvertFont(model.NameProductLong));
            //dlcu.Content1 = ChangeImageSEO1(model.Content1, model.NameProduct, ConvertFont(model.NameProductLong));
            //dlcu.Content2 = ChangeImageSEO2(model.Content2, model.NameProduct, ConvertFont(model.NameProductLong));
            //dlcu.Content3 = ChangeImageSEO3(model.Content3, model.NameProduct, ConvertFont(model.NameProductLong));
            //dlcu.Content4 = ChangeImageSEO4(model.Content4, model.NameProduct, ConvertFont(model.NameProductLong));
            dlcu.Content            = model.Content;
            dlcu.Content1           = model.Content1;
            dlcu.Content2           = model.Content2;
            dlcu.Content3           = model.Content3;
            dlcu.Content4           = model.Content4;
            dlcu.Note               = model.Note;
            dlcu.SapXepSanPham      = model.SapXepSanPham;
            dlcu.sDate              = DateTime.Now;
            dlcu.sDateOk            = DateTime.Now;
            dlcu.ContentLabelTaiSao = model.ContentLabelTaiSao;
            dlcu.ContentTaiSao      = model.ContentTaiSao;
            dlcu.BarCode            = model.BarCode;
            dlcu.ContentTheoSp      = model.ContentTheoSp;
            dlcu.NameProductLong    = model.NameProductLong;
            dlcu.Link               = model.Link; //sửa sản phẩm không sửa tên thành link nữa, cho sửa link trực tiếp
            dlcu.DungSai            = true;
            dlcu.SEOtitle           = model.SEOtitle;
            dlcu.SEODescription     = model.SEODescription;
            dlcu.NguoiTao           = User.Identity.Name;
            dlcu.Bestseller         = false;
            //dlcu.NgayHetHang = DateTime.Now;
            #endregion san pham
            #region hinh anh khac
            //------------- hinh anh khac -----------------


            IList <MenuImageMapping.MenuImage> images = !string.IsNullOrEmpty(model.OtherImages)
                                                       ? JsonConvert.DeserializeObject
                                                        <IList <MenuImageMapping.MenuImage> >(model.OtherImages)
                                                       : new List <MenuImageMapping.MenuImage>();
            foreach (var menuImage in images)
            {
                if (menuImage.id == 0)//them moi hinh anh
                {
                    MenuImage img = new MenuImage()
                    {
                        idMenu    = model.id_,
                        date      = DateTime.Now,
                        ImageName = menuImage.ImageName,
                    };
                    _menuImageRepository.Add(img);
                }
            }
            #endregion hinh anh khac
            #region danh muc

            IList <int> idDanhMucs = !string.IsNullOrEmpty(model.DanhMucIds)
                                        ? JsonConvert.DeserializeObject
                                     <IList <int> >(model.DanhMucIds)
                                        : new List <int>();
            if (model.id_ != 0)
            {
                IList <MenuProAdd> menusDanhMuc = _menuProAddRepository.GetMany(o => o.idMenuProAdded == model.id_).ToList();
                foreach (var menuProAdd in menusDanhMuc)
                {
                    if (!idDanhMucs.Contains(menuProAdd.idMenuCatelogy))
                    {
                        //delete nhung thang khong co trong danh sach idDanhMucs
                        _menuProAddRepository.Delete(menuProAdd);
                        _unitOfWork.Commit();
                    }
                }
                if (idDanhMucs.Any())
                {
                    //lay danh sach menuproadd hien tai cua product

                    foreach (var idDanhMuc in idDanhMucs)
                    {
                        if (!menusDanhMuc.Any(o => o.idMenuCatelogy == idDanhMuc))
                        {
                            MenuProAdd menuProAdd = new MenuProAdd()
                            {
                                idMenuCatelogy = idDanhMuc,
                                idMenuProAdded = model.id_,
                                sDate          = DateTime.Now,
                                sDateOk        = DateTime.Now,
                                Style          = "add-san-pham",
                                idUser         = 15,
                                idUserOk       = 15
                            };
                            _menuProAddRepository.Add(menuProAdd);
                            _unitOfWork.Commit();
                        }
                    }
                }
            }
            else
            {
                if (idDanhMucs.Any())
                {
                    foreach (var idDanhMuc in idDanhMucs)
                    {
                        MenuProAdd menuProAdd = new MenuProAdd()
                        {
                            idMenuCatelogy = idDanhMuc,
                            idMenuProAdded = model.id_,
                            sDate          = DateTime.Now,
                            sDateOk        = DateTime.Now,
                            Style          = "add-san-pham",
                            idUser         = 15,
                            idUserOk       = 15
                        };
                        _menuProAddRepository.Add(menuProAdd);
                        _unitOfWork.Commit();
                    }
                }
            }

            #endregion
            #region danh sach tag
            string[] separators = { "," };
            var      taglist    = model.mySingleField.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            //check null: nếu tồn tại thêm mới bình thường
            if (taglist.Any())
            {
                foreach (var tag in taglist)
                {
                    //check trung
                    int checktrung = _danhSachTagRepository.GetTagNamebyIdmenu(model.id_, tag.Trim());
                    if (checktrung == 0)
                    {
                        DanhSachTag _tag = new DanhSachTag()
                        {
                            NgayTao  = DateTime.Now,
                            IdMenu   = model.id_,
                            NguoiTao = 18,
                            TenTag   = tag.Trim(),
                            Code     = RejectMarks(tag.Trim())
                        };
                        _danhSachTagRepository.Add(_tag);
                    }
                }
            }
            #endregion
            #region update kho quà tặng

            var idkhoqt = _khoQuaTangRepository.Get(o => o.IdMenu == model.id_);
            if (idkhoqt == null)
            {
                //thêm mới
                #region thêm mới kho quà tặng

                if (model.IdQUaTangs != null)
                {
                    KhoQuaTang khoQuaTang = new KhoQuaTang()
                    {
                        IdMenu        = model.id_,
                        NgayTao       = DateTime.Now,
                        IdSanPhamTang = model.IdQUaTangs.Remove(0, 1)
                    };
                    _khoQuaTangRepository.Add(khoQuaTang);
                    _unitOfWork.Commit();
                }

                #endregion
            }
            else
            {
                //update
                KhoQuaTang kho = _khoQuaTangRepository.GetById(idkhoqt.Id);
                kho.Id            = idkhoqt.Id;
                kho.IdMenu        = model.id_;
                kho.NgayTao       = DateTime.Now;
                kho.IdSanPhamTang = model.IdQUaTangs;
                _khoQuaTangRepository.Update(kho);
            }

            #endregion
            _menuRepository.Update(dlcu);

            _menuRepository.ClearCacheByKey(new List <string>()
            {
                Shop.Web.Core.Cache.CacheKey.AllMenu
            });
            _unitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Save(CartViewModel.CartForm form)
        {
            //dien form va luu don hang
            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);
            }

            if (!productCarts.Any())
            {
                return(RedirectToRoute("Cart"));
            }

            #region items
            IList <PromotionMapping.PromotionCheckProduct>  promotions       = _promotionRepository.GetActives();
            IList <ProductFrontPageMapping.ProductShowCart> productShowCarts =
                _menuRepository.GetProductShowCartByBarcode(productCarts.Select(o => o.Barcode).ToList());
            int gia = 0;
            if (!productShowCarts.Any())
            {
                return(RedirectToRoute("Cart"));
            }
            IList <string> ghiChuQT = new List <string>();
            IList <CartViewModel.CartItem> cartItems = new List <CartViewModel.CartItem>();
            if (productCarts.Any())
            {
                foreach (var o in productCarts)
                {
                    var item = productShowCarts.FirstOrDefault(p => p.Barcode.Equals(o.Barcode));

                    if (item == null)
                    {
                        return(RedirectToRoute("Cart"));
                    }
                    #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

                    #region insert sản phẩm quà tặng

                    var quatang = _khoQuaTangRepository.Get(p => p.IdMenu == o.ProductId);
                    if (quatang != null)
                    {
                        int idQT      = Convert.ToInt32(quatang.IdSanPhamTang);
                        var barcodeqt = _menuOptionRepository.Get(p => p.IdMenu == idQT);

                        var productquatang  = _menuRepository.Get(p => p.id_ == idQT);
                        var cartItemquatang = new CartViewModel.CartItem()
                        {
                            ProductId      = productquatang.id_,
                            Name           = productquatang.NameProduct,
                            Image          = productquatang.Img,
                            Price          = productquatang.PricePro.HasValue ? productquatang.PricePro.Value : 0,
                            PricePromotion = productquatang.PricePro.HasValue ? productquatang.PricePro.Value : 0,
                            Barcode        = barcodeqt != null ? barcodeqt.Barcode : "",
                            Quantity       = o.Quantity,
                            AttributeImg   = "",
                            AttributeName  = "",
                            AttributeFlag  = 1,
                            Iquatang       = true
                        };
                        ghiChuQT.Add(productquatang.NameProduct);
                        cartItems.Add(cartItemquatang);
                    }

                    #endregion

                    var cartItem = new CartViewModel.CartItem()
                    {
                        ProductId      = o.ProductId,
                        Name           = item.NameProduct,
                        Image          = item.Img,
                        Price          = item.Price,
                        PricePromotion = gia,
                        Barcode        = o.Barcode,
                        Quantity       = o.Quantity,
                        AttributeImg   = item.AttributeImg,
                        AttributeName  = item.AttributeName,
                        AttributeFlag  = item.AttributeFlag
                    };
                    #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);
                }
            }
            #endregion

            #region order
            DetailMenuComment order = new DetailMenuComment()
            {
                id_Menu        = 9999,
                idBrand        = form.BrandId,
                Name           = form.Name,
                Link           = form.Phone.Trim().TrimEnd().TrimStart(),
                Code           = "Đặt hàng từ Website",
                Content        = form.Note + (ghiChuQT.Any() ? "<span style=\"color: red;font-weight: bold;\"> - Quà tặng</span> " + string.Join(",", ghiChuQT) : ""),
                HuongDanSuDung = form.Email,
                GiaoHang       = form.Address,
                sDate          = DateTime.Now,
                sDateOk        = DateTime.Now
            };
            _detailMenuCommentRepository.Add(order);

            #endregion

            IList <string> str = new List <string>();

            IList <KHLHProduct> khlhProducts = new List <KHLHProduct>();

            #region detail

            foreach (var dt in cartItems)
            {
                DetailMenuCommentItem detail = new DetailMenuCommentItem()
                {
                    id_Menu = order.id_,
                    Name    = dt.Name,
                    Link    = dt.ProductId + "",
                    Price   = dt.Price + "",
                    PriceOf = dt.PricePromotion + "",
                    Content = string.Format("Mã đơn hàng<#{0}#>", order.id_),
                    Number  = dt.Quantity,
                    BarCode = dt.Barcode,
                    sDate   = DateTime.Now,
                    sDateOk = DateTime.Now,
                    Img     = dt.Image
                };
                _detailMenuCommentItemRepository.Add(detail);

                if (!dt.Iquatang)
                {
                    str.Add(string.Format("{0}({1})", dt.Barcode, dt.Quantity));
                }

                khlhProducts.Add(new KHLHProduct()
                {
                    Code      = detail.BarCode,
                    GiaWeb    = int.Parse(detail.PriceOf),
                    NgayTao   = detail.sDate,
                    SL        = dt.Quantity,
                    LinkImage = "https://beautygarden.vn/Upload/Files/" + dt.Image,
                    Quatang   = dt.Iquatang
                });
            }
            #endregion

            #region insert
            string dh = string.Format("{0}#,{1}", order.id_, string.Join(",", str));

            string sql =
                string.Format(
                    "INSERT INTO [bg.hvnet.vn].dbo.KH_LH (NguoiNhap,Nguon,Ten,Phone,DiaChi,GhiChu,idTinh,TrangThai,DonHang,idShop) values (" +
                    " '{0}',{1},N'{2}','{3}',N'{4}',N'{5}',{6},{7},'{8}',{9} " +
                    ")", "system", 1,
                    order.Name,
                    order.Link,
                    order.GiaoHang,
                    order.Content,
                    1,
                    0,
                    dh,
                    order.idBrand
                    );

            int id = _detailMenuCommentRepository.InsertIntoKHLH(sql, order.Link);

            #endregion

            #region
            if (khlhProducts.Any() && id != 0)
            {
                foreach (var khlhProduct in khlhProducts)
                {
                    khlhProduct.IdKH = id;
                }
                _detailMenuCommentRepository.InsertKHLHProduct(khlhProducts);
            }

            #endregion

            _unitOfWork.Commit();
            //sau khi thanh toán thành công thì clear cookie
            cookieHelper.ClearCookie();
            //cookieHelperform.ClearCookie();
            CookieHelper cookieInfo = new CookieHelper("User_Infor");
            string       jsonString = JsonConvert.SerializeObject(new LienHeModel
            {
                GiaoHang       = form.Address,
                HuongDanSuDung = form.Email,
                Link           = form.Phone,
                Name           = form.Name
            });
            cookieInfo.SetUserInforCookie(jsonString);
            return(RedirectToRoute("OrderSuccess", new { id = order.id_ }));
        }