public ActionResult Delete(int id, FormCollection collection) { try { var model = LinhVucManager.find((int)id); if (model == null) { putErrorMessage("Không tìm thấy"); return(RedirectToAction("Index")); } if (model.delete()) { putSuccessMessage("Xóa thành công"); return(RedirectToAction("Index")); } else { putErrorMessage("Xóa không thành công"); } return(RedirectToAction("Delete", new { id })); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("Delete", new { id })); } }
// GET: Sach/Edit/5 public ActionResult Edit(int?id) { if (id == null) { putErrorMessage("Đường dẫn không chính xác"); return(RedirectToAction("Index")); } var model = SachManager.find((int)id); if (model == null || model.TrangThai == 0) { putErrorMessage("Không tìm thấy"); return(RedirectToAction("Index")); } //Combobox Nhà xuất bản ViewBag.DMNXB = new SelectList(NhaXuatBanManager.getAllAlive(), nameof(NhaXuatBanManager.Properties.MaSoNXB), nameof(NhaXuatBanManager.Properties.TenNXB), ""); //Combobox lĩnh vực ViewBag.DMLinhVuc = new SelectList(LinhVucManager.getAllALive(), nameof(LinhVucManager.Properties.MaSoLinhVuc), nameof(LinhVucManager.Properties.TenLinhVuc), ""); if (model.HinhAnh != null) { ViewBag.imgSrc = ImagesHelper.ImageToDataBase64String(model.HinhAnhTypeImage); } setAlertMessage(); return(View(model)); }
/// <summary> /// Load danh sách Lĩnh vực và add vào giao diện /// </summary> public void loadLinhVuc() { _DMLinhVuc = LinhVucManager.getAll(); cmbLinhVuc.DataSource = _DMLinhVuc; cmbLinhVuc.DisplayMember = nameof(LinhVucManager.Properties.TenLinhVuc); cmbLinhVuc.ValueMember = nameof(LinhVucManager.Properties.MaSoLinhVuc); }
//Khi chọn xóa 1 lĩnh vực private void btnXoa_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn xóa lĩnh vực", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (!txbMaLinhVuc.Text.Equals("")) { if (LinhVucManager.delete(int.Parse(txbMaLinhVuc.Text.ToString()))) { MessageBox.Show("Đã xóa lĩnh vực thành công"); loadLinhVuc(); } else { MessageBox.Show("Không xóa được !"); } } else { MessageBox.Show("Chọn lĩnh vực cần xóa"); } } else if (dialogResult == DialogResult.No) { return; } }
protected override void OnActionExecuted(ActionExecutedContext filterContext) { var sess = (NguoiDung)Session[Core.Constants.SESSION.USERNAME]; if (sess == null) { //filterContext.Result = new RedirectToRouteResult( // new RouteValueDictionary(new { controller = "Account", action = "Login"})); } else { ViewBag.currentUser = sess; } ViewBag.Catalory = LinhVucManager.getAllALive(); List <Sach> DMSach = null; if (Session[Core.Constants.SESSION.BOOKS] == null) { DMSach = SachManager.getAllAlive(); Session[Core.Constants.SESSION.BOOKS] = DMSach; } else { DMSach = Session[Core.Constants.SESSION.BOOKS] as List <Sach>; } //Sách còn tồn nhiều nhất ViewBag.newProduct = DMSach.OrderByDescending(s => s.Soluong).FirstOrDefault(); //Sách có giá cao nhất ViewBag.hightRateProducts = DMSach.OrderByDescending(s => s.GiaBan).Take(2).ToList(); base.OnActionExecuted(filterContext); }
//Khi cập nhật lĩnh vực sửa private void btnCapNhat_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn cập nhật", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (String.IsNullOrEmpty(txbTenLinhVuc.Text)) { MessageBox.Show("Tên lĩnh vực chưa hợp lệ"); return; } //Kiểm tra thông tin sửa có tồn tại không if (_DMLinhVuc.Find(l => l.TenLinhVuc.Equals(txbTenLinhVuc.Text)) != null) { MessageBox.Show("Lĩnh vực đã tồn tại."); return; } LinhVuc lv = new LinhVuc() { MaSoLinhVuc = Int32.Parse(txbMaLinhVuc.Text), TenLinhVuc = txbTenLinhVuc.Text }; if (LinhVucManager.edit(lv)) { MessageBox.Show("Đã cập nhật."); reload(); return; } MessageBox.Show("Cập nhật thất bại."); } else if (dialogResult == DialogResult.No) { return; } }
public ActionResult Edit(LinhVuc model, FormCollection collection) { try { // TODO: Add update logic here if (ModelState.IsValid) { if (LinhVucManager.edit(model)) { putSuccessMessage("Cập nhật thành công"); return(RedirectToAction("Details", new { id = model.MaSoLinhVuc })); } else { putErrorMessage("Cập nhật thất bại"); } } else { putModelStateFailErrors(ModelState); } return(RedirectToAction("Edit", new { id = model.MaSoLinhVuc })); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("Edit", new { id = model.MaSoLinhVuc })); } }
public ActionResult Create(LinhVuc model) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var result = LinhVucManager.add(model); if (result != 0) { putSuccessMessage("Thêm thành công"); RedirectToAction("Details", new { id = result }); } else { putErrorMessage("Thêm thất bại"); } } else { putModelStateFailErrors(ModelState); } setAlertMessage(); return(View(model)); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("Create")); } }
//Khi Load Form private void frmThemSach_Load(object sender, EventArgs e) { //Load tất cả lĩnh vực _DMLinhVuc = LinhVucManager.getAll(); cmbLinhVuc.DataSource = _DMLinhVuc; //Load tất cả nhà xuất bản _DMNXB = NhaXuatBanManager.getAll(); cmbNXB.DataSource = _DMNXB; }
// GET: Sach/Create public ActionResult Create() { var model = new Sach(); //Combobox nhà xuất bản ViewBag.DMNXB = new SelectList(NhaXuatBanManager.getAllAlive(), nameof(NhaXuatBanManager.Properties.MaSoNXB), nameof(NhaXuatBanManager.Properties.TenNXB), ""); //Combobox lĩnh vực ViewBag.DMLinhVuc = new SelectList(LinhVucManager.getAllALive(), nameof(LinhVucManager.Properties.MaSoLinhVuc), nameof(LinhVucManager.Properties.TenLinhVuc), ""); setAlertMessage(); return(View(model)); }
// GET: LinhVuc/Details/5 public ActionResult Details(int?id) { if (id == null) { putErrorMessage("Đường dẫn không chính xác"); return(RedirectToAction("Index")); } var model = LinhVucManager.find((int)id); if (model == null) { putErrorMessage("Không tìm thấy"); return(RedirectToAction("Index")); } setAlertMessage(); return(View(model)); }
// GET: LinhVuc public ActionResult Index(int page = 1, int pageSize = 10, string search = null) { List <LinhVuc> DMLinhVuc = null; if (!String.IsNullOrEmpty(search)) { DMLinhVuc = LinhVucManager.filter(search); ViewBag.SearchKey = search; } else { DMLinhVuc = LinhVucManager.getAllALive(); } var models = DMLinhVuc.ToPagedList(page, pageSize); setAlertMessage(); return(View(models)); }
//Khi chọn Thêm Lĩnh vực private void btnThem_Click(object sender, EventArgs e) { string tensach = Prompt.showDialog("Tên Lĩnh vực :", "Nhập tên lĩnh vực muốn thêm.", this); if (!String.IsNullOrEmpty(tensach)) { LinhVuc lv = new LinhVuc() { TenLinhVuc = tensach }; var result = LinhVucManager.add(lv); if (result != 0) { MessageBox.Show("Đã thêm."); reload(); return; } MessageBox.Show("Không thêm được"); } }
public ActionResult Index() { var rand = new Random(); //Giới hạn sách hiển thị var limit = 6; List <Sach> DMSach = null; if (Session[Core.Constants.SESSION.BOOKS] == null) { DMSach = SachManager.getAllAlive(); Session[Core.Constants.SESSION.BOOKS] = DMSach; } else { DMSach = Session[Core.Constants.SESSION.BOOKS] as List <Sach>; } //Láy random 6 sách var models = DMSach.OrderBy(c => rand.Next()).Take(limit); //Danh mục lĩnh vực ViewBag.DMLinhVuc = LinhVucManager.getAllALive().Take(5).ToList(); return(View(models)); }
public ActionResult List(int?id, int page = 1, int pageSize = 9, string search = null) { if (id == null) { return(new HttpNotFoundResult("Bad Request!")); } var model = LinhVucManager.find((int)id); if (model == null || model.TrangThai == 0) { return(new HttpNotFoundResult("Not Found!")); } List <Sach> DMSach = model.Sach; if (!String.IsNullOrEmpty(search)) { DMSach = SachManager.filter(search, DMSach); ViewBag.SearchKey = search; } ViewBag.currentLV = model; var models = DMSach.ToPagedList(page, pageSize); return(View(models)); }
public void reloadLinhVuc() { _DMLinhVuc = LinhVucManager.getAll(); cmbLinhVuc.DataSource = _DMLinhVuc; }
public bool delete() { this.TrangThai = 0; return(LinhVucManager.edit(this)); }
private void loadLinhVuc() { _DMLinhVuc = LinhVucManager.getAllALive(); gdvDMLinhVuc.DataSource = _DMLinhVuc; }