//[ValidateAntiForgeryToken] public ActionResult Edit(User user, FormCollection formCollection) { if (Session["UserName"] == null) { return(RedirectToAction("Login", "AccountAdmin")); } string imageURL = null; try { imageURL = formCollection["txtImageURL"].ToString(); } catch { imageURL = "/Content/images/Image.jpg"; } try { if (ModelState.IsValid || user != null) { var dao = new AccountDAO(); var result = dao.Update(user, imageURL); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Profile")); } } catch (DbEntityValidationException e) { throw e; } return(View(user)); }
public ActionResult Edit(Book book, FormCollection formcollection) { string imageURL = null; try { imageURL = formcollection["txtImageURL"].ToString(); } catch { imageURL = "/Content/images/Image.jpg"; } if (ModelState.IsValid) { var dao = new BookDAO(); var rs = dao.Update(book, imageURL); db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ImageBoolID = new SelectList(db.ImageBools, "ImageBoolID", "ImageBoolID", book.ImageBoolID); ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", book.Authors.First().AuthorID); ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", book.PublisherID); return(View(book)); }
public ActionResult Edit(Book book, FormCollection formcollection) { if (Session["UserName"] == null) { return(RedirectToAction("Login", "AccountAdmin")); } string imageURL = null; try { imageURL = formcollection["txtImageURL"].ToString(); } catch { imageURL = "/Content/images/Image.jpg"; } if (ModelState.IsValid) { var dao = new BookDAO(); var rs = dao.Update(book, imageURL); db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ImageBoolID = new SelectList(db.Images, "ImageBoolID", "ImageBoolID", book.ImageBoolID); //ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", book.Authors.First().AuthorID); //ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", book.PublisherID); ViewBag.AuthorID = new SelectList(db.Authors.Where(x => x.isDeleted == false), "AuthorID", "Name"); ViewBag.CategoryID = new SelectList(db.Categories.Where(x => x.isDeleted == false), "CategoryID", "Name"); ViewBag.PublisherID = new SelectList(db.Publishers.Where(x => x.isDeleted == false), "PublisherID", "Name"); return(View(book)); }
public async Task <ActionResult> PaypalConfirmed() { try { BSDBContext db = new BSDBContext(); var model = (CommonConstant.InforPaypal)TempData["InforOrder"]; int Id = model.OrderId; OrdersBook Order = db.OrdersBooks.Find(Id); Order.Paid = true; // Đã thanh toán db.Entry(Order).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); var orderBook = new OrderBookDAO().Get(Id); historyBankCharging history = new historyBankCharging() { email = orderBook.Email, phone = orderBook.Phone, fullname = orderBook.FullName, date_trans = DateTime.Now, price = (int)model.Total, order_code = null, error_text = null, transaction_info = null, payment_id = null, payment_type = "Paypal", secure_code = null }; db.historyBankChargings.Add(history); await db.SaveChangesAsync(); // giam so luong ton cua cac sách khách đã thanh toán foreach (OrdersDetail ordersDetail in Order.OrdersDetails) { Book book = db.Books.Find(ordersDetail.BookID); book.TotalQuantity -= (ordersDetail.Quantity ?? 0); // giảm db.Entry(book).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } Session[CommonConstant.cartSession] = null; return(Redirect("/hoan-thanh")); } catch (Exception ex) { return(View("ThongBaoLoi")); } }
// ok roi. public async Task <ActionResult> PaymentConfirmed(string transaction_info, string order_code, int price, string payment_id, string payment_type, string error_text, string secure_code) { BSDBContext db = new BSDBContext(); if (error_text == "") { int Id = int.Parse(order_code); OrdersBook Order = db.OrdersBooks.Find(Id); Order.Paid = true; // Đã thanh toán db.Entry(Order).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); var orderBook = new OrderBookDAO().Get(Id); historyBankCharging history = new historyBankCharging() { email = orderBook.Email, phone = orderBook.Phone, fullname = orderBook.FullName, date_trans = DateTime.Now, price = price, order_code = order_code, error_text = error_text, transaction_info = transaction_info, payment_id = payment_id, payment_type = payment_type, secure_code = secure_code }; db.historyBankChargings.Add(history); await db.SaveChangesAsync(); // giam so luong ton cua cac sách khách đã thanh toán foreach (OrdersDetail ordersDetail in Order.OrdersDetails) { Book book = db.Books.Find(ordersDetail.BookID); book.TotalQuantity -= (ordersDetail.Quantity ?? 0); // giảm db.Entry(book).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } Session[CommonConstant.cartSession] = null; return(Redirect("/hoan-thanh")); } else { return(View("ThongBaoLoi")); } }
public ActionResult CancelOrder(int Id, string returnUrl) { OrdersBook ordersBook = _db.OrdersBooks.Find(Id); ordersBook.Canceled = true; ordersBook.Status = 0; _db.Entry(ordersBook).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); return(Redirect(returnUrl)); }