コード例 #1
0
ファイル: CartController.cs プロジェクト: dev-to2k/Boighor
        public ActionResult CheckOut(FormCollection form)
        {
            // Add bill
            DonDatHang  bill     = new DonDatHang();
            KhachHang   customer = (KhachHang)Session["TaiKhoan"];
            List <Cart> cart     = GetCart();

            bill.MaKH   = customer.MaKH;
            bill.NgayDH = DateTime.Now;
            var deliveryDate = String.Format("{0:dd/MM/yyyy}", form["NgayGiao"]);

            bill.NgayGiao          = DateTime.Parse(deliveryDate);
            bill.TinhTrangGiaoHang = false;
            bill.DaThanhToan       = false;
            db.DonDatHangs.Add(bill);
            if (bill.MaKH > 0)
            {
                db.SaveChanges();
            }
            // Add details order
            foreach (var item in cart)
            {
                ChiTietDatHang orderDetails = new ChiTietDatHang();
                orderDetails.SoDH    = bill.SoDH;
                orderDetails.MaSach  = item.maSach;
                orderDetails.SoLuong = item.soLuong;
                orderDetails.DonGia  = (decimal)item.donGia;
                db.ChiTietDatHangs.Add(orderDetails);
            }
            db.SaveChanges();
            Session["Cart"] = null;
            return(RedirectToAction("ConfirmCart", "Cart"));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Ms,Ten_sach,Don_gia,Don_vi_tinh,Mo_ta,Hinh_minh_hoa,Mcd,Mnxb,Ngay_cap_nhat,So_luong_ban,So_lan_xem,so_luong_con")] SACH sACH)
        {
            if (ModelState.IsValid)
            {
                db.SACH.Add(sACH);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Mcd  = new SelectList(db.CHU_DE, "Mcd", "Ten_chu_de", sACH.Mcd);
            ViewBag.Mnxb = new SelectList(db.NHA_XUAT_BAN, "Mnxb", "Ten_nha_xuat_ban", sACH.Mnxb);
            return(View(sACH));
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: dev-to2k/Boighor
 public ActionResult Register(KhachHang customer)
 {
     if (ModelState.IsValid)
     {
         var check = db.KhachHangs.FirstOrDefault(s => s.TaiKhoan == customer.TaiKhoan);
         if (check == null)
         {
             customer.MatKhau = GetMD5(customer.MatKhau);
             db.Configuration.ValidateOnSaveEnabled = false;
             db.KhachHangs.Add(customer);
             db.SaveChanges();
             return(RedirectToAction("SignIn", "User")); // nếu đăng ký thành công
         }
         else
         {
             ViewBag.error = "Username already exists";
             return(View());
         }
     }
     return(View());
 }