Beispiel #1
0
 public ActionResult Bill()
 {
     using (DataContext db = new DataContext())
     {
         var cus = (from c in db.Customers
                    join r in db.Roles on c.role equals r.Role_ID
                    where c.Customer_ID == SessionCheckingCustomes.customerID
                    select new
         {
             c.Customer_ID,
             c.customerName,
             c.customerAddress,
             c.customerEmail,
             c.customerPhone
         }).ToList();
         List <CusIndex_ViewModels> customer = new List <CusIndex_ViewModels>();
         foreach (var c in cus)
         {
             CusIndex_ViewModels ci = new CusIndex_ViewModels();
             ci.cus_id     = c.Customer_ID;
             ci.cusName    = c.customerName;
             ci.cusAddress = c.customerAddress;
             ci.cusEmail   = c.customerEmail;
             ci.cusPhone   = c.customerPhone;
             customer.Add(ci);
         }
         return(View(customer));
     }
 }
Beispiel #2
0
 public ActionResult Bill()
 {
     using (DataContext db = new DataContext())
     {
         ViewBag.GetCus = (from b in db.Customers where b.Customer_ID == SessionCheckingCustomes.customerID select b).ToList();
     }
     return(View());
 }
Beispiel #3
0
 //Trang chủ
 public ActionResult Index()
 {
     using (DataContext db = new DataContext())
     {
         ViewBag.GetAllBooks           = (from b in db.Books select b).ToList();
         ViewBag.GetAllBooksSaleOff    = (from b in db.Books where b.statusSaleOff == true select b).ToList();
         ViewBag.GetAllBooksHighlights = (from b in db.Books orderby b.sellNumber descending select b).Take(6).ToList();
     }
     return(View());
 }
Beispiel #4
0
 //Lấy dữ liệu cho partial menu sách nước ngoài
 public PartialViewResult _PartialMenuSachNuocNgoai()
 {
     using (DataContext db = new DataContext())
     {
         List <GetThemeSachNuocNgoai> themes = new List <GetThemeSachNuocNgoai>();
         var chude = (from c in db.ThemeForeigns select c).ToList();
         foreach (var cd in chude)
         {
             GetThemeSachNuocNgoai theme = new GetThemeSachNuocNgoai();
             theme.themeForeignName = cd.ThemeForeignName;
             themes.Add(theme);
         }
         return(PartialView("_PartialMenuSachNuocNgoai", themes));
     }
 }
Beispiel #5
0
 //Lấy dữ liệu cho partial menu sách trong nước
 public PartialViewResult _PartialMenuSachTrongNuoc()
 {
     using (DataContext db = new DataContext())
     {
         List <GetThemeSachTrongNuoc> themes = new List <GetThemeSachTrongNuoc>();
         var chude = (from c in db.Themes select c).ToList();
         foreach (var cd in chude)
         {
             GetThemeSachTrongNuoc theme = new GetThemeSachTrongNuoc();
             theme.themeName = cd.themeName;
             themes.Add(theme);
         }
         return(PartialView("_PartialMenuSachTrongNuoc", themes));
     }
 }
Beispiel #6
0
 public ActionResult BookDetail(int?bid)
 {
     if (bid != null)
     {
         using (DataContext db = new DataContext())
         {
             ViewBag.GetBook = (from b in db.Books where b.Book_ID == bid select b).ToList();
             var get_id_Category = (from b in db.Books join c in db.Categories on b.category_id equals c.Category_ID where b.Book_ID == bid select c.Category_ID).FirstOrDefault();
             ViewBag.GetBookCategory = (from b in db.Books join c in db.Categories on b.category_id equals c.Category_ID where c.Category_ID == get_id_Category select b).ToList();
         }
         return(View());
     }
     else
     {
         return(PartialView("_Partial404NotFound"));
     }
 }
Beispiel #7
0
 public ActionResult BooksInCategory(int?cid)
 {
     if (cid != null)
     {
         using (DataContext db = new DataContext())
         {
             ViewBag.GetAllCategorys = (from c in db.Categories select c).ToList();
             ViewBag.GetBookFromID   = (from b in db.Books
                                        join c in db.Categories
                                        on b.category_id equals c.Category_ID
                                        where b.category_id == cid select b).ToList();
             return(View());
         }
     }
     else
     {
         return(PartialView("_Partial404NotFound"));
     }
 }
