コード例 #1
0
        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));
        }