Commits

Tairan Wang committed c3cd481

controller code cleanup.

Comments (0)

Files changed (1)

IntranetFAQ.Web/Controllers/FaqController.cs

 
         public ActionResult Index()
         {
-            List<Faq> faqList = (from faq in faqContext.Faqs
-                                     orderby faq.LastModified descending
-                                     select faq).ToList<Faq>();
-            return View(faqList);
+            var faqList = from faq in faqContext.Faqs
+                          orderby faq.LastModified descending
+                          select faq;
+            return View(faqList.ToList<Faq>());
         }
 
         //
 
         public ActionResult Details(int id)
         {
-            var f = (from faq in faqContext.Faqs
-                       where faq.Id == id
-                       select faq).First<Faq>();
-            return View(f);
+            var faq = from item in faqContext.Faqs
+                    where item.Id == id
+                    select item;
+            return View(faq.Single<Faq>());
         }
 
         //
 
         public ActionResult Edit(int id)
         {
-            Faq faq = (from item in faqContext.Faqs
-                       where item.Id == id
-                       select item).First<Faq>();
-            return View(faq);
+            var faq = from item in faqContext.Faqs
+                      where item.Id == id
+                      select item;
+            return View(faq.Single<Faq>());
         }
 
         //
             try
             {
                 // TODO: Add update logic here
-                Faq faq = (from item in faqContext.Faqs
+                var faq = (from item in faqContext.Faqs
                            where item.Id == id
-                           select item).First<Faq>();
+                           select item).Single<Faq>();
+                
                 faq.Title = collection["Title"];
                 faq.Content = collection["Content"];
                 faq.LastModified = DateTime.Now;
 
                 faqContext.SaveChanges();
+
                 return RedirectToAction("Index");
             }
             catch