Inheritance: IDisposable
コード例 #1
0
        public ActionResult Index(int id=0)
        {
            using (var context = new MessagesContext())
            {
                var model = (from m in context.Messages where m.Id == id select m).SingleOrDefault();

                if (model == null)
                {
                    return new HttpNotFoundResult();
                }

                return View(model);
            }
        }
コード例 #2
0
        public ActionResult Protected(int id = 0)
        {
            using (var context = new MessagesContext())
            {
                var model = (from m in context.Messages where m.Id == id select m).SingleOrDefault();

                if (model == null)
                {
                    return new HttpNotFoundResult();
                }

                if (model.To != User.Identity.Name)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
                }

                return View("Index", model);
            }
        }