public ActionResult Index() { FormOrderSalePage model = new FormOrderSalePage() { Barcode = Request.QueryString.Get("barcode"), Name = "", Note = "", Phone = "", Adress = "" }; return(View("formdathang", model)); }
public ActionResult Submit(FormOrderSalePage model) { // lấy giá và tên sản phẩm từ barcode if (string.IsNullOrEmpty(model.Barcode)) { return(RedirectToAction("Index")); } else { int idsanpham = _menuOptionRepository.Get(o => o.Barcode.Equals(model.Barcode)).IdMenu; Menu sanpham = _menuRepository.Get(o => o.id_ == idsanpham); #region Insert DetailMenuComment DetailMenuComment order = new DetailMenuComment() { id_Menu = 9999, idBrand = 48611, // đẩy hết về Phú Nhuận Name = model.Name, Link = model.Phone.Trim().TrimEnd().TrimStart(), Code = "Đặt hàng từ Website", Content = model.Note, HuongDanSuDung = "", GiaoHang = model.Adress, sDate = DateTime.Now, sDateOk = DateTime.Now }; _detailMenuCommentRepository.Add(order); #endregion IList <string> str = new List <string>(); IList <KHLHProduct> khlhProducts = new List <KHLHProduct>(); DetailMenuCommentItem detail = new DetailMenuCommentItem(); //kiem tra khuyen mai string giakm = ""; PromotionDetail HasSalePage = _promotionDetailRepository.CheckKhuyenMaiSalePage(model.Barcode); if (HasSalePage != null) { // co khuyen mai giakm = HasSalePage.PriceDiscount.ToString(); #region Insert DetailMenuCommentItem // co khuyen mai detail = new DetailMenuCommentItem() { id_Menu = order.id_, Name = sanpham.NameProduct, Link = idsanpham + "", Price = sanpham.PricePro + "", PriceOf = giakm, Content = string.Format("Mã đơn hàng<#{0}#>", order.id_), Number = 1, BarCode = model.Barcode, sDate = DateTime.Now, sDateOk = DateTime.Now, Img = sanpham.Img }; khlhProducts.Add(new KHLHProduct() { Code = detail.BarCode, GiaWeb = int.Parse(detail.PriceOf), NgayTao = detail.sDate, SL = 1, //1 là số lượng sản phẩm đặt hàng LinkImage = "https://beautygarden.vn/Upload/Files/" + sanpham.Img }); } else { // không co khuyen mai detail = new DetailMenuCommentItem() { id_Menu = order.id_, Name = sanpham.NameProduct, Link = idsanpham + "", Price = sanpham.PricePro + "", PriceOf = sanpham.PricePro + "", Content = string.Format("Mã đơn hàng<#{0}#>", order.id_), Number = 1, BarCode = model.Barcode, sDate = DateTime.Now, sDateOk = DateTime.Now, Img = sanpham.Img }; khlhProducts.Add(new KHLHProduct() { Code = detail.BarCode, GiaWeb = int.Parse(detail.PriceOf), NgayTao = detail.sDate, SL = 1, //1 là số lượng sản phẩm đặt hàng LinkImage = "https://beautygarden.vn/Upload/Files/" + sanpham.Img }); } _detailMenuCommentItemRepository.Add(detail); str.Add(string.Format("{0}({1})", model.Barcode, 1)); //1 là số lượng sản phẩm đặt hàng #endregion #region insert KH_LH 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 Insert KH_LH_product if (khlhProducts.Any() && id != 0) { foreach (var khlhProduct in khlhProducts) { khlhProduct.IdKH = id; } _detailMenuCommentRepository.InsertKHLHProduct(khlhProducts); } #endregion _unitOfWork.Commit(); return(RedirectToAction("DatHangThanhCong", new { barcode = model.Barcode })); } }