// GET: ShoppingCart public ActionResult Index() { ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; return(View(model)); }
/// <summary> /// 根据指定客户对象的全局唯一标识,获取该客户的购物篮信息。 /// </summary> /// <param name="customerID">用于指代特定客户对象的全局唯一标识。</param> /// <returns>包含了购物篮信息的数据传输对象。</returns> public ShoppingCartModels GetShoppingCart(Guid customerID) { ShoppingCartModels model = new ShoppingCartModels(); var user = userRepository.Get(customerID); var shoppingCart = shoppingCartRepository.FindShoppingCartByUser(user); if (shoppingCart == null) { throw new LException("Customer ID='{0}' doesn't have shopping cart defined.", customerID); } var shoppingCartItems = shoppingCartItemRepository.FindItemsByCart(shoppingCart); if (shoppingCartItems != null && shoppingCartItems.Count() > 0) { foreach (var shoppingCartItem in shoppingCartItems) { model.Items.Add(shoppingCartItem); } model.Subtotal = model.Items.Sum(p => p.LineAmount); } return(model); }
public JsonResult UpdateQuantity(string id, int quantity, int gia) { int tonggia = quantity * gia; var response = new { Code = 1, Msg = "Fail", masp = id, ttien = @Session["TongTien"], tgia = tonggia.ToString("N0") }; DHangModels objCart = (DHangModels)Session["Cart"]; if (objCart != null) { objCart.UpdateQuantity(id, quantity); Session["Cart"] = objCart; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; int ii = 0; int tongtien = 0; foreach (var item2 in model.Cart.ListItem) { tongtien = tongtien + (int)item2.TongCong; ii++; } Session["sluong"] = ii; Session["TongTien"] = tongtien.ToString("N0"); tonggia = quantity * gia; response = new { Code = 0, Msg = "Success", masp = id, ttien = @Session["TongTien"], tgia = tonggia.ToString("N0") }; } return(Json(response)); }
// GET: ProductAction public ActionResult Order() { ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (Carts)Session["Cart"]; return(View(model)); }
public string ThanhToan(string Name, string Email, string SDT, string Adress, string Des) { ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; Order or = new Order(); or.Name = Name; or.Email = Email; or.Date = DateTime.Now; or.SDT = SDT; or.Adress = Adress; or.Des = Des; db.Orders.Add(or); db.SaveChanges(); foreach (var item in model.Cart.ListItem) { OrderDetail det = new OrderDetail(); det.OrderId = or.OrderId; det.ProductId = Convert.ToInt32(item.ProductID); det.ProductName = HttpUtility.UrlEncode(item.ProductName); det.ImgUrl = item.ProductImage; db.OrderDetails.Add(det); db.SaveChanges(); } Session["Cart"] = null; return("Successful"); }
public ActionResult _Cart() { ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; return(PartialView("_Cart", model)); }
public JsonResult RemoveFromCart(string id) { var response = new { Code = 1, Msg = "Fail", masp = id, ttien = @Session["TongTien"] }; DHangModels objCart = (DHangModels)Session["Cart"]; if (objCart != null) { objCart.RemoveFromCart(id); Session["Cart"] = objCart; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; int ii = 0; int tongtien = 0; foreach (var item2 in model.Cart.ListItem) { tongtien = tongtien + (int)item2.TongCong; ii++; } Session["sluong"] = ii; Session["TongTien"] = tongtien.ToString("N0"); response = new { Code = 0, Msg = "Success", masp = id, ttien = @Session["TongTien"] }; } return(Json(response)); }
public ActionResult Index() { ViewBag.Title = "Giỏ hàng"; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; return(View(model)); }
public ActionResult LogOff() { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); cart.DestroyInstance(); Session.Clear(); return(RedirectToAction("Index", "Home")); }
public ActionResult ShoppingCart() { ShoppingCartModels vModel = new ShoppingCartModels(); using (var proxy = this.Service <IOrderService>()) { var model = proxy.GetShoppingCart(UserID); return(View(model)); } }
public void UpdateShoppingCart(ShoppingCartModels shoppingcart) { ShoppingCart dbShoppingCart = dbContext.ShoppingCarts.FirstOrDefault(x => x.ShoppingCartID == shoppingcart.ShoppingCartID); if (dbShoppingCart != null) { dbShoppingCart.ShoppingCartID = shoppingcart.ShoppingCartID; dbShoppingCart.OrderID = shoppingcart.OrderID; dbShoppingCart.ProductCodeID = shoppingcart.ProductCodeID; dbShoppingCart.Quantity = shoppingcart.Quantity; dbShoppingCart.Price = shoppingcart.Price; dbContext.SubmitChanges(); } }
public ActionResult ThanhToan(string ShipAddress, string ShipPhone) { if (Session["TaiKhoan"] == null || Session["TaiKhoan"].ToString() == "") { return(RedirectToAction("Login", "Home")); } int custId = int.Parse(Session["TaiKhoan"].ToString()); var customer = db.Customers.Find(custId); Order order = new Order(); order.CustId = custId; order.OrderDate = DateTime.Now; order.Status = 0; if (ShipAddress == null || ShipAddress == "") { order.ShipAddress = customer.Address; } else { order.ShipAddress = ShipAddress; } if (ShipPhone == null || ShipPhone == "") { order.ShipPhone = customer.PhoneNumber; } else { order.ShipPhone = ShipPhone; } //luu vao bang order db.Orders.Add(order); ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; foreach (var item in model.Cart.ListItem) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderId = order.OrderId; orderDetail.ProductId = item.ProductId; orderDetail.Quantity = item.Quantity; orderDetail.Price = item.Price; db.OrderDetails.Add(orderDetail); } db.SaveChanges(); Session["Cart"] = null; TempData["msg"] = "Thành công"; return(RedirectToAction("Index", "GioHang")); }
public ActionResult OrderDetail(int cityid = 0) { var listLocationDis = ServiceFactory.LocationDiscountManager.GetAllActive(Culture); ViewBag.ListLocationDis = new SelectList(listLocationDis, "LocationDiscountId", "LocationDiscountName"); var listLocations = ServiceFactory.LocationManager.GetAllActiveByParentId(cityid); ViewBag.Locations = new SelectList(listLocations, "LocationId", "LocationName"); ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (Carts)System.Web.HttpContext.Current.Session["Cart"]; return(View(model)); }
private ShoppingCart MapModelToDbObject(ShoppingCartModels shoppingcart) { ShoppingCart dbShoppingCart = new ShoppingCart(); if (shoppingcart != null) { dbShoppingCart.ShoppingCartID = shoppingcart.ShoppingCartID; dbShoppingCart.OrderID = shoppingcart.OrderID; dbShoppingCart.ProductCodeID = shoppingcart.ProductCodeID; dbShoppingCart.Quantity = shoppingcart.Quantity; dbShoppingCart.Price = shoppingcart.Price; return(dbShoppingCart); } return(null); }
private ShoppingCartModels MapDbObjectsToModel(ShoppingCart dbShoppingCart) { ShoppingCartModels shoppingCartModels = new ShoppingCartModels(); if (dbShoppingCart != null) { shoppingCartModels.ShoppingCartID = dbShoppingCart.ShoppingCartID; shoppingCartModels.OrderID = dbShoppingCart.OrderID; shoppingCartModels.ProductCodeID = dbShoppingCart.ProductCodeID; shoppingCartModels.Quantity = dbShoppingCart.Quantity; shoppingCartModels.Price = dbShoppingCart.Price; return(shoppingCartModels); } return(null); }
public ActionResult CheckoutView(string isUser) { if (isUser != null) { UserModel userModel = new UserModel(); return(PartialView("_UserView", userModel)); } else { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); return(PartialView("_ProductView", cart)); } }
//Thanh Toan public ActionResult ThanhToan() { if (Session["TaiKhoan"] == null || Session["TaiKhoan"].ToString() == "") { return(RedirectToAction("Login", "Home")); } ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; int custId = int.Parse(Session["TaiKhoan"].ToString()); var customer = db.Customers.Find(custId); ViewBag.customer = customer; return(View(model)); }
public ActionResult Edit(int id, FormCollection collection) { try { ShoppingCartModels shoppingCartModels = shoppingCartRepository.GetShoppingCartByID(id); UpdateModel(shoppingCartModels); shoppingCartModels.Price = shoppingCartModels.Quantity * productRepository.GetProductById(shoppingCartModels.ProductCodeID).Price; shoppingCartRepository.UpdateShoppingCart(shoppingCartModels); return(RedirectToAction("Index")); } catch { return(View("EditShoppingCart")); } }
public ActionResult ShoppingCartView(string name) { if (name != null) { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); cart.TotalPrice = cart.TotalPrice - cart.ProductsList[name].Price; cart.ProductsList.Remove(name); return(View(cart)); } else { //Save shopping cart code ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); int accountID = Int32.Parse(Session["CurrentID"].ToString()); Order order = Order.ExecuteCreate(accountID, 1, 1, cart.TotalPrice); decimal subtotal = 0; bool isPresent = false; List <Order> orderList = Order.ListByAccountID(accountID); order.Insert(); foreach (Order o in orderList) { List <OrderItem> orderItemList = OrderItem.ListByOrderID(o.ID); foreach (OrderItem item in orderItemList) { item.Delete(); } } foreach (string key in cart.ProductsList.Keys) { Product product = cart.ProductsList[key]; subtotal = subtotal + product.Price; OrderItem orderItem = OrderItem.ExecuteCreate(order.ID, product.ID, 1, product.Price, subtotal); if (!isPresent) { orderItem.Insert(); } } return(View(cart)); } }
public ActionResult Create(int id, FormCollection collection) { try { ProductsModels productsModels = productRepository.GetProductById(id); ShoppingCartModels shoppingCartModel = new ShoppingCartModels(); UpdateModel(shoppingCartModel); shoppingCartModel.OrderID = orderChartRepository.LastOrder(); shoppingCartModel.ProductCodeID = productsModels.ProductCode; shoppingCartModel.Price = productsModels.Price * shoppingCartModel.Quantity; shoppingCartRepository.InsertShoppingCart(shoppingCartModel); return(RedirectToAction("Index")); } catch { return(View("CreateShoppingCart")); } }
public JsonResult AddToCart(string id) { var response = new { Code = 1, Msg = "Fail", sluong = @Session["sluong"], ttien = @Session["TongTien"] }; var db = new SmartShopConnectionDB(); Product sp = db.Single <Product>("select * from Product where MaSP = @0", id); if (sp != null) { DHangModels objCart = (DHangModels)Session["Cart"]; if (objCart == null) { objCart = new DHangModels(); } ShoppingCartItem item = new ShoppingCartItem() { MaSP = sp.MaSP, TenSP = sp.TenSP, Hinh = sp.Hinh, Gia = Int32.Parse(sp.Gia), SoLuong = 1, TongCong = Int32.Parse(sp.Gia), }; objCart.AddToCart(item); Session["Cart"] = objCart; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; int ii = 0; int tongtien = 0; foreach (var item2 in model.Cart.ListItem) { tongtien = tongtien + (int)item2.TongCong; ii++; } Session["sluong"] = ii; Session["TongTien"] = tongtien.ToString("N0"); response = new { Code = 0, Msg = "Success", sluong = @Session["sluong"], ttien = @Session["TongTien"] }; } return(Json(response)); }
public ActionResult Header() { var shoppingCart = ShoppingCart.Instance; var result = new ShoppingCartModels { item_count = shoppingCart.Items.Count, items = shoppingCart.Items.Select(product => new ProductsCartModels { Id = product.ProductItem.Id, Url = url.productURL(product.ProductItem.Name, product.ProductItem.Id), Title = product.ProductItem.Name, Quanity = product.Quantity, Image = product.ProductItem.Avatar, Price = product.ProductItem.Price.ToString("N0") }).ToList(), total_price = shoppingCart.SubTotal }; return(View("Header", result)); }
public ActionResult ProductList(string idField) { int id = Int32.Parse(idField); ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); Product productToBeUpdated = Product.ExecuteCreate(id); int newQuantity = productToBeUpdated.Status + 1; int idfield = Int32.Parse(idField); Product product = Product.ExecuteCreate(productToBeUpdated.CategoryID, productToBeUpdated.Name, productToBeUpdated.Description, productToBeUpdated.Price, productToBeUpdated.ImageName, newQuantity, productToBeUpdated.CreatedAccountID, productToBeUpdated.ModifiedAccountID); cart.AddProductToCart(id); product.Update(idfield, product); return(PartialView("_AddedCorrectlyView")); }
public ActionResult menucart() { ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; ViewBag.dem = 0; int dem = 0; if (model.Cart != null) { foreach (var item in model.Cart.ListItem) { dem++; } } if (dem > 0) { ViewBag.dem = dem; } return(PartialView()); }
public ActionResult ThanhToan(string HoTen, string Email, string DienThoai, string DiaChi, string GhiChu) { try { DonDatHang dh = new DonDatHang(); dh.Username = User.Identity.GetUserName(); dh.HoTen = HoTen; dh.Email = Email; dh.DiaChi = DiaChi; dh.SDT = DienThoai; dh.GhiChu = GhiChu; dh.NgayDatHang = DateTime.Now; //dh.Tongtien = (int)Session["TongTien"]; int tongtien = 0; //CTDH List <ChiTietDH> dsCTDH = new List <ChiTietDH>(); ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (DHangModels)Session["Cart"]; foreach (var item in model.Cart.ListItem) { ChiTietDH ctdh = new ChiTietDH(); ctdh.MaSP = item.MaSP; ctdh.SoLuong = item.SoLuong; ctdh.DonGia = item.Gia.ToString(); ctdh.TongTien = (int)item.TongCong; dsCTDH.Add(ctdh); tongtien = tongtien + (int)item.TongCong; } // dh.Tongtien = tongtien; DonHangBus.Them(dh, dsCTDH, User.Identity.GetUserName()); return(RedirectToAction("Index", "Home")); } catch { return(RedirectToAction("Index", "ShoppingCart")); } }
public void InsertShoppingCart(ShoppingCartModels shoppingcart) { dbContext.ShoppingCarts.InsertOnSubmit(MapModelToDbObject(shoppingcart)); dbContext.SubmitChanges(); }
public ActionResult Order(string CustomerName, string Phone, string Email, string Address, string City, string District, string Message) { var resultEntry = new JsonResultEntry() { Success = false }; int idOrder = 0; int customer = 0; double total = 0; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (Carts)System.Web.HttpContext.Current.Session["Cart"]; var totalMoney = 0; var city = ServiceFactory.LocationDiscountManager.Get(new LocationDiscount { LocationDiscountId = Convert.ToInt32(City) }); var district = ServiceFactory.LocationManager.Get(new Location { LocationId = Convert.ToInt32(District) }); var customerFind = ServiceFactory.CustomerManager.GetByPhone(Phone); if (customerFind == null) { ServiceFactory.CustomerManager.Add(new Customers { Name = CustomerName, Phone = Phone, Email = Email, Address = Address + "," + district.LocationName + ", " + city.LocationDiscountName }); customer = ServiceFactory.CustomerManager.GetLastId(); //Customers customer = ServiceFactory.CustomerManager.GetByPhone(Phone); string strChuoi = "<li>Đơn đặt hàng:</li>"; if (model.Cart != null) { Orders orders = new Orders { CustomerId = customer, Note = Message, IsActive = 0 }; ServiceFactory.OrderManager.Add(orders); idOrder = ServiceFactory.OrderManager.GetLastId(); foreach (var item in model.Cart.ListItem) { OrderDetail orderDetail = new OrderDetail { ProductId = item.ProductId, Quality = item.Quantity, Price = item.Price, OrderId = idOrder }; var product = ServiceFactory.ProductManager.Get(new Product { ProductId = item.ProductId }); Product newPro = ServiceFactory.ProductManager.Get(new Product { ProductId = item.ProductId }); newPro.Quality -= item.Quantity; ServiceFactory.ProductManager.Update(newPro, product); total += (double)item.Price * item.Quantity; ServiceFactory.OrderDetailManager.Add(orderDetail); strChuoi += "<li>Tên sản phẩm: " + item.ProductName + "</li> "; strChuoi += "<li> Giá: " + item.Price.ToString("#,##") + " đ</li> "; strChuoi += "<li> Số lượng: " + item.Quantity + "</li> "; } } var order = ServiceFactory.OrderManager.Get(new Orders { OrderId = idOrder }); var orderNew = ServiceFactory.OrderManager.Get(new Orders { OrderId = idOrder }); orderNew.ToTalMoney = total; ServiceFactory.OrderManager.Update(orderNew, order); strChuoi += "<li>Tổng tiền: " + total.ToString("#,##") + " đ </li>"; SendEmail(Email, strChuoi); System.Web.HttpContext.Current.Session["Cart"] = null; return(Json(new { Success = true, Title = "Đã đặt hàng thành công!", CheckSuccess = "1", strUrl = Url.Action("OrderSuccess", "ProductAction") })); //return RedirectToAction("OrderSuccess", "ProductAction"); } else { string strChuoi = "<li>Đơn đặt hàng:</li>"; if (model.Cart != null) { Orders orders = new Orders { CustomerId = customerFind.CustomerId, Note = Message, IsActive = 0 }; ServiceFactory.OrderManager.Add(orders); idOrder = ServiceFactory.OrderManager.GetLastId(); foreach (var item in model.Cart.ListItem) { OrderDetail orderDetail = new OrderDetail { ProductId = item.ProductId, Quality = item.Quantity, Price = item.Price, OrderId = idOrder }; total += (double)item.Price * item.Quantity; ServiceFactory.OrderDetailManager.Add(orderDetail); var product = ServiceFactory.ProductManager.Get(new Product { ProductId = item.ProductId }); Product newPro = ServiceFactory.ProductManager.Get(new Product { ProductId = item.ProductId }); newPro.Quality -= item.Quantity; ServiceFactory.ProductManager.Update(newPro, product); strChuoi += "<li>Tên sản phẩm: " + item.ProductName + "</li> "; strChuoi += "<li> Giá: " + item.Price.ToString("#,##") + " đ</li> "; strChuoi += "<li> Số lượng: " + item.Quantity + "</li> "; } } var order = ServiceFactory.OrderManager.Get(new Orders { OrderId = idOrder }); var orderNew = ServiceFactory.OrderManager.Get(new Orders { OrderId = idOrder }); orderNew.ToTalMoney = total; ServiceFactory.OrderManager.Update(orderNew, order); strChuoi += "<li>Tổng tiền: " + total.ToString("#,##") + " đ </li>"; SendEmail(Email, strChuoi); System.Web.HttpContext.Current.Session["Cart"] = null; } return(Json(new { Success = true, Title = "Đã đặt hàng thành công!", CheckSuccess = "1", strUrl = Url.Action("OrderSuccess", "ProductAction") })); //return RedirectToAction("OrderDetail", "ProductAction"); }
// GET: ShoppingCart public ActionResult ShoppingCartView() { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); return(View(cart)); }
public ActionResult DatHang() { string strChuoi = ""; decimal total = 0; ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (Carts)Session["Cart"]; if (Session["Account"] == null || Session["Account"].ToString() == "") { //return RedirectToAction("Login", "Account"); return(Json(new { Success = false, Url = Url.Action("Login", "Account") })); } OAccount account = (OAccount)Session["Account"]; OAccount kh = accountService.Get(account.TenDN, account.MatKhau); if (kh == null) { return(Redirect("Error")); } OHoaDonBan ddh = new OHoaDonBan { MaKhach = kh.MaKhach, TrangThai = 0, }; hdbService.Add(ddh); int idHdb = hdbService.GetLastId(); foreach (var item in model.Cart.ListItem) { cTHDBService.Add(new OCTHDB { MaHDB = idHdb, MaSanPham = item.ProductId, SoLuong = item.Quantity, ThanhTien = item.Total, }); strChuoi += "<li> Tên sản phẩm: " + item.ProductName + "</li> "; strChuoi += "<li> Giá: " + item.Price.ToString("#,##") + " đ</li> "; strChuoi += "<li> Số lượng: " + item.Quantity + "</li> "; total += item.Total; var product = sachService.Get(new OSanPham { MaSanPham = item.ProductId }); var newproduct = sachService.Get(new OSanPham { MaSanPham = item.ProductId }); if (product != null) { newproduct.SoLuong = product.SoLuong - item.Quantity; sachService.Update(newproduct); } } strChuoi += "<li>Tổng tiền: " + total.ToString("#,##") + " đ </li>"; SendEmail(kh.Email, strChuoi); Session["Cart"] = null; return(Json(new { Success = true, Message = "Đặt hàng thành công. Bạn hãy check email nhé !" })); }
public ActionResult ThanhToan(HoaDon hoadon, string shipName, string mobile, string address, string email) { ShopEntities shop = new ShopEntities(); ShoppingCartModels model = new ShoppingCartModels(); model.Cart = (ShoppingCart)Session["Cart"]; decimal tong = model.Cart.ListItem.Sum(item => decimal.Parse(item.Price) * item.Quanlity); HoaDon hd = new HoaDon(); hd.TenKH = hoadon.TenKH; hd.GioiTinh = hoadon.GioiTinh; hd.Diachi = hoadon.Diachi; hd.Email = hoadon.Email; hd.SDT = hoadon.SDT; hd.DiaChiGiaoHang = hoadon.DiaChiGiaoHang; hd.ThoiGianGiaoHang = hoadon.ThoiGianGiaoHang; hd.NgayTao = DateTime.Now; hd.TongGia = tong; hd.TrangThai = false; shop.HoaDons.Add(hd); shop.SaveChanges(); KhachHang kh = new KhachHang(); kh.TenKH = hoadon.TenKH; kh.GioiTinh = hoadon.GioiTinh; kh.DiaChi = hoadon.Diachi; kh.Email = hoadon.Email; kh.SDT = hoadon.SDT; shop.KhachHangs.Add(kh); shop.SaveChanges(); var hoaDon = (from h in shop.HoaDons orderby h.MaHoaDon descending select h).FirstOrDefault(); string tam = ""; tam += "<table style='border-collapse:collapse;border:thin solid gray;width:800px'><tr><th style='border:thin solid gray'>TT</th><th style='border:thin solid gray'>Tên sản phẩm</th><th style='border:thin solid gray'>Số lượng</th><th style='border:thin solid gray'>Đơn giá</th><th style='border:thin solid gray'>Thành tiền</th></tr>"; int sott = 1; int tongtien = 0; foreach (var item in model.Cart.ListItem) { ChiTietHoaDon ct = new ChiTietHoaDon(); ct.MaHoaDon = hoaDon.MaHoaDon; ct.MaSanPham = item.ProductID; ct.SoLuong = item.Quanlity; ct.TongGia = decimal.Parse(item.Total.ToString(CultureInfo.InvariantCulture)); shop.ChiTietHoaDons.Add(ct); shop.SaveChanges(); } model.Cart.ListItem.Clear(); double vat = tongtien * 0.1; double thanhtoan1 = tongtien + vat; tam += string.Format("<tr><td colspan=4 style='border:thin solid gray'><b>Tổng </b></td><td align='right' style='border:thin solid gray'>{0:#,##0}</td></tr>", tongtien); tam += string.Format("<tr><td colspan=4 style='border:thin solid gray;color:blue'><b>VAT </b></td><td align='right' style='border:thin solid gray'>{0:#,##0}</td></tr>", vat); tam += string.Format("<tr><td colspan=4 style='border:thin solid gray; color:red'><b>Tổng tiền: </b></td><td align='right' style='border:thin solid gray'>{0:#,##0}</td></tr>", thanhtoan1); //gui email: string senderID = "*****@*****.**"; string senderPassword = "******"; tam += "</table>"; string body = " " + hoadon.TenKH + " Đã được gửi mail từ website cửa kính"; body += "Phone : " + hoadon.SDT + "<br>"; body += "Chi tiết hóa đơn<br>"; body += tam; try { MailMessage mail = new MailMessage(); mail.To.Add(hoadon.Email); mail.From = new MailAddress(senderID); mail.Subject = "Xác nhận hóa đơn hàng công ty cửa HTĐQ"; mail.Body = body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Credentials = new System.Net.NetworkCredential(senderID, senderPassword); smtp.Port = 587; smtp.EnableSsl = true; smtp.Send(mail); } catch (Exception) { } return(View()); }