// GET: /TrangChu/ public ActionResult Index() { ViewBag.Title = Conf.TITLE_PUBLIC; var slide = db.slides.OrderBy(x => x.vitri).ToList(); var qc = db.quangcaos.Where(x => x.trangthai == true).Single(); var spMoi = db.san_phams.OrderByDescending(x => x.id_sanpham).Skip(0).Take(Conf.TAKE_ROWS_PUBLIC).ToList(); int khuyenMai = db.khuyenmais.Where(x => x.id_khuyenmai == Conf.ID_PROMOTION).Select(x => x.giatri).Single(); var spKM = db.san_phams.Where(x => x.khuyenmai == true).OrderByDescending(x => x.id_sanpham).Skip(0).Take(Conf.TAKE_ROWS_PUBLIC).ToList(); var spMuaNhieu = (from d in db.dat_hang_details group d by d.id_sanpham into v select new { id = v.Select(x => x.id_sanpham).FirstOrDefault(), count = v.Count() }).OrderByDescending(x => x.count).Skip(0).Take(Conf.TAKE_ROWS_PUBLIC); List <san_pham> listMuaNhieu = new List <san_pham>(); foreach (var item in spMuaNhieu) { //san_pham t = db.san_phams.Where(x => x.id_sanpham == item.id).Select(s =>new san_pham { id_sanpham = s.id_sanpham, gia = s.gia, hinhanh = s.hinhanh, khuyenmai = s.khuyenmai}).Single(); san_pham t = db.san_phams.Where(x => x.id_sanpham == item.id).Single(); listMuaNhieu.Add(t); } List <object> lst = new List <object>(); lst.Add(slide); lst.Add(qc); lst.Add(spMoi); lst.Add(khuyenMai); lst.Add(spKM); lst.Add(listMuaNhieu); return(View(lst)); }
public ActionResult DeleteConfirmed(int id) { san_pham san_pham = db.san_pham.Find(id); db.san_pham.Remove(san_pham); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "id_san_pham,ma_san_pham,ten_san_pham,ma_loai,mo_ta_chi_tiet,don_gia,dvt,tinh_trang,hinh,san_pham_moi,tac_gia,nxb,ngay_xuat_ban,so_trang")] san_pham san_pham) { if (ModelState.IsValid) { db.Entry(san_pham).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(san_pham)); }
// GET: /admin/c_san_phamAD/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } san_pham san_pham = db.san_pham.Find(id); if (san_pham == null) { return(HttpNotFound()); } return(View(san_pham)); }
// pay: public ActionResult PayOrder(int id = -1, bool capt = false) { if (capt == true) { ViewBag.error = Lib.messenger(1, "Mã CAPTCHA không đúng!"); } ViewBag.Title = Conf.TITLE + "Thanh toán đơn hàng"; int promotion = this.GetPromotion(); decimal tongTiem = 0; int indexCaptchar = new Random().Next(0, Conf.CAPCHAR.Length - 1); dat_hang dh = db.dat_hangs.Where(x => x.id_dathang == id).Single(); List <san_pham> listSp = new List <san_pham>(); List <int> soLuong = dh.dat_hang_details.Select(x => x.soluong).ToList(); List <string> size = dh.dat_hang_details.Select(x => x.size).ToList(); List <object> listCS = new List <object>(); listCS.Add(soLuong); listCS.Add(size); foreach (dat_hang_detail item in dh.dat_hang_details) { san_pham p = db.san_phams.Where(x => x.id_sanpham == item.id_sanpham).Single(); if (p.khuyenmai == true) { int percent = 100 - promotion; tongTiem += ((p.gia * percent) / 100) * item.soluong; } else { tongTiem += p.gia * item.soluong; } listSp.Add(p); } List <object> list = new List <object>(); list.Add(dh); list.Add(indexCaptchar); list.Add(listSp); list.Add(tongTiem); list.Add(listCS); if (id != -1) { return(View(list)); } else { return(Redirect("/admin/dat-hang.html")); } }
// sam ban chay: public ActionResult SanPhamBanChay(int page = 0) { ViewBag.Title = Conf.TITLE_PUBLIC + " - Sản phẩm bán chạy"; int spCount = (from d in db.dat_hang_details group d by d.id_sanpham).Count(); var spMuaNhieu = (from d in db.dat_hang_details group d by d.id_sanpham into v select new { id = v.Select(x => x.id_sanpham).FirstOrDefault(), count = v.Count() }).OrderByDescending(x => x.count).Skip(0).Take(Conf.TAKE_ROWS_PRO_PUBLIC); List <san_pham> listMuaNhieu = new List <san_pham>(); foreach (var item in spMuaNhieu) { san_pham t = db.san_phams.Where(x => x.id_sanpham == item.id).Single(); listMuaNhieu.Add(t); } ViewBag.count = spCount; ViewBag.current = page; return(View(listMuaNhieu)); }
// GET: /Cart/ public ActionResult Index() { ViewBag.Title = Config.Conf.TITLE_PUBLIC + " - Giỏ hàng"; if (Session["cart"] != null) { List <MCart> lstCart = (List <MCart>)Session["cart"]; List <san_pham> lstSanPham = new List <san_pham>(); foreach (MCart m in lstCart) { san_pham sp = db.san_phams.Where(x => x.id_sanpham == m.idPro).Single(); lstSanPham.Add(sp); } List <object> lst = new List <object>(); lst.Add(lstCart); lst.Add(lstSanPham); ViewBag.khuyenMai = this.GetPromotion(); return(View(lst)); } else { ViewBag.messenger = "Giỏ hàng trống!"; return(Redirect("/")); } }
public ActionResult EditProduct(FormCollection coll, HttpPostedFileBase file) { int id = Convert.ToInt32(coll["idHd"].ToString()); string title = Lib.VietNamToEnglish(coll["txtTen"].ToString()); string txtTen = coll["txtTen"]; string txtSoLuong = coll["txtSoLuong"]; string cmbDanhMuc = coll["cmbDanhMuc"]; string txtThongTinChiTiet = coll["txtThongTinChiTiet"]; string txtGia = coll["txtGia"]; string chkKhuyenMai = coll["chkKhuyenMai"]; DateTime dt = DateTime.Now; string nameFile = ""; bool tf = false; ViewBag.DanhMuc = this.LoadDahMuc(); var sanpham = (from sp in db.san_phams where sp.id_sanpham == id select sp).Single(); ViewBag.Title = Conf.TITLE + "Thông tin sản phẩm - " + sanpham.ten_sanpham; if (file != null && file.ContentLength > 0) { try { string path = Path.Combine(Server.MapPath("~/uploads")); nameFile = dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second + "-" + dt.Millisecond + Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(path, nameFile)); ViewBag.file = "File uploaded successfully!"; tf = true; } catch (Exception ex) { tf = false; ViewBag.file = "ERROR:" + ex.Message.ToString(); } } try { san_pham sp = db.san_phams.Where(x => x.id_sanpham == id).Single(); sp.gia = Decimal.Parse(txtGia); if (tf == true) { sp.hinhanh = nameFile; } sp.id_danhmuc = int.Parse(cmbDanhMuc); sp.khuyenmai = Boolean.Parse(chkKhuyenMai); sp.ngaydang = DateTime.Now; sp.soluong = int.Parse(txtSoLuong); sp.ten_sanpham = txtTen; sp.tt_chitiet = txtThongTinChiTiet; db.SubmitChanges(); ///return Redirect("/thong-tin-san-pham-" + title + "-" + coll["idHd"] + ".html"); ViewBag.error = Lib.messenger(0, "Cập nhật thành công!"); return(View(sanpham)); } catch (Exception ex) { ViewBag.error = Lib.messenger(2, "Cập nhật thất bại!"); return(View(sanpham)); } }
public ActionResult AddProduct(FormCollection coll, HttpPostedFileBase file) { ViewBag.Title = Conf.TITLE + "Thêm mới sản phẩm"; string txtTen = coll["txtTen"]; string txtSoLuong = coll["txtSoLuong"]; string cmbDanhMuc = coll["cmbDanhMuc"]; string txtThongTinChiTiet = coll["txtThongTinChiTiet"]; string txtGia = coll["txtGia"]; string chkKhuyenMai = coll["chkKhuyenMai"]; string nameFile = ""; DateTime dt = DateTime.Now; bool insert, upload = true; string messesnger = ""; ViewBag.DanhMuc = this.LoadDahMuc(); if (file != null && file.ContentLength > 0) { try { string path = Path.Combine(Server.MapPath("~/uploads")); nameFile = dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second + "-" + dt.Millisecond + Path.GetExtension(file.FileName); //file.SaveAs(path); file.SaveAs(Path.Combine(path, nameFile)); ViewBag.file = "File uploaded successfully!"; upload = true; } catch (Exception ex) { upload = false; ViewBag.file = "ERROR:" + ex.Message.ToString(); } } // insert: if (upload == true) { try { san_pham sp = new san_pham(); sp.gia = Decimal.Parse(txtGia); sp.hinhanh = nameFile; sp.id_danhmuc = int.Parse(cmbDanhMuc); sp.khuyenmai = Boolean.Parse(chkKhuyenMai); sp.ngaydang = DateTime.Now; sp.soluong = int.Parse(txtSoLuong); sp.ten_sanpham = txtTen; sp.tt_chitiet = txtThongTinChiTiet; db.san_phams.InsertOnSubmit(sp); db.SubmitChanges(); insert = true; } catch (Exception ex) { insert = false; messesnger += Lib.messenger(2, "ERROR: " + ex); } if (insert == true && upload == true) { messesnger = Lib.messenger(0, "Thêm sản phẩm thành công"); } } ViewBag.error = messesnger; return(View()); }