public ActionResult ProductContent(int n) { try { var productList = _product.Get().ToList(); Expression <Func <MODEL.Product, bool> > filter = e => e.Id == n; MODEL.Product productCurrent = _product.Get(filter).FirstOrDefault(); var currentIndex = productList.FindIndex(e => e.Id == productCurrent.Id); var prev = currentIndex == 0?null: productList[currentIndex - 1]; var next = currentIndex == _product.Count(null) - 1?null: productList[currentIndex + 1]; return(View(new ProductsContentViewModel { ProductCurrent = productCurrent, ProductPrev = prev, ProductNext = next })); } catch (Exception ex) { return(null); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string PrdNo = context.Request["PrdNo"]; if (context.Session["userInfo"] == null) { context.Response.Write("NoLogin"); } else { if (!string.IsNullOrEmpty(PrdNo)) { MODEL.Product product = BLL.ProductManager.GetPrd(PrdNo); if (product != null) { MODEL.User user = context.Session["userInfo"] as MODEL.User; MODEL.ShoppingCart cart = BLL.ShoppingCartManager.GetCart(user.LoginId, PrdNo); if (cart != null) { cart.PrdQty = cart.PrdQty + 1; BLL.ShoppingCartManager.UpdateCart(cart); } else { cart = new MODEL.ShoppingCart(); cart.UserId = user.LoginId; cart.PrdName = product.PrdName; cart.PrdNo = product.PrdNo; cart.PrdQty = 1; cart.SettleStt = 0; BLL.ShoppingCartManager.AddCart(cart); } string strCart = Common.LoadShoppingCart.GetCartByUser(); context.Response.Write(strCart); } } } }