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)); }
/// <summary> /// Chuyển trạng thái đơn hàng đã thanh toán /// Trừ số lượng sách KDH vừa mua /// </summary> /// <param name="orderID"></param> public void ConvertPaidToTrue(int orderID) { BSDBContext db = new BSDBContext(); var model = db.OrdersBooks.Find(orderID); model.Paid = true; db.SaveChanges(); var detail = db.OrdersDetails.Where(x => x.OrderID == orderID).ToList(); foreach (var item in detail) { var book = db.Books.Find(item.BookID); int temp = book.TotalQuantity - item.Quantity.GetValueOrDefault(); if (temp <= 0) { book.TotalQuantity = 0; db.SaveChanges(); } else { book.TotalQuantity = temp; db.SaveChanges(); } } }
public bool AddCmt(Comment cmt) { try { string qrInsert = "Insert into Comments (UserID, BookID, Content, CreatedDate, isDeleted, isLike, FolderID) values (" + cmt.UserID + ", " + cmt.BookID + ", N'" + cmt.Content + "', getdate(), " + "0, 0, 0)"; db.Database.ExecuteSqlCommand(qrInsert); db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
public bool Insert(User ac) { try { db.Users.Add(ac); db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
public ActionResult Register(User account) { if (account.Username == null || account.Password == null) { return(View()); } if (ModelState.IsValid) { using (BSDBContext db = new BSDBContext()) { var user = db.Users.FirstOrDefault(p => p.Username == account.Username); if (user == null) { account.UserRoleID = 2; account.isActivated = true; account.Password = CommonConstant.Encrypt(account.Password); account.Birthday = DateTime.Now; db.Users.Add(account); db.SaveChanges(); } else { ViewBag.Message = "UserName already exists" + account.Username; return(View()); } } ModelState.Clear(); ViewBag.Message = "Successfully Registered Mr. " + account.Username; } return(RedirectToAction("Index")); }
public ActionResult UnActived(int userID) { var dao = db.Users.Find(userID); dao.isActivated = false; int rslt = 1; try { db.SaveChanges(); }catch (Exception ex) { rslt = -1; } return(Json(rslt, JsonRequestBehavior.AllowGet)); }
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 Register(User model) { if (ModelState.IsValid) { using (BSDBContext db = new BSDBContext()) { var user = db.Users.FirstOrDefault(p => p.Username == model.Username); if (user == null) { model.UserRoleID = 1; model.isActivated = true; model.Password = CommonConstant.Encrypt(model.Password); db.Users.Add(model); db.SaveChanges(); } else { ViewBag.Message = "Tài khoản " + model.Username + " đã tồn tại"; return(View()); } } ModelState.Clear(); ViewBag.Message = "Đăng ký thành công cho tài khoản " + model.Username; } return(RedirectToAction("Login")); }
/// <summary> /// Ham BookDetail co tham so truyen vao la id /// </summary> /// <param name="id"></param> /// <returns></returns> public PartialViewResult BookDetail(int id) { var model = db.Books.Find(id); // Tăng số lần xem model.ViewCount++; db.SaveChanges(); // Lấy cookie cũ tên views var views = Request.Cookies["views"]; // Nếu chưa có cookie cũ -> tạo mới if (views == null) { views = new HttpCookie("views"); } // Bổ sung mặt hàng đã xem vào cookie views.Values[id.ToString()] = id.ToString(); // Đặt thời hạn tồn tại của cookie views.Expires = DateTime.Now.AddMonths(1); // Gửi cookie về client để lưu lại Response.Cookies.Add(views); // Lấy List<int> chứa mã hàng đã xem từ cookie var keys = views.Values.AllKeys.Select(k => int.Parse(k)).ToList(); // Truy vấn hàng đã xem ViewBag.Views = db.Books.Where(p => keys.Contains(p.BookID)); return(PartialView(model)); //// trả về tất cả các trường trong sách có id là tham số truyền vào //var model = Context.Books.Where(p => p.BookID == id).SingleOrDefault(); //return PartialView(model); }
/// <summary> /// update thong tin profile vao database /// </summary> /// <param name="userName">kiem tra user co trong database de update</param> /// <param name="birthDay">user chi duoc update birth vao database</param> /// <returns>update thanh cong thi tra ve tru con nguoc lai la false</returns> public bool Update(string userName, DateTime birthDay, string image, string Phone, string Address) { try { var queryProfile = from userProfle in _db.Users where userProfle.Username == userName select userProfle; if (birthDay == null && image == null) { return(false); } else { queryProfile.FirstOrDefault().Birthday = birthDay.Date; queryProfile.FirstOrDefault().ImageURL = image; queryProfile.FirstOrDefault().Phone = Phone; queryProfile.FirstOrDefault().Address = Address; _db.SaveChanges(); return(true); } } catch { return(false); } }
public ActionResult Register(User account) { if (account.Username == null || account.Password == null) { return(View()); } if (ModelState.IsValid) { using (BSDBContext db = new BSDBContext()) { var user = db.Users.FirstOrDefault(p => p.Username == account.Username); if (user == null) { account.Password = HashPassword.getHash(account.Password); db.Users.Add(account); db.SaveChanges(); } else { ViewBag.Message = "UserName already exists" + account.Username; return(View()); } } ModelState.Clear(); ViewBag.Message = "Successfully Registered Mr. " + account.Username; } return(RedirectToAction("Index")); }
/// <summary> /// hàm lưu phản hồi từ khách hàng vào db /// </summary> /// <param name="entity">LienHe</param> /// <returns>int</returns> public int InsertContact(LienHe entity) { db.LienHes.Add(entity); db.SaveChanges(); return(entity.MaLH); }
/// <summary> /// Thêm vào 1 tác giả dựa trên ID /// </summary> /// <param name="author"></param> /// <returns>trả về ID của tác giả được chọn</returns> public int Insert(Author author, string imageURL) { db.Authors.Add(author); var image = new Image(); image.ImageURL = imageURL; var imageID = db.Images.Add(image); db.SaveChanges(); //câu lệnh sửa imageboolID của 1 tác giả string updateAuthorImage = "update Authors set ImageBoolID = " + imageID.ImageBoolID + " where AuthorID = " + author.AuthorID; db.Database.ExecuteSqlCommand(updateAuthorImage); db.SaveChanges(); return(author.AuthorID); }
/// <summary> /// Update thông tin của 1 cuốn sách /// </summary> /// <param name="book"></param> /// <param name="imageURL"></param> /// <returns></returns> public bool Update(Book book, string imageURL) { try { var bookOld = db.Books.Find(book.BookID); //bookOld.Image.ImageURL = imageURL; db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
public JsonResult ThayDoiTrangThaiDonHang(int maDDH, int?id) { if (id == 3) { var donHang = db.DonDatHangs.FirstOrDefault(p => p.MaDDH == maDDH); donHang.Tracking = id; donHang.ThanhToan = 1; var value = db.SaveChanges(); return(Json(value, JsonRequestBehavior.AllowGet)); } else { var donHang = db.DonDatHangs.FirstOrDefault(p => p.MaDDH == maDDH); donHang.Tracking = id; var value = db.SaveChanges(); return(Json(value, JsonRequestBehavior.AllowGet)); } }
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)); }
/// <summary> /// Thêm vào 1 tác giả dựa trên ID /// </summary> /// <param name="author"></param> /// <returns>trả về ID của tác giả được chọn</returns> public int Insert(Author author, string imageURL) { db.Authors.Add(author); //tạo mới 1 imagebool var imageBool = new ImageBool(); var image = db.ImageBools.Add(imageBool); db.SaveChanges(); //câu lệnh thêm URL của 1 tác giả trên SQL string qrInsertImage = "insert into Images values (" + image.ImageBoolID + ", N'" + imageURL + "');"; //câu lệnh sửa imageboolID của 1 tác giả string updateAuthorImage = "update Authors set ImageBoolID = " + image.ImageBoolID + " where AuthorID = " + author.AuthorID; db.Database.ExecuteSqlCommand(qrInsertImage); db.Database.ExecuteSqlCommand(updateAuthorImage); db.SaveChanges(); return(author.AuthorID); }
public JsonResult XacNhanEmail(int khMaKh) { KhachHang Data = db.KhachHangs.Where(x => x.MaKH == khMaKh).FirstOrDefault(); Data.TrangThai = true; db.SaveChanges(); var msg = "Đã Xác Nhận Email!"; Session["User"] = null; return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult TransferStatus(int orderID) { var dao = db.OrdersBooks.Find(orderID); if (dao.Status == 3) { dao.Status++; dao.Paid = true; var detail = db.OrdersDetails.Where(x => x.OrderID == orderID).ToList(); foreach (var item in detail) { var book = db.Books.Find(item.BookID); int temp = book.TotalQuantity - item.Quantity.GetValueOrDefault(); if (temp <= 0) { book.TotalQuantity = 0; db.SaveChanges(); } else { book.TotalQuantity = temp; db.SaveChanges(); } } } else { dao.Status++; } int result = 1; try { db.SaveChanges(); } catch (Exception e) { result = -1; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public bool Insert(OrdersBook order) { try { db.OrdersBooks.Add(order); db.SaveChanges(); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// hàm thêm sản phẩm vào đơn đặt hàng /// </summary> /// <param name="detail">ChiTietDDH</param> /// <returns>bool</returns> public bool Insert(ChiTietDDH detail) { try { db.ChiTietDDHs.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
public bool Insert(OrdersDetail temp) { try { db.OrdersDetails.Add(temp); db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
public bool Insert(OrdersBook order) { try { string qrInsert = "Insert into OrdersBooks (FoundedDate, UserID, Status, Address, Phone, Email) Values ('" + order.FoundedDate + "', " + order.UserID + ", " + order.Status + ", N'" + order.Address + "', '" + order.Phone + "', '" + order.Email + "')"; db.Database.ExecuteSqlCommand(qrInsert); db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
public ActionResult TransferStatus(int orderID) { var dao = db.OrdersBooks.Find(orderID); dao.Status++; int result = 1; try { if (dao.Status == 4) { var bookDetail = from table in db.OrdersDetails where table.OrderID == orderID select table; foreach (var bookD in bookDetail) { var bookS = from table in db.Books where table.BookID == bookD.BookID select table; foreach (var book in bookS) { var daoBook = new BookDAO(); daoBook.UpdateCurrent(book.BookID, Int32.Parse(book.CurrentQuantity.ToString()), Int32.Parse(bookD.Quantity.ToString())); } } dao.Paid = true; } db.SaveChanges(); } catch (Exception e) { result = -1; } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Update thông tin của 1 cuốn sách /// </summary> /// <param name="book"></param> /// <param name="imageURL"></param> /// <returns></returns> public bool Update(Book book, string imageURL, int Quantity) { try { var bookOld = db.Books.Find(book.BookID); bookOld.ImageBool.Images.First().ImageURL = imageURL; bookOld.TotalQuantity += Quantity; bookOld.CurrentQuantity += Quantity; //string updateBook = "update Books set CurrentQuantity = " + bookOld.CurrentQuantity + Quantity + ",TotalQuantity = " + bookOld.TotalQuantity + Quantity + " where BookID = "+ book.BookID +")"; //db.Database.ExecuteSqlCommand(updateBook); db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
/// <summary> /// Lấy Category đã khi Insert, thực hiện Insert lên CSDL /// </summary> /// <param name="entity">Categoy đã Insert trên trang Index Category</param> /// <returns></returns> public int Insert(Category entity) { db.Categories.Add(entity); db.SaveChanges(); return(entity.CategoryID); }
/// <summary> /// Hàm thêm khách hàng mới /// </summary> /// <param name="entity">KhachHang</param> /// <returns>int</returns> public int InsertUser(KhachHang entity) { db.KhachHangs.Add(entity); db.SaveChanges(); return(entity.MaKH); }
/// <summary> /// hàm thêm đơn hàng /// </summary> /// <param name="order">DonDatHang</param> /// <returns>int</returns> public int Insert(DonDatHang order) { db.DonDatHangs.Add(order); db.SaveChanges(); return(order.MaDDH); }
/// <summary> /// hàm thêm thểm loại /// </summary> /// <param name="entity">TheLoai</param> /// <returns>int</returns> public int InsertCategory(TheLoai entity) { db.TheLoais.Add(entity); db.SaveChanges(); return(entity.MaLoai); }
public int Insert(Publisher publisher) { db.Publishers.Add(publisher); db.SaveChanges(); return(publisher.PublisherID); }