// GET: Admin/Bill public ActionResult Index(string searchString, int page = 1, int pageSize = 2) { var data = new BillDetailData(); var model = data.ListAllBillDetails(searchString, page, pageSize); ViewBag.Product = new ProductData().ListAll(); ViewBag.SearchString = searchString; return(View(model)); }
public ActionResult AmountProduct() { List <string> productName = new List <string>(); List <int?> product1 = new List <int?>(); List <int?> product2 = new List <int?>(); List <int?> product3 = new List <int?>(); List <int?> product4 = new List <int?>(); List <int?> product5 = new List <int?>(); var model = new BillDetailData().ProductID(); var productList = new ProductData().ListAll(); foreach (var item in model) { foreach (var product in productList) { if (item.productID == product.ProductID) { productName.Add(product.Name); } } } for (int i = 1; i <= 12; i++) { product1.Add(new BillDetailData().GetProductPerMonth(model[0], i)); product2.Add(new BillDetailData().GetProductPerMonth(model[1], i)); product3.Add(new BillDetailData().GetProductPerMonth(model[2], i)); product4.Add(new BillDetailData().GetProductPerMonth(model[3], i)); product5.Add(new BillDetailData().GetProductPerMonth(model[4], i)); } ViewBag.Name = productName; ViewBag.Product1 = product1; ViewBag.Product2 = product2; ViewBag.Product3 = product3; ViewBag.Product4 = product4; ViewBag.Product5 = product5; return(View()); }
public ActionResult Payment(string Address, string CreditCard) { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; var bill_session = (decimal?)Session[CommonConstants.BILL_SESSION]; if (session == null) { return(RedirectToAction("Login", "Login")); } else { if (bill_session != null) { var user = new UserData().GetByID(session.userID); var cart = new CartData().GetByUserID(session.userID); try { var bill = new Bill { UserID = session.userID, CreateDate = DateTime.Now, TotalMoney = bill_session.Value, Status = 0, Address = Address, CreditCard = CreditCard }; //Thêm vào hóa đơn var id = new BillData().insert(bill); if (id != -1) { var list = new List <CartModel>(); if (session == null) { return(RedirectToAction("Login", "Login")); } else { var product = new ProductData().ListAll(); foreach (var temp in cart) { foreach (var item in product) { if (temp.ProductID == item.ProductID) { var model = new CartModel(); model.CartID = temp.CartID; model.UserID = session.userID; model.Product = item; model.Quantity = temp.Quantity; list.Add(model); } } } var detaildata = new BillDetailData(); foreach (var item in list) { var detail = new BillDetail(); detail.BillID = id; detail.ProductID = item.Product.ProductID; detail.Price = item.Product.PromotionPrice; detail.Quantity = item.Quantity; //Thêm vào chi tiết hóa đơn var check = detaildata.insert(detail); if (check == -1) { ViewBag.ThongBao = "Đặt hàng thất bại!"; return(View(cart)); } } try { //Gửi mail var mail = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "ZXCVB@1999"), EnableSsl = true }; DateTime UpdatedTime = bill.CreateDate ?? DateTime.Now; //Tạo email var message = new MailMessage("*****@*****.**", user.Email); //attach message.Subject = "Hóa đơn điện tử"; string htmlString = @"<html> <body> <p>Chào quý khách,</p> <p>Vào " + UpdatedTime.ToString("dddd, dd MMMM yyyy") + " bạn đã mua hàng tại <a href=https://localhost:44377/ >ConvenientStore</a></p>" + "<p>Chân thành cảm ơn quý khách.</p>" + "</body>" + "</html>"; message.IsBodyHtml = true; message.Body = htmlString; mail.Send(message); } catch { } //Xóa hàng khỏi giỏ hàng khi đã mua if (cart != null) { foreach (var item in list) { foreach (var userCart in cart) { if (item.Product.ProductID == userCart.ProductID) { new CartData().Delete(userCart); } } } } Session[CommonConstants.BILL_SESSION] = null; return(Redirect("~/dat-hang/thanh-cong/" + bill.BillID)); } } else { ViewBag.ThongBao = "Đặt hàng thất bại ở bill id!"; return(View()); } } catch (Exception) { ViewBag.ThongBao = "Đặt hàng thất bại ở exception!"; return(View()); } } ViewBag.ThongBao = "Đặt hàng thất bại, đã có lỗi xảy ra"; return(View()); } }