Beispiel #8
0
        public ActionResult SuccessView()
        {
            using (DataContext db = new DataContext())
            {
                var bill_id_max = db.Bills.Max(x => x.Bill_ID);
                var bookbill    = (from b in db.Books
                                   join d in db.DetailBills on b.Book_ID equals d.Book_ID
                                   join bi in db.Bills on d.Bill_ID equals bi.Bill_ID
                                   where d.Book_ID == b.Book_ID && d.Bill_ID == bill_id_max
                                   select new
                {
                    b.statusSaleOff,
                    b.saleOffPrice,
                    b.bookName,
                    b.image,
                    d.quantity,
                    b.price,
                    bi.customerName,
                    bi.phoneNumber,
                    bi.total,
                    bi.payment_method
                }).ToList();

                List <DetailBills_ViewModels> detailsBill = new List <DetailBills_ViewModels>();
                foreach (var b in bookbill)
                {
                    DetailBills_ViewModels detailBills = new DetailBills_ViewModels();
                    detailBills.bookName       = b.bookName;
                    detailBills.image          = b.image;
                    detailBills.quantity       = (int)b.quantity;
                    detailBills.price          = b.price;
                    detailBills.customerName   = b.customerName;
                    detailBills.phone          = b.phoneNumber;
                    detailBills.total          = (double)b.total;
                    detailBills.payment_method = (int)b.payment_method;
                    detailBills.saleOffPrice   = b.saleOffPrice;
                    detailBills.statusSaleOff  = b.statusSaleOff;
                    detailsBill.Add(detailBills);
                }

                return(View(detailsBill));
            }
        }
Beispiel #9
0
        public ActionResult UpdateCart(BooksPost bo, FormCollection f)
        {
            using (DataContext db = new DataContext())
            {
                int   quantities = bo.number;
                int[] quantity   = new int[] { quantities };
                var   carts      = (List <Cart_ViewModels>)Session["Cart"];
                Book  book       = db.Books.Where(x => x.Book_ID == bo.book_id).FirstOrDefault();

                for (int i = 0; i < carts.Count; i++)
                {
                    if (quantity[i] > book.quantityExists)
                    {
                        return(Json(new { _mess__ = 0 }));
                    }
                    else
                    {
                        if (quantity[i] <= 0)
                        {
                            carts.Remove(carts[i]);
                        }
                        else
                        {
                            carts[i].number = quantity[i];
                            carts[i].total  = Convert.ToDouble(carts[i].number * carts[i].price);
                        }
                    }
                }

                Session["Cart"] = carts;

                double total = 0;
                foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                {
                    total = total + Math.Round(item.total, 2);
                }
                Session["ThanhTien"] = total;
                return(Json(new { _mess__ = 1 }));
            }
        }
Beispiel #10
0
        public ActionResult UpdateCart(BooksPost quanti, FormCollection f)
        {
            using (DataContext db = new DataContext())
            {
                string[] quantity = f.GetValues("quantity");
                var      carts    = (List <Cart_ViewModels>)Session["Cart"];
                Book     book     = db.Books.Where(x => x.Book_ID == quanti.book_id).FirstOrDefault();

                for (int i = 0; i < carts.Count; i++)
                {
                    if (Convert.ToInt32(quantity[i]) >= quanti.quantityExist)
                    {
                        return(Json(new { quan_check = 1 }));
                    }
                    else
                    {
                        if (Convert.ToInt32(quantity[i]) <= 0)
                        {
                            carts.Remove(carts[i]);
                        }
                        else
                        {
                            carts[i].number = Convert.ToInt32(quantity[i]);
                            carts[i].total  = Convert.ToDouble(carts[i].number * carts[i].price);
                        }
                    }
                }

                Session["Cart"] = carts;

                double total = 0;
                foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                {
                    total = total + item.total;
                }
                Session["ThanhTien"] = total;
                return(View("ViewCart"));
            }
        }
