/// <summary> /// 浏览记录 /// </summary> /// <returns></returns> public PartialViewResult History() { List <ShopProduct> list = new List <ShopProduct>(); //判断用户是否登录 if (User_Shop.IsLogin()) { string curUserID = User_Shop.GetMemberID(); list = DB.ShopBrowsingHistory.Where(q => q.MemberID == curUserID && q.ShopProduct.IsEnable) .OrderByDescending(q => q.CreateTime) .Select(q => q.ShopProduct) .Take(3) .ToList(); ViewBag.title = "浏览记录"; } else { list = DB.ShopProduct.Where(q => q.IsNew && q.IsEnable) .OrderByDescending(q => q.CreateTime) .Take(3) .ToList(); ViewBag.title = "最新商品"; } return(PartialView(list)); }
/// <summary> /// 添加点赞记录 /// </summary> /// <param name="productid"></param> /// <returns></returns> public string Praise(int productid) { try { //判断是否登录 if (User_Shop.IsLogin() == false) { throw new Exception("请登陆后点赞"); } string curUserID = User_Shop.GetMemberID(); //判断是否赞过 if (DB.PraiseRecord.Any(q => q.ProductID == productid && q.MemberID == curUserID)) { throw new Exception("亲,当前商品已经赞过了"); } PraiseRecord record = new PraiseRecord(); record.ProductID = productid; record.MemberID = curUserID; record.CreateTime = DateTime.Now; DB.PraiseRecord.Insert(record); //累计点赞数 ShopProduct product = DB.ShopProduct.FindEntity(productid); product.PraiseCount++; DB.ShopProduct.Update(product); return("1"); } catch (Exception ex) { return(ex.Message); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { //判断是否登录,如果没有登录跳转登录页 //if (User_Shop.IsLogin() == false) //{ // string url = ""; // //如果是微信登录跳转到授权页面 // if (Url_Mobile.IsWechat()) // { // url = Url_Mobile.GetLogin() + "/auth"; // } // else // { // url = Url_Mobile.GetLogin(); // } // url += "?redirecturl=" + ReqHelper.req.Url.AbsolutePath; // if (string.IsNullOrEmpty(url) == false) // filterContext.Result = new RedirectResult(url); //} if (User_Shop.IsLogin() == false) { string url = ""; url = Url_Mobile.GetLogin(); //url += "?redirecturl=" + ReqHelper.req.Url.AbsolutePath; if (string.IsNullOrEmpty(url) == false) { filterContext.Result = new RedirectResult(url); } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { // base.OnActionExecuting(filterContext); //判断用户是否登录 if (User_Shop.IsLogin() == false) { ActionResult result = new RedirectResult(Url_Shop.GetLogin()); filterContext.Result = result; } }
/// <summary> /// 产品详细页面 /// </summary> /// <returns></returns> //public ActionResult Detail(int id) //{ // string curUserID = User_Shop.GetMemberID(); // ViewBag.member = DB.Member_Info.Where(p => p.MemberId == curUserID).FirstOrDefault(); // ShopProduct model = DB.ShopProduct.FindEntity(q => q.ID == id); // if (model == null) // throw new HttpException("您要查看的商品不存在或已经删除"); // //添加用户的浏览记录 // if (User_Shop.IsLogin()) // { // DB.ShopBrowsingHistory.Add(id, User_Shop.GetMemberID()); // } // return View(model); //} public ActionResult Detail(int id) { if (User_Shop.IsLogin()) { string curUserID = User_Shop.GetMemberID(); ViewBag.member = DB.Member_Info.FindEntity(p => p.MemberId == curUserID); DB.ShopBrowsingHistory.Add(id, User_Shop.GetMemberID()); } ShopProduct model = DB.ShopProduct.FindEntity(q => q.ID == id); if (model == null) { throw new HttpException("您要查看的商品不存在或已经删除"); } return(View(model)); }
protected override void OnException(ExceptionContext filterContext) { //错误处理 //判断是否登录,判断用户是否存在 if (User_Shop.IsLogin()) { if (filterContext.RequestContext.HttpContext.Request.HttpMethod.ToLower() == "get") { Account curUser = User_Shop.GetAccount(); Member_Info model = DB.Member_Info.FindEntity(curUser.Id); if (model == null) { CookieHelper.ClearCookie("openid"); User_Shop.Clear(); filterContext.Result = new RedirectResult("~/mobile/memberlogin"); filterContext.ExceptionHandled = true; } } } base.OnException(filterContext); }