public ActionResult Login([Bind(Include = "UserName,PassWord,Remember")] Models.LoginVM user) { string txtPassword = user.PassWord; string RawPassword; Helper.UserContext.Destroy(); using (var md5Hash = MD5.Create()) { RawPassword = Helper.StringUtils.GetMd5Hash(md5Hash, txtPassword); ///RawPassword.ToLower(); } using (var db = new Models.QLBHEntities()) { var CheckUser = db.Users.Where(item => item.f_Username == user.UserName && item.f_Password == RawPassword) .FirstOrDefault(); if (CheckUser != null) { Session["isLogin"] = true; Session["CurrentUser"] = CheckUser; if (user.Remember == true) { Response.Cookies["user_id"].Value = CheckUser.f_ID.ToString(); ///System.Diagnostics.Debug.Write(Response.Cookies["user_id"].Value+"\n\n\n"); Response.Cookies["user_id"].Expires = DateTime.Now.AddDays(7); } return(RedirectToAction("Index", "Home")); } } ViewBag.MgsErorrAccount = "Sai Tài Khoản Hoặc Mật Khẩu"; return(View()); }
// GET: ByCat public ActionResult BySpe(int?id, int page = 1) { List <Models.Product> listProduct; if (id.HasValue) { using (var db = new Models.QLBHEntities()) { ViewBag.Spe = db.Species.Where(it => it.ID == id).FirstOrDefault(); int n = db.Products.Where(it => it.SpeID == id).Count(); int recordsOfPage = 6; int nPage = n / recordsOfPage; nPage = n % recordsOfPage == 0 ? nPage : nPage + 1; nPage = nPage == 0 ? 1 : nPage; ViewBag.Pages = nPage; ViewBag.CurentPage = page; ViewBag.TotalPage = nPage; listProduct = db.Products.Where(it => it.SpeID == id) .OrderBy(i => i.ProID) .Skip((page - 1) * recordsOfPage) .Take(recordsOfPage) .ToList(); } } else { return(RedirectToAction("Index", "Home")); } return(View("ByCat", listProduct)); }
// GET: Product public ActionResult Detail(int?id) { if (!id.HasValue) { return(RedirectToAction("Index", "Home")); } Product product = null; using (var db = new Models.QLBHEntities()) { product = db.Products.Where(item => item.ProID == id) .FirstOrDefault(); if (product != null) { ViewBag.PsameCat = db.Products.Where(item => item.CatID == product.CatID) .Take(5).ToList(); ViewBag.PsamSpe = db.Products.Where(item => item.SpeID == product.SpeID) .Take(5).ToList(); product.Viewer++; } db.SaveChanges(); } if (product == null) { return(RedirectToAction("Index", "Home")); } return(View(product)); }
// GET: MenuAdmin public ActionResult GetMenu() { List <Models.Category> listCategory = null; using (var db = new Models.QLBHEntities()) { listCategory = db.Categories.ToList(); } return(PartialView(listCategory)); }
public ActionResult search(string strSearch, int page = 1) { List <Models.Product> listP; listProduct.Clear(); if (!string.IsNullOrEmpty(strSearch)) { ssearch = strSearch; ViewBag.Stsearch = ssearch; using (var db = new Models.QLBHEntities()) { decimal pr; decimal.TryParse(strSearch, out pr); var pcat = db.Products.Where(it => it.Category.CatName.Contains(strSearch)).ToList(); listProduct.AddRange(pcat); if (pr != 0) { var pPrice = db.Products.Where(item => item.Price > (pr - 2000000) && item.Price < (pr + 2000000)) .ToList().Except(pcat).ToList(); listProduct.AddRange(pPrice); } var pName = db.Products.Where(item => item.ProName.Contains(strSearch)) .ToList().Except(listProduct).ToList(); listProduct.AddRange(pName); int n = listProduct.Count; int recordsOfPage = 6; int nPage = n / recordsOfPage; nPage = nPage % recordsOfPage == 0 ? nPage : nPage + 1; nPage = nPage == 0 ? 1 : nPage; ViewBag.Pages = nPage; ViewBag.CurentPage = page; ViewBag.TotalPage = nPage; listP = listProduct .OrderBy(i => i.ProID) .Skip((page - 1) * recordsOfPage) .Take(recordsOfPage) .ToList(); } return(View("ByCat", listP)); } else { return(RedirectToAction("Index", "Home")); } }
// GET: Home public ActionResult Index(int?id) { List <Models.Product> listProduct; using (var db = new Models.QLBHEntities()) { if (id.HasValue) { listProduct = db.Products.Where(it => it.CatID == id).ToList(); } else { listProduct = db.Products.ToList(); } } return(View(listProduct)); }
public ActionResult Add(int proId, int quantity) { using (var db = new Models.QLBHEntities()) { var pro = db.Products.Where(p => p.ProID == proId && p.Quantity >= quantity) .FirstOrDefault(); if (pro != null) { var item = new CartItem() { Quantity = quantity, product = pro }; UserContext.GetCart().AddItem(item); } } return(RedirectToAction("Detail", "Product", new { id = proId })); }
public ActionResult AddIndex(int proId, int quantity, int curpage) { Product pro; using (var db = new Models.QLBHEntities()) { pro = db.Products.Where(p => p.ProID == proId && p.Quantity >= quantity) .FirstOrDefault(); if (pro != null) { var item = new CartItem() { Quantity = quantity, product = pro }; UserContext.GetCart().AddItem(item); } } return(RedirectToAction("Index", "Home")); }
// GET: GetProduct public ActionResult GetProduct(int?id, int page = 1) { List <Models.Product> listProduct; if (id.HasValue) { using (var db = new Models.QLBHEntities()) { var name = db.Categories.Where(it => it.CatID == id).SingleOrDefault(); if (name != null) { ViewBag.NameCat = name.CatName; } int n = db.Products.Where(it => it.CatID == id).Count(); int recordsOfPage = 6; int nPage = n / recordsOfPage; nPage = n % recordsOfPage == 0 ? nPage : nPage + 1; nPage = nPage == 0 ? 1 : nPage; ViewBag.Pages = nPage; ViewBag.CurentPage = page; ViewBag.TotalPage = nPage; listProduct = db.Products.Where(it => it.CatID == id) .OrderBy(i => i.ProID) .Skip((page - 1) * recordsOfPage) .Take(recordsOfPage) .ToList(); } } else { return(RedirectToAction("Index", "Home")); } return(View(listProduct)); }
static public bool isLogin() { var flag = HttpContext.Current.Session["isLogin"]; if (flag == null || (bool)flag != true) { if (HttpContext.Current.Request.Cookies["user_id"] != null) { int user_id = int.Parse(HttpContext.Current.Request.Cookies["user_id"].Value); HttpContext.Current.Session["isLogin"] = true; using (var db = new Models.QLBHEntities()) { var CheckUser = db.Users.Where(item => item.f_ID == user_id) .FirstOrDefault(); HttpContext.Current.Session["CurrentUser"] = CheckUser; } return(true); } return(false); } return(true); }