zoukankan      html  css  js  c++  java
  • 排球积分程序(五)——Controller的编码

    VolleyballController

    using MvcVolleyball.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcVolleyball.Controllers
    {
        public class VolleyballController : Controller
        {
            //
            // GET: /Volleyball/
            private VolleyballDBContext db = new VolleyballDBContext();
            public ActionResult Index()//选择功能
            {
               
                return View();
            }
           public ActionResult Count()//选择队伍
            {
                ViewBag.teamId = new SelectList(db.teams, "teamId", "teamName");
                return View();
            }
            [HttpPost]
           public ActionResult Count(string team)//将选择队伍的信息接收病发送
            {
                team = Request.Form[0];
                if (team != null)
                {
                    return RedirectToAction("CountScore", new { teamId=team});
                }
                return View();
           }
            public ActionResult CountScore(string teamId)//进行计分
            {
                ViewBag.teamId = teamId;
                string [] teamsId=teamId.Split(',');
                int hostTeamId = Convert.ToInt32( teamsId[0]);
                int guestTeamId =Convert.ToInt32( teamsId[1]);
                var hostTeam = from d in db.teams
                               where d.teamId == hostTeamId
                               select d.teamName;
                var guestTeam = from d in db.teams
                                where d.teamId == guestTeamId
                                select d.teamName;
                foreach (var name in hostTeam)
                {
                    ViewBag.hostteam = name;
                }
                foreach (var name in guestTeam)
                {
                    ViewBag.guestteam = name;
                }
                var hostMemberlst = new List<string>();
                var guestMemberlst = new List<string>();
                var guestMember = from d in db.teamMembers
                                 where d.teamId == guestTeamId
                                 select d.name;
                var hostMember = from d in db.teamMembers
                                 where d.teamId == hostTeamId
                                 select d.name;
                hostMemberlst.AddRange(hostMember);
                guestMemberlst.AddRange(guestMember);
                ViewBag.hostMember = new SelectList(hostMemberlst);
                ViewBag.guestMember = new SelectList(guestMemberlst);
                var hostteamscores = from d in db.hostTeamScores
                                     where d.teamId == hostTeamId
                                     select d.hostTeamScore;
                foreach (var item in hostteamscores)
                {
                    ViewBag.hostteamscores = item;
                }
                var guestteamscores = from d in db.guestTeamScores
                                      where d.teamId == guestTeamId
                                      select d.guestTeamScore;
                foreach (var item in guestteamscores)
                {
                    ViewBag.guestteamscores = item;
                }
    
                return View();
            }
            public ActionResult addScore(string teamIds,HostTeamScore host,GuestTeamScore guest)//加分
            {
                host.hostTeamScore++;
                db.hostTeamScores.Add(host);
                db.SaveChanges();
                guest.guestTeamScore++;
                db.guestTeamScores.Add(guest);
                db.SaveChanges();
                return RedirectToAction("CountScore", new { teamId = teamIds });
            }
            public ActionResult Search()//查询,选择队伍
            {
                ViewBag.teamId = new SelectList(db.teams, "teamId", "teamName");
                return View();
            }
            [HttpPost]
            public ActionResult Search(string teamId)//将队伍Id传过去
            {
                teamId = Request.Form[0];
                return RedirectToAction("TeamScore",new{teamIds=int.Parse(teamId)});
            }
            public ActionResult TeamScore(int teamIds)//显示队伍得分信息
            {
                var teamScore = from d in db.hostTeamScores
                                where d.teamId == teamIds
                                select d;
    
                return View(teamScore.ToList());
            }
    
        }
    }
  • 相关阅读:
    onenote 使用手记0.3阶级
    尘埃落定:没有传说中k700i,官方只认可k700!
    【转】Ubuntu 9.10下安装Eclipse CDT 6.0
    四则运算
    文本内容统计
    《程序员修炼之道:从小工到专家》读后感(4)
    《程序员修炼之道:从小工到专家》读后感(5)
    多线程
    河北金力集团公文流转系统节选(2)
    动手动脑(6)文件和流
  • 原文地址:https://www.cnblogs.com/colorful-Ji/p/7074262.html
Copyright © 2011-2022 走看看