Beispiel #1
0
        public ActionResult Order()
        {
            if (Session["MaKhachHang"] == null || Session["TenDangNhap"] == null)
            {
                return(RedirectToAction("Signin", "User"));
            }
            if (Session["GioHang"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Chitetdathang p  = new Chitetdathang();
            DATHANG       DH = new DATHANG();
            Khach_Hang    KH = (Khach_Hang)Session["TaiKhoan"];
            List <Cart>   GH = getCart();

            DH.Ma_KhachHang = KH.Ma_Khach_Hang;
            DH.NgayDatHang  = DateTime.Now;
            DH.TenNguoiNhan = KH.HoKH + " " + KH.TenKH;
            if (DH.TenNguoiNhan == null)
            {
                DH.TenNguoiNhan = KH.TenDangNhap;
            }
            DH.SoDienThoai       = Request["Sodienthoai"];
            DH.DiaChiNhan        = Request["DiachiNhan"];
            DH.HinhThucThanhToan = Request["Hinhthucthanhtoan"];
            DH.TriGia            = TongTien();
            dbo.DATHANGs.Add(DH);
            dbo.SaveChanges();
            foreach (var item in GH)
            {
                CTDATHANG CTDH = new CTDATHANG();

                CTDH.SoHD      = item.SoHD;
                CTDH.SoHD      = DH.SoHD;
                CTDH.MaHangHoa = item.Ma_Sach;
                CTDH.SoLuong   = item.SoLuong;
                CTDH.DonGia    = (decimal)item.DonGia;
                CTDH.ThanhTien = (decimal)item.ThanhTien;
                Sach sl = dbo.Saches.Find(item.Ma_Sach);
                sl.SoLuongTon = sl.SoLuongTon - item.SoLuong;
                sl.SoLuongBan = 0;
                sl.SoLuongBan = sl.SoLuongBan + item.SoLuong;
                if (sl.SoLuongTon >= 0)
                {
                    dbo.Entry(sl).State = EntityState.Modified;
                }
                else
                {
                    sl.SoLuongTon       = 0;
                    ViewBag.sltErr      = sl.SoLuongTon;
                    dbo.Entry(sl).State = EntityState.Modified;
                }

                dbo.CTDATHANGs.Add(CTDH);
            }
            dbo.SaveChanges();
            Session["GioHang"] = null;
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public ActionResult Customer(Khach_Hang Khach_Hang, info_costomer p)
        {
            try
            {
                var      b    = Request["Ngaysinh"];
                DateTime date = DateTime.Parse(b);
                p.NgaySinh = date;
            }
            catch
            {
                var x       = "1/1/1990";
                var dateErr = DateTime.Parse(x);
                Khach_Hang.NgaySinh = dateErr;
            }
            var d = Request["Gioitinh"];

            Khach_Hang.Gioi_tinh = d;
            Khach_Hang.NgaySinh  = p.NgaySinh;
            dataMeBookEntities dbo = new dataMeBookEntities();

            dbo.Entry(Khach_Hang).State = System.Data.Entity.EntityState.Modified;
            dbo.SaveChanges();

            return(RedirectToAction("InfomationCustomer", "Customer", new { Ma_Khach_Hang = Khach_Hang.Ma_Khach_Hang }));
        }
Beispiel #3
0
        public ActionResult Edit(Sach sach, HttpPostedFileBase Postfile)
        {
            var i = Request["NXB"];
            var j = Request["NXB"];
            int n = int.Parse(i);
            int m = int.Parse(i);

            sach.Ma_NXB      = n;
            sach.Ma_CD       = n;
            sach.Don_Vi_Tinh = Request["DonViTinh"];
            sach.LoaiBia     = Request["LoaiBia"];
            sach.Loai        = Request["XuatXu"];
            sach.NgayCapNhat = DateTime.Now.Date;
            /***/
            if (Postfile != null)
            {
                var fileName = Path.GetFileName(Postfile.FileName);
                var filePath = Path.Combine(Server.MapPath("~/Content/ImgBook"), fileName);
                if (System.IO.File.Exists(filePath))
                {
                    sach.HinhAnh          = Postfile.FileName;
                    dbo.Entry(sach).State = EntityState.Modified;
                    dbo.SaveChanges();
                }
                else
                {
                    Postfile.SaveAs(filePath);
                    sach.HinhAnh          = Postfile.FileName;
                    dbo.Entry(sach).State = EntityState.Modified;
                    dbo.SaveChanges();
                }
            }
            else
            {
                dbo.Entry(sach).State = EntityState.Modified;
                dbo.SaveChanges();
            }
            /**/
            dbo.Entry(sach).State = EntityState.Modified;
            dbo.SaveChanges();
            return(RedirectToAction("Book"));
        }
Beispiel #4
0
 public ActionResult Edit(Khach_Hang Khach_Hang)
 {
     dbo.Entry(Khach_Hang).State = System.Data.Entity.EntityState.Modified;
     dbo.SaveChanges();
     return(RedirectToAction("KhachHang"));
 }
 public ActionResult test(Khach_Hang Khachang)
 {
     dbo.Entry(Khachang).State = System.Data.Entity.EntityState.Modified;
     dbo.SaveChanges();
     return(Redirect("/"));
 }