public ActionResult Edit([Bind(Include = "TheLoaiID,TenTheLoai")] TheLoai theLoai) { if (ModelState.IsValid) { db.Entry(theLoai).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(theLoai)); }
public ActionResult Edit([Bind(Include = "QuocGiaID,TenQuocGia")] QuocGia quocGia) { if (ModelState.IsValid) { db.Entry(quocGia).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quocGia)); }
public ActionResult Edit([Bind(Include = "KhachHangID,TenKhachHang,EmailKhachHang,DiaChi,DienThoai,DiemKhachHang")] KhachHang khachHang) { if (ModelState.IsValid) { db.Entry(khachHang).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(khachHang)); }
public ActionResult Edit([Bind(Include = "NhanVienID,TenNhanVien,EmailNhanVien,MatKhauNhanVien")] NhanVien nhanVien) { if (ModelState.IsValid) { db.Entry(nhanVien).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhanVien)); }
public ActionResult Edit([Bind(Include = "BaiHatID,TenBaiHat,LoiBaiHat,ThoiLuong,AlbumID")] BaiHat baiHat) { if (ModelState.IsValid) { db.Entry(baiHat).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AlbumID = new SelectList(db.Albums, "AlbumID", "TenAlbum", baiHat.AlbumID); return(View(baiHat)); }
public ActionResult DatLai(int?DonHangID) { if (DonHangID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DonHang donHang = db.DonHangs.Find(DonHangID); Album album = new Album(); foreach (var item in donHang.ChiTietDonHangs) { album = item.Album; album.SoLuong -= item.SoLuong; db.Entry(album).State = EntityState.Modified; db.SaveChanges(); } donHang.TrangThaiDonHangID = 1; db.Entry(donHang).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ThongTinDonHang", new { id = DonHangID })); }
public ActionResult Edit([Bind(Include = "TacGiaID,TenTacGia,GioiThieu,NamSinh,NoiSinh")] TacGia tacGia, HttpPostedFileBase HinhAnh) { if (ModelState.IsValid) { if (HinhAnh != null) { var fileName = Path.GetFileName(HinhAnh.FileName); tacGia.HinhAnh = fileName; string path = Path.Combine(Server.MapPath("~/Contents/images/Artist"), fileName); HinhAnh.SaveAs(path); db.Entry(tacGia).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(tacGia)); }
public ActionResult Edit([Bind(Include = "AlbumID,TenAlbum,HinhAnh,NgayPhatHanh,GiaBan,SoLuong,DaBan,DiemDanhGia,XuatXu,PhuKien,TheLoaiID,QuocGiaID,TacGiaID")] Album album, HttpPostedFileBase HinhAnh) { if (ModelState.IsValid) { if (HinhAnh != null) { var fileName = Path.GetFileName(HinhAnh.FileName); album.HinhAnh = fileName; string path = Path.Combine(Server.MapPath("~/Contents/images/album"), fileName); HinhAnh.SaveAs(path); db.Entry(album).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.QuocGiaID = new SelectList(db.QuocGias, "QuocGiaID", "TenQuocGia", album.QuocGiaID); ViewBag.TheLoaiID = new SelectList(db.TheLoais, "TheLoaiID", "TenTheLoai", album.TheLoaiID); ViewBag.TacGiaID = new SelectList(db.TacGias, "TacGiaID", "TenTacGia", album.TacGiaID); return(View(album)); }
public ActionResult PaymentWithPaypal(string Cancel = null) { //getting the apiContext APIContext apiContext = PaypalConfiguration.GetAPIContext(); try { //A resource representing a Payer that funds a payment Payment Method as paypal //Payer Id will be returned when payment proceeds or click to pay string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { //this section will be executed first because PayerID doesn't exist //it is returned by the create function call of the payment class // Creating a payment // baseURL is the url on which paypal sendsback the data. string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Home/PaymentWithPayPal?"; //here we are generating guid for storing the paymentID received in session //which will be used in the payment execution var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid Session.Add(guid, createdPayment.id); return(Redirect(paypalRedirectUrl)); } else { // This function exectues after receving all parameters for the payment var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); //If executed payment failed then we will show payment failure message to user if (executedPayment.state.ToLower() != "approved") { return(View("FailureView")); } } } catch (Exception ex) { return(View("FailureView")); } //on successful payment, show success page to user. Cart cart = Session["Cart"] as Cart; DonHang donHang = (DonHang)TempData["donHang"]; bool fastbuy = Convert.ToBoolean(TempData["fastbuy"]); int id = Convert.ToInt32(TempData["id"]); donHang.NgayDatHang = DateTime.Now; donHang.TrangThaiDonHangID = 1; if (Session["KhachHangID"] == null) { donHang.KhachHangID = null; } else { KhachHang kh = db.KhachHangs.Find(Convert.ToInt32(Session["KhachHangID"])); donHang.KhachHangID = kh.KhachHangID; } int tongtien = 0; float tongtienpaypal = 0; try { if (fastbuy == true) { Cart cart1 = new Cart(); Album album = db.Albums.Find(id); cart1.Add(album); foreach (var item in cart1.Items) { ChiTietDonHang chiTietDonHang = new ChiTietDonHang(); chiTietDonHang.DonHangID = donHang.DonHangID; chiTietDonHang.AlbumID = item._shopping_product.AlbumID; chiTietDonHang.GiaBan = item._shopping_product.GiaBan; chiTietDonHang.SoLuong = item._shopping_quantity; db.ChiTietDonHangs.Add(chiTietDonHang); tongtien += item._shopping_product.GiaBan * item._shopping_quantity; float tempPrice = item._shopping_product.GiaBan / 23000; tongtienpaypal += tempPrice * item._shopping_quantity; } donHang.TongTien = tongtien; db.DonHangs.Add(donHang); donHang.ThuTienPayPal = tongtienpaypal + 2; donHang.TrangThaiThanhToan = "Đã thanh toán qua Paypal"; db.SaveChanges(); foreach (var item in cart1.Items) { Album a = db.Albums.Find(item._shopping_product.AlbumID); a.SoLuong -= item._shopping_quantity; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); } if (donHang.HinhThucThanhToanID == 2) { return(RedirectToAction("Shopping_Success", "Cart")); } } } catch { return(RedirectToAction("CheckOut", new { id = id, fastbuy = fastbuy })); } foreach (var item in cart.Items) { ChiTietDonHang chiTietDonHang = new ChiTietDonHang(); chiTietDonHang.DonHangID = donHang.DonHangID; chiTietDonHang.AlbumID = item._shopping_product.AlbumID; chiTietDonHang.GiaBan = item._shopping_product.GiaBan; chiTietDonHang.SoLuong = item._shopping_quantity; db.ChiTietDonHangs.Add(chiTietDonHang); tongtien += item._shopping_product.GiaBan * item._shopping_quantity; float tempPrice = item._shopping_product.GiaBan / 23000; tongtienpaypal += tempPrice * item._shopping_quantity; } donHang.TongTien = tongtien; donHang.ThuTienPayPal = tongtienpaypal + 2; donHang.TrangThaiThanhToan = "Đã thanh toán qua Paypal"; db.DonHangs.Add(donHang); db.SaveChanges(); foreach (var item in cart.Items) { Album a = db.Albums.Find(item._shopping_product.AlbumID); a.SoLuong -= item._shopping_quantity; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); } cart.ClearCart(); if (Session["KhachHangID"] != null) { int KhachHangID = (int)Session["KhachHangID"]; if (db.GioHangs.Where(x => x.KhachHangID == KhachHangID).FirstOrDefault() != null) { foreach (GioHang item in db.GioHangs.Where(x => x.KhachHangID == KhachHangID).ToList()) { db.GioHangs.Remove(item); } } db.SaveChanges(); } //return View("SuccessView"); return(RedirectToAction("Shopping_Success", "Cart")); }
public ActionResult DoCheckout(DonHang donHang, bool?fastbuy, int?id) { if (ModelState.IsValid) { if (donHang.HinhThucThanhToanID == 2) { TempData["fastbuy"] = fastbuy; TempData["donHang"] = donHang; TempData["id"] = id; return(RedirectToAction("PaymentWithPaypal", "Home")); } Cart cart = Session["Cart"] as Cart; donHang.NgayDatHang = DateTime.Now; donHang.TrangThaiDonHangID = 1; if (Session["KhachHangID"] == null) { donHang.KhachHangID = null; } else { KhachHang kh = db.KhachHangs.Find(Convert.ToInt32(Session["KhachHangID"])); donHang.KhachHangID = kh.KhachHangID; } int tongtien = 0; try { if (fastbuy == true) { Cart cart1 = new Cart(); Album album = db.Albums.Find(id); cart1.Add(album); foreach (var item in cart1.Items) { ChiTietDonHang chiTietDonHang = new ChiTietDonHang(); chiTietDonHang.DonHangID = donHang.DonHangID; chiTietDonHang.AlbumID = item._shopping_product.AlbumID; chiTietDonHang.GiaBan = item._shopping_product.GiaBan; chiTietDonHang.SoLuong = item._shopping_quantity; db.ChiTietDonHangs.Add(chiTietDonHang); tongtien += item._shopping_product.GiaBan * item._shopping_quantity; } donHang.TongTien = tongtien; donHang.TrangThaiThanhToan = "Chưa thanh toán"; db.DonHangs.Add(donHang); db.SaveChanges(); foreach (var item in cart1.Items) { Album a = db.Albums.Find(item._shopping_product.AlbumID); a.SoLuong -= item._shopping_quantity; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); } if (donHang.HinhThucThanhToanID == 1) { return(RedirectToAction("Shopping_Success", "Cart")); } } } catch { return(RedirectToAction("CheckOut", new { id = id, fastbuy = fastbuy })); } foreach (var item in cart.Items) { ChiTietDonHang chiTietDonHang = new ChiTietDonHang(); chiTietDonHang.DonHangID = donHang.DonHangID; chiTietDonHang.AlbumID = item._shopping_product.AlbumID; chiTietDonHang.GiaBan = item._shopping_product.GiaBan; chiTietDonHang.SoLuong = item._shopping_quantity; db.ChiTietDonHangs.Add(chiTietDonHang); tongtien += item._shopping_product.GiaBan * item._shopping_quantity; } donHang.TongTien = tongtien; donHang.TrangThaiThanhToan = "Chưa thanh toán"; db.DonHangs.Add(donHang); db.SaveChanges(); foreach (var item in cart.Items) { Album a = db.Albums.Find(item._shopping_product.AlbumID); a.SoLuong -= item._shopping_quantity; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); } cart.ClearCart(); if (Session["KhachHangID"] != null) { int KhachHangID = (int)Session["KhachHangID"]; if (db.GioHangs.Where(x => x.KhachHangID == KhachHangID).FirstOrDefault() != null) { foreach (GioHang item in db.GioHangs.Where(x => x.KhachHangID == KhachHangID).ToList()) { db.GioHangs.Remove(item); } } db.SaveChanges(); } if (donHang.HinhThucThanhToanID == 1) { return(RedirectToAction("Shopping_Success", "Cart")); } } ViewBag.HinhThucThanhToanID = new SelectList(db.HinhThucThanhToans, "HinhThucThanhToanID", "TenHinhThucThanhToan"); ViewBag.fastbuy = fastbuy; ViewBag.id = id; return(View("CheckOut")); //return RedirectToAction("CheckOut", new { id = id, fastbuy = fastbuy}); }
// GET: Admin/DonHang/Details/5 public ActionResult Details(int?id, int?TrangThaiDonHangID) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DonHang donHang = db.DonHangs.Find(id); if (donHang.TrangThaiDonHangID != TrangThaiDonHangID && TrangThaiDonHangID != null) { ThongBao thongBao = new ThongBao(); thongBao.KhachHangID = donHang.KhachHangID; thongBao.ThoiGian = DateTime.Now; thongBao.DongHangID = id; thongBao.TrangThai = 1; thongBao.TrangThaiDonHangID = TrangThaiDonHangID; db.ThongBaos.Add(thongBao); db.SaveChanges(); } if (TrangThaiDonHangID == 6) { Album album = new Album(); foreach (var item in donHang.ChiTietDonHangs) { album = item.Album; album.SoLuong += item.SoLuong; db.Entry(album).State = EntityState.Modified; db.SaveChanges(); } } if (donHang == null) { return(HttpNotFound()); } if (TrangThaiDonHangID != null && db.TrangThaiDonHangs.Find(TrangThaiDonHangID) != null) { if (TrangThaiDonHangID == 4) { var ctdh = db.ChiTietDonHangs.Where(x => x.DonHangID == donHang.DonHangID).ToList(); var album = db.Albums.ToList(); foreach (var item in ctdh) { foreach (var item1 in album) { if (item1.AlbumID == item.AlbumID) { item1.DaBan += item.SoLuong; db.Entry(item1).State = EntityState.Modified; db.SaveChanges(); } } } if (donHang.TrangThaiThanhToan == "Chưa thanh toán") { donHang.TrangThaiThanhToan = "Đã thanh toán tiền mặt"; } if (donHang.KhachHangID != null) { KhachHang kh = db.KhachHangs.Find(donHang.KhachHangID); decimal diem = donHang.TongTien / 100000; kh.DiemKhachHang += diem; db.Entry(kh).State = EntityState.Modified; db.SaveChanges(); } } donHang.TrangThaiDonHangID = TrangThaiDonHangID; db.Entry(donHang).State = EntityState.Modified; db.SaveChanges(); } ViewBag.tt = donHang.TrangThaiDonHangID; //ViewBag.DonHang = donHang; var chiTietDonHang = db.ChiTietDonHangs.Where(m => m.DonHangID == id); ViewBag.Total = db.ChiTietDonHangs.Sum(m => m.SoLuong * m.GiaBan); ViewBag.TrangThaiDonHangID = new SelectList(db.TrangThaiDonHangs, "TrangThaiDonHangID", "TenTrangThaiDonHang", donHang.TrangThaiDonHangID); return(View(donHang)); }