zoukankan      html  css  js  c++  java
  • MVC系列博客之排球计分(六)Controller的实现(二)

    上一篇博客没有完整的展现controller的代码,现在展示一下

    HomeController

    CoachController代码如下

     public class CoachController : Controller
        {
            private gDBContext db = new gDBContext();

            //
         

            public ActionResult Index()
            {
                return View(db.Students.ToList());
            }

            //
          

            public ActionResult Details(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }

            //
          

            public ActionResult Create()
            {
                return View();
            }

            //
          

            [HttpPost]
            public ActionResult Create(Score Score)
            {
                if (ModelState.IsValid)
                {
                    db.Students.Add(Score);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                return View(Score);
            }

     
           
            public ActionResult Edit(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }



            [HttpPost]
            public ActionResult Edit(Score score)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(score).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(score);
            }

            //


            public ActionResult Delete(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }

            //
           

            [HttpPost, ActionName("Delete")]
            public ActionResult DeleteConfirmed(int id)
            {
                Score gzscore = db.Students.Find(id);
                db.Students.Remove(score);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            protected override void Dispose(bool disposing)
            {
                db.Dispose();
                base.Dispose(disposing);
            }
        }

    至此,controller已全部完成。

  • 相关阅读:
    设计模式之美学习-接口隔离原则(七)
    设计模式之美学习-里式替换原则(六)
    设计模式之美学习-开闭原则(五)
    设计模式之美学习-设计原则之单一职责(四)
    设计模式之美学习-如何进行面向对象设计(三)
    ffmpeg 从内存中读取数据(或将数据输出到内存)
    CImage 对话框初始化时候显示透明 PNG
    RTMPdump(libRTMP) 源代码分析 9: 接收消息(Message)(接收视音频数据)
    RTMPdump(libRTMP) 源代码分析 8: 发送消息(Message)
    RTMPdump(libRTMP) 源代码分析 7: 建立一个流媒体连接 (NetStream部分 2)
  • 原文地址:https://www.cnblogs.com/shiyufan/p/7073652.html
Copyright © 2011-2022 走看看