Пример #1
0
        public IActionResult DeleteAd(int id)
        {
            SimpleAdDb db = new SimpleAdDb(_connectionString);

            db.Delete(id);
            return(Redirect("/"));
        }
Пример #2
0
        public ActionResult DeleteAd(int id)
        {
            SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr);

            db.Delete(id);
            return(Redirect("/"));
        }
Пример #3
0
        public IActionResult Index()
        {
            SimpleAdDb             db  = new SimpleAdDb(_connectionString);
            IEnumerable <SimpleAd> ads = db.GetAds();
            List <string>          ids = new List <string>();

            if (Request.Cookies["AdIds"] != null)
            {
                ids = Request.Cookies["AdIds"].Split(',').ToList();
            }

            var vm = new HomePageViewModel
            {
                Ads = ads.Select(ad => new AdViewModel
                {
                    Ad        = ad,
                    CanDelete = ids.Contains(ad.Id.ToString())
                })
            };

            if (TempData["message"] != null)
            {
                vm.Message = (string)TempData["Message"];
            }


            return(View(vm));
        }
        public IActionResult DeleteAd(int postId)
        {
            SimpleAdDb db = new SimpleAdDb();

            db.DeleteAd(postId);                                           //i don't know if it's necessary to remove the id from the cookie
            List <string> ids     = new List <string>();
            List <int>    postIds = new List <int>();

            if (Request.Cookies["postIds"] != null)               //if id is still on the cookie, it shouldn't do any harm
            {
                ids = Request.Cookies["postIds"].Split(',').ToList();
                foreach (string num in ids)
                {
                    postIds.Add(int.Parse(num));                        //filling a new list of ints with the string
                }
                postIds.Remove(postId);                                 //removing the deleted id
                string result = "";
                for (int i = 0; i < postIds.Count; i++)
                {
                    result += $"{postIds[i]}";                             //making a new string with no comma at the end
                    if (i < postIds.Count - 1)
                    {
                        result += ",";
                    }
                }
                Response.Cookies.Append("postIds", result);            //overriding the cookie with the new string
            }
            return(Redirect("/cookies/index"));
        }
Пример #5
0
        public IActionResult MyAccount()
        {
            SimpleAdDb db     = new SimpleAdDb(_connectionString);
            var        userId = GetCurrentUserId().Value;

            return(View(db.GetAdsForUser(userId)));
        }
Пример #6
0
        public ActionResult Index()
        {
            SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr);

            return(View(new HomePageViewModel
            {
                Ads = db.GetAds()
            }));
        }
Пример #7
0
        public ActionResult NewAd(SimpleAd ad)
        {
            var userId = GetCurrentUserId();

            ad.UserId = userId.Value;
            SimpleAdDb db = new SimpleAdDb(_connectionString);

            db.AddSimpleAd(ad);

            return(Redirect("/"));
        }
Пример #8
0
        public IActionResult DeleteAd(int postId)
        {
            SimpleAdDb db = new SimpleAdDb();

            db.DeleteAd(postId);
            if (HttpContext.Session.Get <List <int> >("adIds") != null)
            {
                HttpContext.Session.Get <List <int> >("adIds").Remove(postId);
            }
            return(Redirect("/home/index"));
        }
Пример #9
0
        public IActionResult Index()
        {
            SimpleAdDb       db = new SimpleAdDb();
            SessionViewModel vm = new SessionViewModel();

            vm.Posts = db.GetPosts();
            if (HttpContext.Session.Get <List <int> >("adIds") != null)
            {
                vm.Ids = HttpContext.Session.Get <List <int> >("adIds");
            }
            return(View(vm));
        }
Пример #10
0
        public IActionResult DeleteAd(int id)
        {
            List <int> ids = HttpContext.Session.Get <List <int> >("ListingIds");

            if (ids != null && ids.Contains(id))
            {
                SimpleAdDb db = new SimpleAdDb(_connectionString);
                db.Delete(id);
            }

            return(Redirect("/homesession/index"));
        }
Пример #11
0
        public IActionResult DeleteAd(int id)
        {
            SimpleAdDb db            = new SimpleAdDb(_connectionString);
            var        userIdForAd   = db.GetUserIdForAd(id);
            var        currentUserId = GetCurrentUserId().Value;

            if (currentUserId == userIdForAd)
            {
                db.Delete(id);
            }

            return(Redirect("/"));
        }
Пример #12
0
        public IActionResult NewAd(Post post)
        {                                                    //post came with a name, a phone number, and text
            SimpleAdDb db = new SimpleAdDb();

            db.AddPost(post);                                //now my post has the id, too
            List <int> adIds = HttpContext.Session.Get <List <int> >("adIds");

            if (adIds == null)
            {
                adIds = new List <int>();
            }
            adIds.Add(post.Id);
            HttpContext.Session.Set("adIds", adIds);
            return(Redirect("/home/index"));
        }
Пример #13
0
        public IActionResult Index()
        {
            SimpleAdDb db  = new SimpleAdDb(_connectionString);
            var        ads = db.GetAds();
            var        ids = HttpContext.Session.Get <List <int> >("ListingIds");

            return(View(new HomePageViewModel
            {
                Ads = ads.Select(ad => new AdViewModel
                {
                    Ad = ad,
                    CanDelete = ids != null && ids.Contains(ad.Id)
                }).ToList()
            }));
        }
