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")); }
public ActionResult signup(signup p)/*DangKy*/ { if (ModelState.IsValid) { var userdao = new UserDAO(); if (userdao.checkUsername(p.Username)) { ModelState.AddModelError(string.Empty, ""); ViewBag.ErrSigupUserName = "******"; } else if (userdao.checkUsername(p.Email)) { ModelState.AddModelError(string.Empty, ""); ViewBag.ErrSigupEmail = "Email đã tồn tại!"; } else { dataMeBookEntities dbo = new dataMeBookEntities(); Khach_Hang a = new Khach_Hang(); a.TenDangNhap = p.Username; a.Email = p.Email; a.MatKhau = Encryptor.MD5Hash(p.Password1); a.DienThoai = p.phone; dbo.Khach_Hang.Add(a); dbo.SaveChanges(); } return(Redirect("/")); } return(View()); }
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 })); }
public ActionResult AddBook(info_Book p, HttpPostedFileBase Postimgbook) { Sach a = new Sach(); a.Ten_Sach = p.TenSach; a.Gia = p.Gia; a.GiaCuaHang = p.GiaCuaHang; var i = Request["NXB"]; var j = Request["ChuDe"]; var k = Request["XuatXu"]; int n = int.Parse(i); int m = int.Parse(j); a.Ma_NXB = n; a.Ma_CD = m; a.Loai = k; a.Don_Vi_Tinh = Request["DonViTinh"]; a.NgayCapNhat = DateTime.Now.Date; a.Mota = Request["Mota"]; a.SoLanXem = p.SolanXem; a.Tac_Gia = p.TacGia; a.SoLuongTon = p.Soluongton; a.LoaiBia = Request["LoaiBia"]; a.SoTrang = p.Sotrang; a.NhaPhanPhoi = p.NhaPhanPhoi; if (Postimgbook != null) { var fileName = Path.GetFileName(Postimgbook.FileName); var filePath = Path.Combine(Server.MapPath("~/Content/ImgBook"), fileName); Postimgbook.SaveAs(filePath); a.HinhAnh = Postimgbook.FileName; dbo.SaveChanges(); } else { dbo.Saches.Add(a); dbo.SaveChanges(); } dbo.Saches.Add(a); dbo.SaveChanges(); return(View()); }
public ActionResult ConfirmDelete(int?SoHD) { DATHANG DH = dbo.DATHANGs.SingleOrDefault(n => n.SoHD == SoHD); List <CTDATHANG> CTDH = dbo.CTDATHANGs.Where(n => n.SoHD == SoHD).ToList(); if (DH == null) { Response.StatusCode = 404; return(null); } foreach (var item in CTDH) { dbo.CTDATHANGs.Remove(item); } dbo.DATHANGs.Remove(DH); dbo.SaveChanges(); return(RedirectToAction("Order")); }
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("/")); }