Beispiel #11
0
 public ActionResult Cart(int?bid)
 {
     using (DataContext db = new DataContext())
     {
         if (bid != null)
         {
             Book book = db.Books.Where(x => x.Book_ID == bid).FirstOrDefault();
             if (book.statusSaleOff == true)
             {
                 AddToCart(book.Book_ID, book.bookName, book.saleOffPrice, book.image);
             }
             else
             {
                 AddToCart(book.Book_ID, book.bookName, book.price, book.image);
             }
             return(PartialView("_PartialCart"));
         }
         else
         {
             return(PartialView("_Partial404NotFound"));
         }
     }
 }
Beispiel #12
0
        public ActionResult Bill(BillsPost bi, FormCollection f)
        {
            using (DataContext db = new DataContext())
            {
                if (f["payment"] != null)
                {
                    if (Convert.ToInt32(f["payment"]) == 1)
                    {
                        Bill bills = new Bill();
                        bills.Customer_ID      = SessionCheckingCustomes.customerID;
                        bills.customerName     = f["txtKhachHang"];
                        bills.phoneNumber      = f["txtSoDienThoai"];
                        bills.date_set         = DateTime.Now;
                        bills.customerAddress  = f["txtDiaChi"];
                        bills.total            = (double?)Session["ThanhTien"];
                        bills.payment_method   = Convert.ToInt32(f["payment"]);
                        bills.payment_status   = false;
                        bills.delivered_status = false;
                        db.Bills.Add(bills);
                        db.SaveChanges();
                        var bill_id_max = db.Bills.Max(x => x.Bill_ID);
                        foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                        {
                            DetailBill detailBill = new DetailBill();
                            detailBill.Bill_ID  = bill_id_max;
                            detailBill.Book_ID  = item.book_id;
                            detailBill.quantity = item.number;
                            db.DetailBills.Add(detailBill);
                            db.SaveChanges();
                        }
                        foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                        {
                            Book b = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault();
                            if (b != null)
                            {
                                if (b.sellNumber == null)
                                {
                                    b.sellNumber = item.number;
                                    db.SaveChanges();
                                }
                                else
                                {
                                    b.sellNumber = b.sellNumber + item.number;
                                    db.SaveChanges();
                                }
                            }
                        }
                        foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                        {
                            int? quantityExist = 0;
                            var  quantity      = (from bo in db.Books where bo.Book_ID == item.book_id select new { bo.quantityExists }).ToList();
                            Book b             = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault();
                            foreach (var sl in quantity)
                            {
                                quantityExist = (sl.quantityExists - item.number);
                            }
                            b.quantityExists = quantityExist;
                            db.SaveChanges();
                        }


                        Session["Cart"] = null;
                        return(RedirectToAction("SuccessView"));
                    }
                    else
                    {
                        Bill bills = new Bill();
                        bills.Customer_ID      = SessionCheckingCustomes.customerID;
                        bills.customerName     = f["txtKhachHang"];
                        bills.phoneNumber      = f["txtSoDienThoai"];
                        bills.date_set         = DateTime.Now;
                        bills.customerAddress  = f["txtDiaChi"];
                        bills.total            = (double?)Session["ThanhTien"];
                        bills.payment_method   = Convert.ToInt32(f["payment"]);
                        bills.payment_status   = false;
                        bills.delivered_status = false;
                        db.Bills.Add(bills);
                        db.SaveChanges();
                        var bill_id_max = db.Bills.Max(x => x.Bill_ID);
                        foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                        {
                            DetailBill detailBill = new DetailBill();
                            detailBill.Bill_ID  = bill_id_max;
                            detailBill.Book_ID  = item.book_id;
                            detailBill.quantity = item.number;
                            db.DetailBills.Add(detailBill);
                            db.SaveChanges();
                        }

                        foreach (var item in (List <Cart_ViewModels>)Session["Cart"])
                        {
                            int? quantityExist = 0;
                            var  quantity      = (from bo in db.Books where bo.Book_ID == item.book_id select new { bo.quantityExists }).ToList();
                            Book b             = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault();
                            foreach (var sl in quantity)
                            {
                                quantityExist = (sl.quantityExists - item.number);
                            }
                            b.quantityExists = quantityExist;
                            db.SaveChanges();
                        }
                        return(RedirectToAction("PaymentWithPaypal"));
                    }
                }
                else
                {
                    return(Json(new { _mess__ = 0 }));
                }
            }
        }