public ActionResult Edit([Bind(Include = "BookId,Title,CateId,AuthorId,PubId,Summary,ImgUrl,Price,Quantity,CreatedDate,ModifiedDate,IsActive")] Book sach) { if (ModelState.IsValid) { db.Entry(sach).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sach)); }
public ActionResult GioHang(FormCollection frm, DONDATHANG donhang) { if (Session["makh"] == null) { return(RedirectToAction("Index", "SSO")); } else { int x = int.Parse(Session["makh"].ToString()); var user = db.Users.FirstOrDefault(n => n.MaKH == x); if (user.DiaChi == null || user.DienThoaiKH == null) { user = db.Users.Find(x); { user.DienThoaiKH = frm["dienthoainhanhang"]; user.DiaChi = frm["diachinhanhang"]; }; db.Entry(user); bool am = false; donhang.MaKH = int.Parse(Session["makh"].ToString()); donhang.NgayDH = DateTime.Parse(DateTime.Now.ToString()); //donhang.NgayGiaoHang = DateTime.Parse(frm["ngaynhanhang"].ToString()); donhang.TriGia = decimal.Parse(Session["TongTien"].ToString()); donhang.TrangThai = am; donhang.TenNguoiNhan = frm["tennguoinhan"]; donhang.DienThoaiNhan = int.Parse(frm["dienthoainhanhang"]); donhang.DiaChiNhan = frm["diachinhanhang"]; db.DONDATHANGs.Add(donhang); db.SaveChanges(); List <SamPhamGH> listSP = LayGioHang(); foreach (var item in listSP) { CTDONHANG ctdh = new CTDONHANG(); ctdh.SoDH = donhang.SoHD; ctdh.MaSP = item.BookId; ctdh.SoLuong = item.SoLuongMua; ctdh.DonGia = (decimal)item.Price; db.CTDONHANGs.Add(ctdh); db.SaveChanges(); } Session["GioHang"] = null; return(RedirectToAction("ThanhToanThanhCong", "GioHang")); } else { bool a = false; donhang.MaKH = int.Parse(Session["makh"].ToString()); donhang.NgayDH = DateTime.Parse(DateTime.Now.ToString()); //donhang.NgayGiaoHang = DateTime.Parse(frm["ngaynhanhang"].ToString()); donhang.TriGia = decimal.Parse(Session["TongTien"].ToString()); donhang.TrangThai = a; donhang.TenNguoiNhan = frm["tennguoinhan"]; donhang.DienThoaiNhan = int.Parse(frm["dienthoainhanhang"]); donhang.DiaChiNhan = frm["diachinhanhang"]; db.DONDATHANGs.Add(donhang); db.SaveChanges(); List <SamPhamGH> listSP = LayGioHang(); foreach (var item in listSP) { CTDONHANG ctdh = new CTDONHANG(); ctdh.SoDH = donhang.SoHD; ctdh.MaSP = item.BookId; ctdh.SoLuong = item.SoLuongMua; ctdh.DonGia = (decimal)item.Price; db.CTDONHANGs.Add(ctdh); db.SaveChanges(); } Session["Madh"] = donhang.SoHD; return(RedirectToAction("ThanhToanThanhCong", "GioHang")); } } }