public async Task <IActionResult> Delete(int productId)
 {
     if (await MVCHelper.GetAPI(string.Format("{0}{1}", configuration.GetSection("baseUrl").Value + "api/Delete/", productId)) == "true")
     {
         return(RedirectToAction("Index", "Products"));
     }
     return(RedirectToAction("Index", "Products"));
 }
        public void ProductToSession(int productId, int sessionQuantity = 1)
        {
            ProductModel productModel = JsonConvert.DeserializeObject <ProductModel>(MVCHelper.GetAPI(string.Format("{0}{1}", configuration.GetSection("baseUrl").Value + "api/ProductDetail/", productId)).Result);

            productModel.SessionQuantity = sessionQuantity;
            productModel.SessionPrice    = sessionQuantity * productModel.SalePrice;

            string sessionKey  = MethodHelper.IsThereSomeone(HttpContext.Session);
            var    listSession = SessionHelper.GetObjectFromJson <List <ProductModel> >(HttpContext.Session, sessionKey) ?? new List <ProductModel>();

            listSession.Add(productModel);

            SessionHelper.SetObjectAsJson(HttpContext.Session, sessionKey, listSession);
            SessionHelper.SetObjectAsJson(HttpContext.Session, "card", listSession.Count);
        }
Пример #3
0
        // GET: RecipesController

        public async Task <IActionResult> Index()
        {
            List <RecipesModel> recipesList = JsonConvert.DeserializeObject <List <RecipesModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetRecipes")));

            return(View(recipesList));
        }
        public async Task <ActionResult> PriceRange(int min, int max)
        {
            ProductModel productModel = new ProductModel();

            productModel.listProducts = JsonConvert.DeserializeObject <List <ProductModel> >(await MVCHelper.GetAPI(string.Format("{0}{1}/{2}", configuration.GetSection("baseUrl").Value + "api/PriceRange/", min, max)));
            return(PartialView("_Product", productModel));
        }
        public async Task <ActionResult> Search(string searchBy)
        {
            ProductModel productModel = new ProductModel();

            productModel.listProducts = JsonConvert.DeserializeObject <List <ProductModel> >(await MVCHelper.GetAPI(string.Format("{0}{1}", configuration.GetSection("baseUrl").Value + "api/Search/", searchBy)));
            return(PartialView("_Product", productModel));
        }
        public async Task <ActionResult> GetProductsByCategory(int categoryId)
        {
            ProductModel productModel = new ProductModel();

            productModel.listProducts = JsonConvert.DeserializeObject <List <ProductModel> >(await MVCHelper.GetAPI(string.Format("{0}/{1}", configuration.GetSection("baseUrl").Value + "api/GetProductsByCategory", categoryId)));
            return(PartialView("_Product", productModel));
        }
        public async Task <IActionResult> Create()
        {
            ProductModel productModel = JsonConvert.DeserializeObject <ProductModel>(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/CreateProduct/")));

            return(View(productModel));
        }
        public async Task <IActionResult> Index()
        {
            ProductModel productsModel = new ProductModel();

            productsModel.listProducts = JsonConvert.DeserializeObject <List <ProductModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetProducts")));
            userSession                = SessionHelper.GetObjectFromJson <UserModel>(HttpContext.Session, "userObject");
            productsModel.IsAdmin      = userSession != null ? userSession.IsAdmin : false;
            productsModel.listCategory = JsonConvert.DeserializeObject <List <CategoriesModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetCategories")));
            return(View(productsModel));
        }
        public async Task <ActionResult> ProductDetail(int productId)
        {
            ProductModel productModel = JsonConvert.DeserializeObject <ProductModel>(await MVCHelper.GetAPI(string.Format("{0}{1}", configuration.GetSection("baseUrl").Value + "api/ProductDetail/", productId)));

            productModel.listCategory = JsonConvert.DeserializeObject <List <CategoriesModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetCategories")));
            return(View(productModel));
        }
        public async Task <IActionResult> Index()
        {
            ProductModel productsModel = new ProductModel();

            productsModel.listProducts = JsonConvert.DeserializeObject <List <ProductModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetProducts")));
            productsModel.listCategory = JsonConvert.DeserializeObject <List <CategoriesModel> >(await MVCHelper.GetAPI(string.Format("{0}", configuration.GetSection("baseUrl").Value + "api/GetCategories")));
            return(View(productsModel));
        }