Пример #14
0
        public ActionResult NewAd(SimpleAd ad)
        {
            SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr);

            db.AddSimpleAd(ad);
            string     ids    = "";
            HttpCookie cookie = Request.Cookies["AdIds"];

            if (cookie != null)
            {
                ids = $"{cookie.Value},";
            }
            ids += ad.Id;
            Response.Cookies.Add(new HttpCookie("AdIds", ids));
            return(Redirect("/"));
        }
Пример #15
0
        public IActionResult NewAd(SimpleAd ad)
        {
            SimpleAdDb db = new SimpleAdDb(_connectionString);

            db.AddSimpleAd(ad);

            List <int> ids = HttpContext.Session.Get <List <int> >("ListingIds");

            if (ids == null)
            {
                ids = new List <int>();
            }
            ids.Add(ad.Id);
            HttpContext.Session.Set("ListingIds", ids);
            return(Redirect("/homesession/index"));
        }
Пример #16
0
        public IActionResult Index()
        {
            SimpleAdDb             db  = new SimpleAdDb(_connectionString);
            IEnumerable <SimpleAd> ads = db.GetAds();
            var currentUserId          = GetCurrentUserId();
            var vm = new HomePageViewModel
            {
                Ads = ads.Select(ad => new AdViewModel
                {
                    Ad        = ad,
                    CanDelete = currentUserId != null && ad.UserId == currentUserId
                })
            };

            return(View(vm));
        }
        public IActionResult NewAd(Post post)
        {
            SimpleAdDb db = new SimpleAdDb();

            db.AddPost(post);
            string postIds = "";

            if (Request.Cookies["postIds"] != null)
            {
                postIds += Request.Cookies["postIds"];              //getting the previous cookie
                postIds += ",";                                     //adding a comma to the end of it (not to the new one after)
            }
            postIds += $"{post.Id}";                                //adding the newest id to the string
            Response.Cookies.Append("postIds", postIds);            //overriding the cookie with the new string
            return(Redirect("/cookies/index"));
        }
Пример #18
0
        public ActionResult NewAd(SimpleAd ad)
        {
            SimpleAdDb db = new SimpleAdDb(_connectionString);

            db.AddSimpleAd(ad);
            string ids    = "";
            var    cookie = Request.Cookies["AdIds"];

            if (cookie != null)
            {
                ids = $"{cookie},";
            }
            ids += ad.Id;
            Response.Cookies.Append("AdIds", ids);

            return(Redirect("/"));
        }
Пример #19
0
        public ActionResult AdDetails(int adId)
        {
            SimpleAdDb db        = new SimpleAdDb(Properties.Settings.Default.ConStr);
            var        viewModel = new AdDetailsViewModel
            {
                Ad = db.GetById(adId)
            };
            var cookie = Request.Cookies["AdIds"];

            if (cookie != null)
            {
                var ids = cookie.Value.Split(',').Select(int.Parse);
                viewModel.ShowDeleteButton = ids.Any(i => i == adId);
            }

            return(View(viewModel));
        }
        public IActionResult Index()
        {
            SimpleAdDb       db = new SimpleAdDb();
            SessionViewModel vm = new SessionViewModel();

            vm.Posts = db.GetPosts();
            List <string> ids = new List <string>();

            if (Request.Cookies["postIds"] != null)
            {
                ids = Request.Cookies["postIds"].Split(',').ToList(); //setting a string to the result of the cookie
                                                                      //splitting that string into a list of sep #s
                foreach (string num in ids)
                {                                                     //parsing the nums and adding them to the list of ints that will go to index.cshtml
                    vm.Ids.Add(int.Parse(num));
                }
            }
            return(View(vm));
        }
Пример #21
0
        public ActionResult NewAd(SimpleAd ad, IEnumerable <HttpPostedFileBase> adImages)
        {
            SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr);

            ad.Images = adImages?
                        .Where(i => i != null)
                        .Select(i => new Image {
                FileName = SaveFile(i)
            });
            db.AddSimpleAd(ad);
            string ids    = "";
            var    cookie = Request.Cookies["AdIds"];

            if (cookie != null)
            {
                ids = $"{cookie.Value},";
            }
            ids += ad.Id;
            Response.Cookies.Add(new HttpCookie("AdIds", ids));
            return(Redirect("/"));
        }
Пример #22
0
        public IActionResult Index()
        {
            var             db  = new SimpleAdDb(_connectionString);
            List <SimpleAd> ads = db.GetAds();
            List <string>   ids = new List <string>();

            if (Request.Cookies["AdIds"] != null)
            {
                ids = Request.Cookies["AdIds"].Split(',').ToList();
            }

            var vm = new HomePageViewModel
            {
                Ads = ads.Select(ad => new AdViewModel
                {
                    Ad        = ad,
                    CanDelete = ids.Contains(ad.Id.ToString())
                }).ToList()
            };

            return(View(vm));
        }
Пример #23
0
        public ActionResult Index()
        {
            SimpleAdDb             db  = new SimpleAdDb(Properties.Settings.Default.ConStr);
            IEnumerable <SimpleAd> ads = db.GetAds();
            List <string>          ids = new List <string>();

            if (Request.Cookies["AdIds"] != null)
            {
                ids = Request.Cookies["AdIds"].Value.Split(',').ToList();
            }

            return(View(new HomePageViewModel
            {
                Ads = ads.Select(ad =>
                {
                    return new AdViewModel
                    {
                        Ad = ad,
                        CanDelete = ids.Contains(ad.Id.ToString())
                    };
                })
            }));
        }