public IActionResult DeleteAd(int id) { SimpleAdDb db = new SimpleAdDb(_connectionString); db.Delete(id); return(Redirect("/")); }
public ActionResult DeleteAd(int id) { SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr); db.Delete(id); return(Redirect("/")); }
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")); }
public IActionResult MyAccount() { SimpleAdDb db = new SimpleAdDb(_connectionString); var userId = GetCurrentUserId().Value; return(View(db.GetAdsForUser(userId))); }
public ActionResult Index() { SimpleAdDb db = new SimpleAdDb(Properties.Settings.Default.ConStr); return(View(new HomePageViewModel { Ads = db.GetAds() })); }
public ActionResult NewAd(SimpleAd ad) { var userId = GetCurrentUserId(); ad.UserId = userId.Value; SimpleAdDb db = new SimpleAdDb(_connectionString); db.AddSimpleAd(ad); return(Redirect("/")); }
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")); }
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)); }
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")); }
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("/")); }
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")); }
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() })); }
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("/")); }
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")); }
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")); }
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("/")); }
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)); }
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("/")); }
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)); }
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()) }; }) })); }