public IActionResult DeletePost(int Id)
        {
            ManageAds db = new ManageAds(_conn);

            db.DeletePost(Id);
            return(Redirect("/Cookie/Index"));
        }
예제 #2
0
        public IActionResult AddPost(AdPost newAd)
        {
            ManageAds   db = new ManageAds(_conn);
            AdViewModel vm = new AdViewModel();

            db.AddNewAd(newAd);

            idList = HttpContext.Session.Get <List <int> >("adIdSession");

            if (idList == null)
            {
                idList = new List <int> {
                    newAd.Id
                };
            }

            else
            {
                idList.Add(newAd.Id);
            }

            HttpContext.Session.Set <List <int> >("adIdSession", idList);

            return(Redirect("/Home/Index"));
        }
예제 #3
0
        public IActionResult Index()
        {
            AdViewModel vm = new AdViewModel();
            ManageAds   db = new ManageAds(_conn);

            vm.Ads     = db.GetPosts();
            vm.Session = HttpContext.Session.Get <List <int> >("adIdSession");
            return(View(vm));
        }
예제 #4
0
        public IActionResult DeletePost(int Id)
        {
            idList = HttpContext.Session.Get <List <int> >("adIdSession");
            if (idList != null && idList.Contains(Id))
            {
                ManageAds db = new ManageAds(_conn);
                db.DeletePost(Id);
            }

            return(Redirect("/Home/Index"));
        }
        public IActionResult Index()
        {
            AdViewModelCookies vm = new AdViewModelCookies();
            ManageAds          db = new ManageAds(_conn);

            vm.Ads = db.GetPosts();
            string ids = Request.Cookies["ids"];

            if (!String.IsNullOrEmpty(ids)) //(ids != null)
            {
                vm.Cookie = ids.Split(',').ToList();
            }
            return(View(vm));
        }
        public IActionResult AddPost(AdPost newAd)
        {
            ManageAds   db = new ManageAds(_conn);
            AdViewModel vm = new AdViewModel();

            db.AddNewAd(newAd);

            string idList = Request.Cookies["ids"];

            if (idList == null)
            {
                idList = $"{newAd.Id}";
            }
            else
            {
                idList += $",{newAd.Id}";
            }

            Response.Cookies.Append("ids", $"{idList}");

            return(Redirect("/Cookie/Index"));
        }