public ActionResult Submit(LienHeModel luuVao)
        {
            if (!ModelState.IsValid)
            {
                ViewData["message"] = "Vui lòng nhập đầy đủ thông tin!";
                return(View("LienHe"));
            }
            DetailMenuComment lienHe = new DetailMenuComment()
            {
                id_Menu        = 7777,
                sDate          = DateTime.Now,
                sDateOk        = DateTime.Now,
                idControl      = 0,
                Ma_Hang        = "",
                Name           = luuVao.Name,
                Number         = 0,
                ok             = false,
                ShowIconHot    = false,
                ShowIconNew    = false,
                ShowMenu       = false,
                ShowKhuyenMai  = false,
                TinhTrangSP    = false,
                idUser         = 15,
                idUserOk       = 15,
                GiaoHang       = luuVao.GiaoHang,
                HuongDanSuDung = luuVao.HuongDanSuDung,
                Link           = luuVao.Link,
                Content        = luuVao.Content,
                Img            = "",
                sPosition      = 0,
                BanHangChuan   = "",
                BaoHanh        = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36",
                Brochure       = "Desktop",
                Code           = "Liên hệ",
                Diagram        = "171.232.236.109",
                LinkHTTP       = "/lien-he.html",
                Link02         = "https://beautygarden.vn/lien-he.html",
            };

            _detailMenuCommentRepository.Add(lienHe);
            _unitOfWork.Commit();
            //new MailersController().GoiMailLienHe(luuVao).Deliver();
            ViewData["thongbao"] = "Thông tin của bạn đã được ghi nhận, bộ phận Tư Vấn sẽ sớm liên hệ với bạn!";
            CookieHelper cookieHelper = new CookieHelper("User_Infor");
            string       jsonString   = JsonConvert.SerializeObject(new LienHeModel()
            {
                HuongDanSuDung = lienHe.HuongDanSuDung,
                Link           = lienHe.Link,
                Name           = lienHe.Name,
                GiaoHang       = lienHe.GiaoHang
            });

            cookieHelper.SetUserInforCookie(jsonString);
            return(View("LienHe"));
        }
Exemple #2
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_ }));
        }