public ActionResult Index(string pid)
        {
            Service         service    = new Service();
            List <Category> categories = service.GetCategory();

            ViewBag.Categories = categories;

            if (Session["sessionUser"] == "")
            {
                return(RedirectToAction("LoginPage", "UserLogin"));
            }

            int    num;
            string id = pid ?? "16";

            try
            {
                num = Int32.Parse(id);
            }
            catch (FormatException)
            {
                num = 16;
            }

            if (Request.IsAjaxRequest())
            {
                try
                {
                    ProductsById   product           = new ProductsById(num);
                    List <Product> returning_List    = product.ByID();
                    Product        returning_Product = returning_List[0];
                    return(Json(returning_Product, JsonRequestBehavior.AllowGet));
                }
                catch
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            TempData["pid"] = num;
            return(View());
        }
Пример #2
0
        public ActionResult Index(params int[] list)
        {
            Service         service    = new Service();
            List <Category> categories = service.GetCategory();

            ViewBag.Categories = categories;


            if (Session["sessionUser"] == "")
            {
                return(RedirectToAction("LoginPage", "UserLogin"));
            }

            if (Request.IsAjaxRequest())
            {
                try
                {
                    ProductsById   products       = new ProductsById(list);
                    List <Product> returning_List = products.ByID();
                    return(Json(returning_List, JsonRequestBehavior.AllowGet));
                }
                catch
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (list != null)
            {
                ViewData["length"] = list.Length;
                for (int i = 0; i < list.Length; i++)
                {
                    ViewData["id" + i.ToString()] = list[i].ToString();
                }
            }
            else
            {
                ViewData["length"] = 0;
            }
            return(View());
        }