コード例 #1
0
ファイル: CourseController.cs プロジェクト: tonykung06/mvc02
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                mvc02.Models.Course c = clist.Single(r => r.Id == id);
                clist.Remove(c);

                return(RedirectToAction("Index"));
            }
            catch
            {
                mvc02.Models.Course c = clist.Single(r => r.Id == id);

                return(View(c));
            }
        }
コード例 #2
0
ファイル: CourseController.cs プロジェクト: tonykung06/mvc02
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                mvc02.Models.Course c = new mvc02.Models.Course();
                c.Id    = clist.ElementAt(clist.Count - 1).Id + 1;
                c.Code  = collection["Code"];
                c.Name  = collection["Name"];
                c.Tutor = collection["Tutor"];
                c.Price = Convert.ToDecimal(collection["Price"]);
                clist.Add(c);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
ファイル: CourseController.cs プロジェクト: tonykung06/mvc02
        static CourseController()
        {
            mvc02.Models.Course c = new mvc02.Models.Course();
            c.Id       = 1;
            c.Code     = "L001";
            c.Name     = "Linux LPI Level 1";
            c.Category = "Server Admin";
            c.Tutor    = "Peter";
            c.Price    = 3000;
            clist.Add(c);

            c          = new mvc02.Models.Course();
            c.Id       = 2;
            c.Code     = "L002";
            c.Name     = "LPI Level 2";
            c.Category = "Server Admin";
            c.Tutor    = "Peter";
            c.Price    = 4000;
            clist.Add(c);
        }
コード例 #4
0
ファイル: CourseController.cs プロジェクト: tonykung06/mvc02
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                mvc02.Models.Course c = clist.Single(r => r.Id == id);
                c.Id    = clist.ElementAt(clist.Count - 1).Id + 1;
                c.Code  = collection["Code"];
                c.Name  = collection["Name"];
                c.Tutor = collection["Tutor"];
                c.Price = Convert.ToDecimal(collection["Price"]);

                return(RedirectToAction("Index"));
            }
            catch
            {
                mvc02.Models.Course c = clist.Single(r => r.Id == id);

                return(View(c));
            }
        }
コード例 #5
0
ファイル: CourseController.cs プロジェクト: tonykung06/mvc02
 public ActionResult Edit(int id)
 {
     mvc02.Models.Course c = clist.Single(r => r.Id == id);
     return(View(c));
 }