public ActionResult ViewImage(int id) { var viewModel = new ViewImageViewModel(); if (TempData["message"] != null) { viewModel.Message = (string)TempData["message"]; } if (!HasPermissionToView(id)) { viewModel.HasPermissionToView = false; viewModel.Image = new Image { Id = id }; } else { viewModel.HasPermissionToView = true; var db = new ImageDb(Properties.Settings.Default.ConStr); db.IncrementViewCount(id); var image = db.GetById(id); if (image == null) { return(RedirectToAction("Index")); } viewModel.Image = image; } return(View(viewModel)); }
public ActionResult ViewImage(int id, string password) { var db = new ImageDb(Properties.Settings.Default.ConStr); var image = db.GetById(id); if (image == null) { return(RedirectToAction("Index")); } if (password != image.Password) { TempData["message"] = "Invalid password"; } else { List <int> allowedIds; if (Session["allowedids"] == null) { allowedIds = new List <int>(); Session["allowedids"] = allowedIds; } else { allowedIds = (List <int>)Session["allowedids"]; } allowedIds.Add(id); } return(Redirect($"/image/viewimage?id={id}")); }
public ActionResult ViewImage(int id, string password) { var db = new ImageDb(_connectionString); var image = db.GetById(id); if (image == null) { return(RedirectToAction("Index")); } if (password != image.Password) { TempData["message"] = "Invalid password"; } else { var allowedIds = HttpContext.Session.Get <List <int> >("allowedids"); if (allowedIds == null) { allowedIds = new List <int>(); } allowedIds.Add(id); HttpContext.Session.Set("allowedids", allowedIds); } return(Redirect($"/home/viewimage?id={id}")); }