• 控制器的设计与实现(五)


     创建army实体模型类的控制器armyController

     

    添加了队伍模型的添加,编辑,详情,删除几种方法

     相关代码如下

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Data;
      4 using System.Linq;
      5 using System.Web;
      6 using System.Web.Mvc;
      7 using 排球计分规则.Models;
      8 
      9 namespace 排球计分规则.Controllers
     10 {
     11     public class armyController : Controller
     12     {
     13         private armyDBContext db = new armyDBContext();
     14 
     15         //
     16         // GET: /Team/
     17 
     18         public ActionResult Index()
     19         {
     20             return View(db.army.ToList());
     21         }
     22 
     23         //private ActionResult View(List<Models.army> list)
     24         //{
     25         //    throw new NotImplementedException();
     26         //}
     27 
     28         //
     29         // GET: /Team/Details/5
     30 
     31         public ActionResult Details(int id = 0)
     32         {
     33             army team = db.army.Find(id);
     34             if (team == null)
     35             {
     36                 return HttpNotFound();
     37             }
     38             return View(team);
     39         }
     40 
     41         //private ActionResult HttpNotFound()
     42         //{
     43         //    throw new NotImplementedException();
     44         //}
     45 
     46         //
     47         // GET: /Team/Create
     48 
     49         public ActionResult Create()
     50         {
     51             return View();
     52         }
     53 
     54         //
     55         // POST: /Team/Create
     56 
     57         [HttpPost]
     58         public ActionResult Create(army team)
     59         {
     60             if (ModelState.IsValid)
     61             {
     62                 db.army.Add(team);
     63                 db.SaveChanges();
     64                 return RedirectToAction("Index");
     65             }
     66 
     67             return View(team);
     68         }
     69 
     70         //
     71         // GET: /Team/Edit/5
     72 
     73         public ActionResult Edit(int id = 0)
     74         {
     75             army team = db.army.Find(id);
     76             if (team == null)
     77             {
     78                 return HttpNotFound();
     79             }
     80             return View(team);
     81         }
     82 
     83         //
     84         // POST: /Team/Edit/5
     85 
     86         [HttpPost]
     87         public ActionResult Edit(army team)
     88         {
     89             if (ModelState.IsValid)
     90             {
     91                 db.Entry(team).State = EntityState.Modified;
     92                 db.SaveChanges();
     93                 return RedirectToAction("Index");
     94             }
     95             return View(team);
     96         }
     97 
     98         //
     99         // GET: /Team/Delete/5
    100 
    101         public ActionResult Delete(int id = 0)
    102         {
    103             army team = db.army.Find(id);
    104             if (team == null)
    105             {
    106                 return HttpNotFound();
    107             }
    108             return View(team);
    109         }
    110 
    111         //
    112         // POST: /Team/Delete/5
    113 
    114         [HttpPost, ActionName("Delete")]
    115         public ActionResult DeleteConfirmed(int id)
    116         {
    117             army team = db.army.Find(id);
    118             db.army.Remove(team);
    119             db.SaveChanges();
    120             return RedirectToAction("Index");
    121         }
    122 
    123         protected override void Dispose(bool disposing)
    124         {
    125             db.Dispose();
    126             base.Dispose(disposing);
    127         }
    128     }
    129 }

     接下来在Armys添加视图以便于了解详细得分

  • 相关阅读:
    Core3.0部署后访问接口提示500.30
    Core3.0返回的Json数据大小写格式问题
    linux内核分析之fork()
    【转】【机器人学:运动规划】OMPL开源运动规划库的安装和demo
    【转】毫米波雷达和激光雷达的对比
    [转]开发者需要的 9 款代码比较工具
    [转]关于特征点法、直接法、光流法slam的对比
    [转]【视觉 SLAM-2】 视觉SLAM- ORB 源码详解 2
    [转]ORB特征提取-----FAST角点检测
    [转]图像金字塔
  • 原文地址:https://www.cnblogs.com/chen-bo/p/7065824.html
Copyright © 2020-2023  润新知