public ActionResult Search(string tensp, string tenloaisp, string TuGia, string DenGia, int page = 1, int pageSize = 10) { if (Session["us"] == null) { return(RedirectToAction("Login")); } else { List <LOAIMAY> cateLoaiSP = db.LOAIMAYs.ToList(); if (page == 1 && tensp == null && tenloaisp == null && TuGia == null && DenGia == null) { tensp = Request.Form["txtTenSP"]; tenloaisp = Request.Form["IDLOAIMAY"]; TuGia = Request.Form["txtTuGia"]; DenGia = Request.Form["txtDenGia"]; } if (tenloaisp == null || tenloaisp == "") { tenloaisp = ""; } else { LOAIMAY lp = new LOAIMAY(); lp = (LOAIMAY)db.LOAIMAYs.Where(p => p.TENLMAY == tenloaisp).SingleOrDefault(); cateLoaiSP.Remove(lp); LOAIMAY lp1 = new LOAIMAY(); lp1.IDLOAIMAY = 0; lp1.TENLMAY = ""; cateLoaiSP.Add(lp1); } ViewBag.TenSP = tensp; ViewBag.IDLOAIMAY = cateLoaiSP; ViewBag.TenLoaiSP = tenloaisp; ViewBag.TuGia = TuGia; ViewBag.DenGia = DenGia; if (TuGia == "" || TuGia == null) { TuGia = "0"; } if (DenGia == "" || DenGia == null) { DenGia = "1000000000000000"; } string query = string.Format("select IDMAY, TENMAY, HINHANH, DONGIA, MAYANH.IDLOAIMAY, LOAIMAY.TENLMAY from MAYANH,LOAIMAY where MAYANH.IDLOAIMAY = LOAIMAY.IDLOAIMAY and TENMAY like N'%" + tensp + "%' and TENLMAY like N'%" + tenloaisp + "%' and DONGIA >= " + TuGia + " and DONGIA <= " + DenGia); var lst = (db.Database.SqlQuery <CTMAYANH>(query).ToList()).ToPagedList(page, pageSize); return(View(lst)); } }
public ActionResult Edit(LOAIMAY pr) { LOAIMAY lOAIMAY = new LOAIMAY(); lOAIMAY = db.LOAIMAYs.Find(pr.IDLOAIMAY); if (lOAIMAY != null) { lOAIMAY.TENLMAY = pr.TENLMAY; } return(RedirectToAction("List")); }
public ActionResult Delete(LOAIMAY pr) { LOAIMAY lOAIMAY = new LOAIMAY(); lOAIMAY = db.LOAIMAYs.Find(pr.IDLOAIMAY); if (lOAIMAY != null) { db.LOAIMAYs.Remove(pr); db.SaveChanges(); } return(RedirectToAction("List")); }
public ActionResult Delete(int id) { if (Session["us"] == null) { return(RedirectToAction("Login", "MayAnh")); } else { LOAIMAY pr = new LOAIMAY(); pr = db.LOAIMAYs.Find(id); return(View(pr)); } }
public ActionResult Create(LOAIMAY pr) { db.LOAIMAYs.Add(pr); db.SaveChanges(); return(RedirectToAction("List")); }