コード例 #1
0
 // GET: Coffees/Edit/5
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     // Get coffee object using FK JournalID
     Coffee coffee = (from c in db.Coffees
                      where c.JournalID == id
                      select c).FirstOrDefault();
     if (coffee == null)
     {
         return HttpNotFound();
     }
     Journal journal = db.Journals.Find(coffee.JournalID);
     if (journal == null)
     {
         return HttpNotFound();
     }
     // Journal record exists, make ViewModel and pass to edit view
     CoffeeViewModel cvm = new CoffeeViewModel()
     {
         Author = (from a in db.Authors
                   where a.AuthorID == journal.AuthorID
                   select a).FirstOrDefault(),
         Journal = journal,
         Coffee = coffee
     };
     // Set dropdownlist to preselected privacy type.
     ViewBag.PrivacyList = GetPrivacyList(journal.PrivacyType);
     return View(cvm);
 }
コード例 #2
0
        // GET: Coffees/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            // Get coffee object using FK JournalID sent from ActionLink
            Coffee coffee = (from c in db.Coffees
                             where c.JournalID == id
                             select c).FirstOrDefault();
            if (coffee == null)
            {
                return HttpNotFound();
            }

            Journal journal = db.Journals.Find(coffee.JournalID);

            if (journal == null)
            {
                return HttpNotFound();
            }
            // Journal record exists, make ViewModel and pass to edit view
            CoffeeViewModel cvm = new CoffeeViewModel()
            {
                Author = (from a in db.Authors
                          where a.AuthorID == journal.AuthorID
                          select a).FirstOrDefault(),
                Journal = journal,
                Coffee = coffee
            };
            return View(cvm);
        }