public ActionResult Show() { try { var list = new Func_SanPham().DS_SanPham.ToList(); ViewBag.SP = list; if (Request.QueryString["sanpham"] == null) { return(RedirectToAction("Index")); } int x = Int32.Parse(Request.QueryString["sanpham"]); foreach (var i in list) { if (i.id == x) { ViewBag.sanpham = i; ViewBag.linkanh = sp.getImg(i.id)[0]; break; } } }catch (Exception) { ViewBag.linkanh = null; ViewBag.linkanh = null; } return(View()); }
public Dictionary <int, string> getList_imange(int pageNumber, int pageSize) { var list = new Func_SanPham().DS_SanPham.ToList(); int n = new Func_SanPham().DS_SanPham.Count(); //Dictionary<int, string> listImg = new Dictionary<int, string>(); //for (int i = 0; i < n; i++) //{ // try // { // listImg.Add(i, sp.getImg(list[i].id)[0]);//add ảnh lấy được vào dict // } // catch (Exception) // { // } //} Dictionary <int, string> listImg = new Dictionary <int, string>(); for (int i = 0; i < pageSize; i++) { try { listImg.Add(i, sp.getImg(list[(pageNumber - 1) * pageSize + i].id)[0]);//add ảnh lấy được vào dict } catch (Exception) { } } return(listImg); }
public string DeleteSanPham(int id) { var status = "{\"status\":-1, \"sanpham\":" + id + "}"; try { Func_SanPham hamsanpham = new Func_SanPham(); tbl_sanpham data = hamsanpham.FindEntity(id); if (data.tinhtrang != -1) { data.tinhtrang = -1; } else { data.tinhtrang = 1; } int?ss = hamsanpham.Update(data); if (ss != null) { status = "{\"status\":1, \"sanpham\":" + id + ", \"color\":" + data.tinhtrang + "}"; } else { status = "{\"status\":-1, \"sanpham\":" + id + ", \"color\":1}}"; } } catch (Exception ex) { string er = ex.Message; status = "{\"status\":-1, \"sanpham\":" + id + ", \"error\":\"" + er + "\"}"; } return(status); }
public string GetSanPham(int id) { Func_SanPham hamsanpham = new Func_SanPham(); tbl_sanpham sanpham = hamsanpham.FindEntity(id); sanpham newsanpham = hamsanpham.getnewsanpham(sanpham); string json = JsonConvert.SerializeObject(newsanpham); return(json); }
public ActionResult DanhMuc(int?page) { int pageNumber = (page ?? 1); int pageSize = 8; string txtString = Request.QueryString["danhmuc"]; var model = new Func_SanPham().DS_SanPham.Where(x => x.id_dm.ToString().Contains(txtString)).ToList(); ViewBag.DanhMuc = model; return(View("Index", model.ToPagedList(pageNumber, pageSize))); }
public ActionResult ThuongHieu(int?page) { int pageNumber = (page ?? 1); int pageSize = 8; string txtString = Request.QueryString["thuonghieu"]; var model = new Func_SanPham().DS_SanPham.Where(x => x.id_nsx.ToString().Contains(txtString)).ToList(); ViewBag.ThuongHieu = model; return(View("Index", model.ToPagedList(pageNumber, pageSize))); }
public ActionResult Search(string txtString, int?page) { int pageNumber = (page ?? 1); int pageSize = 8; var model = new Func_SanPham().DS_SanPham.Where(x => x.ten.Contains(txtString)).ToList(); ViewBag.Search = model; return(View("Index", model.ToPagedList(pageNumber, pageSize))); }
public ActionResult PriceSearch(int?price_max, int?price_min, int?page) { int pageNumber = (page ?? 1); int pageSize = 8; var model = new Func_SanPham().DS_SanPham.Where(x => x.gia >= price_min * 1000000 && x.gia <= price_max * 1000000).ToList(); ViewBag.PriceSearch = model; return(View("Index", model.ToPagedList(pageNumber, pageSize))); }
// GET: Admin/Home public ActionResult Index() { if (Session["username"] == null) { return(RedirectToAction("Index", "Login")); } else { var list = new Func_SanPham().DS_SanPham.ToList(); ViewBag.SP = list; ViewBag.tittle = "Admin shop mua ban"; ViewBag.select = "dashbord"; return(View()); } }
public ActionResult Index(int?page) { if (Session["userLogin"] != null) { Func_TaiKhoan tinhuser = new Func_TaiKhoan(); ViewBag.user = tinhuser.getTaiKhoan((string)Session["userLogin"]); } else { ViewBag.user = null; } var list = new Func_SanPham().DS_SanPham.ToList(); int pageNumber = (page ?? 1); int pageSize = 8; Dictionary <int, string> listImg = (Dictionary <int, string>)getList_imange(pageNumber, pageSize); ViewBag.Anh = listImg; //return View(listImg); return(View(list.ToPagedList(pageNumber, pageSize))); }
public ActionResult Show() { if (Session["userLogin"] != null) { Func_TaiKhoan tinhuser = new Func_TaiKhoan(); ViewBag.user = tinhuser.getTaiKhoan((string)Session["userLogin"]); } else { ViewBag.user = null; } try { var list = new Func_SanPham().DS_SanPham.ToList(); ViewBag.SP = list; if (Request.QueryString["sanpham"] == null) { return(RedirectToAction("Index")); } int x = Int32.Parse(Request.QueryString["sanpham"]); foreach (var i in list) { if (i.id == x) { ViewBag.sanpham = i; ViewBag.linkanh = sp.getImg(i.id)[0]; break; } } }catch (Exception) { ViewBag.linkanh = null; ViewBag.linkanh = null; } return(View()); }
public ActionResult NameSearch(string txtString, int?page) { if (Session["userLogin"] != null) { Func_TaiKhoan tinhuser = new Func_TaiKhoan(); ViewBag.user = tinhuser.getTaiKhoan((string)Session["userLogin"]); } else { ViewBag.user = null; } ViewBag.name = txtString; int pageNumber = (page ?? 1); int pageSize = 8; var model = new Func_SanPham().DS_SanPham.Where(x => x.ten.Contains(txtString)).ToList(); ViewBag.NameSearch = model; return(View(model.ToPagedList(pageNumber, pageSize))); }
public ActionResult PriceSearch(int?price_max, int?price_min, int?page) { if (Session["userLogin"] != null) { Func_TaiKhoan tinhuser = new Func_TaiKhoan(); ViewBag.user = tinhuser.getTaiKhoan((string)Session["userLogin"]); } else { ViewBag.user = null; } ViewBag.price_max = price_max; ViewBag.price_min = price_min; int pageNumber = (page ?? 1); int pageSize = 8; var model = new Func_SanPham().DS_SanPham.Where(x => x.gia >= price_min * 1000000 && x.gia <= price_max * 1000000).ToList(); ViewBag.PriceSearch = model; return(View(model.ToPagedList(pageNumber, pageSize))); }
public ActionResult ThuongHieu(int?id, int?page) { if (Session["userLogin"] != null) { Func_TaiKhoan tinhuser = new Func_TaiKhoan(); ViewBag.user = tinhuser.getTaiKhoan((string)Session["userLogin"]); } else { ViewBag.user = null; } id = Convert.ToInt32(Request.QueryString["thuonghieu"]); ViewBag.id_nsx = id; int pageNumber = (page ?? 1); int pageSize = 8; var model = new Func_SanPham().DS_SanPham.Where(x => x.id_nsx == id).ToList(); ViewBag.ThuongHieu = model; return(View(model.ToPagedList(pageNumber, pageSize))); }
public string UpdatesSanPham([FromBody] string data) { // string data = requestdata.Content.ReadAsStringAsync().Result; dynamic stuff = JsonConvert.DeserializeObject(data); string status = "{\"status\":1, \"sanpham\":" + stuff.id + "}"; try { sanpham newsanpham = JsonConvert.DeserializeObject <sanpham>(data); Func_SanPham hamsanpham = new Func_SanPham(); tbl_sanpham sanpham = hamsanpham.getsanpham(newsanpham); int? x = hamsanpham.Update(sanpham); if (x == null) { status = "{\"status\":-1, \"sanpham\":" + stuff.id + "}"; } } catch { status = "{\"status\":0, \"sanpham\":" + stuff.id + "}"; } return(status); }
public ActionResult AddProduct() { int? res = null; tbl_sanpham data = new tbl_sanpham(); try { data.ten = Request["tensp"]; data.thenho = Request["thenhosp"]; data.gia = Int32.Parse(Request["giasp"]); data.trongluong = Request["trongluongsp"]; data.soluong = Int32.Parse(Request["soluongsp"]); data.ROM = Request["romsp"]; data.RAM = Request["ramsp"]; data.baohanh = Request["thoigianbaohanhsp"]; data.camera_sau = Request["camerasausp"]; data.camera_truoc = Request["cameratruocsp"]; data.CPU = Request["cpusp"]; data.manhinh = Request["manhinhsp"]; data.pin = Int32.Parse(Request["pinsp"]); data.tinhtrang = 1; data.id_nsx = Int32.Parse(Request["nhasanxuatsp"]); data.bluetooth = Int32.Parse(Request["bluetoothsp"]); HttpPostedFileBase fileUpload = Request.Files["imgsp"]; Func_SanPham tp = new Func_SanPham(); res = tp.Insert(data); if (res != null) { int id = (int)res; if (fileUpload != null) { String timeStamp = GetTimestamp(DateTime.Now); var fileName = timeStamp + Path.GetExtension(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/Content/images"), fileName); // file is uploaded if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { Func_Anh installanh = new Func_Anh(); tbl_anh anh = new tbl_anh(); anh.duongdan = fileName; anh.id_sp = id; int?x = installanh.Insert(anh); if (x == null) { res = -1; } else { fileUpload.SaveAs(path); } } } } } catch { res = -1; } if (res != null) { ViewBag.add = res; } else { ViewBag.add = -1; } return(RedirectToAction("Add", new { add = res })); }