Beispiel #1
0
        public IActionResult GetAll()
        {
            if (!(Convert.ToBoolean(HttpContext.Session.GetString("Active"))))
            {
                return(RedirectToAction("Login", "IO"));
            }
            string tempId = HttpContext.Session.GetString("id");
            int    userId = int.Parse(tempId);

            foreach (var favori in _favorilerService.GetAll(userId))
            {
                bool logic = false;
                foreach (var product in _productService.ViewAllProducts(userId))
                {
                    if (favori.ProductId == product.Id)
                    {
                        logic = true;
                    }
                }
                if (logic == false)
                {
                    _favorilerService.Delete(favori); //favorilerden de silinir ve null hatası oluşması engellenir.
                }
            }


            var favoriler = _favorilerService.GetAll(userId);

            List <FavoriGetAllModel> favoriGetAllModels = new List <FavoriGetAllModel>();

            foreach (var item in favoriler)
            {
                var product = _productService.GetById(item.ProductId);
                FavoriGetAllModel favoriGetAllModel = new FavoriGetAllModel();
                favoriGetAllModel.Product  = product;
                favoriGetAllModel.FavoriId = item.Id;
                favoriGetAllModels.Add(favoriGetAllModel);
            }
            //ViewBag.Favorite = "true";

            return(View(favoriGetAllModels));
        }
Beispiel #2
0
        public IActionResult GetByCategoryId(int id) // category id gelir.
        {
            if (!(Convert.ToBoolean(HttpContext.Session.GetString("Active"))))
            {
                return(RedirectToAction("Login", "IO"));
            }

            string tempId = HttpContext.Session.GetString("id");
            int    userId = int.Parse(tempId);

            var result = _favorilerService.GetByCategoryId(userId, id);

            List <FavoriGetAllModel> favoriGetAllModels = new List <FavoriGetAllModel>();

            foreach (var item in result)
            {
                var product = _productService.GetById(item.ProductId);
                FavoriGetAllModel favoriGetAllModel = new FavoriGetAllModel();
                favoriGetAllModel.Product  = product;
                favoriGetAllModel.FavoriId = item.Id;
                favoriGetAllModels.Add(favoriGetAllModel);
            }
            return(View("GetAll", favoriGetAllModels));
        }