Ejemplo n.º 1
0
 public void AddCourtToScoring(OpusContext db1, OpusContext db3, string date, CourtAssignment item)
 {
     //Load a record into Scores table for each player (4 per item found)
     //The data being used comes from the CourtAssignment data which keeps player namses as First, Last (STC Rank)
     //The code below just grabs First and Last for use in the Scoring table.
     int id = Convert.ToInt32(item.Player1ID);
     OpusPlayer player = db3.OpusPlayers.Single(q => q.PlayerID == id);
     Scoring sRow = new Scoring
     {
         Date = date,
         First = player.First,
         Last = player.Last,
         Group = player.Group,
         STCPlayerID = player.PlayerID,
         Name = item.Player1
     };
     db1.Scores.Add(sRow);
     id = Convert.ToInt32(item.Player2ID);
     player = db3.OpusPlayers.Single(q => q.PlayerID == id);
     sRow = new Scoring
     {
         Date = date,
         First = player.First,
         Last = player.Last,
         Group = player.Group,
         STCPlayerID = player.PlayerID,
         Name = item.Player2
     };
     db1.Scores.Add(sRow);
     id = Convert.ToInt32(item.Player3ID);
     player = db3.OpusPlayers.Single(q => q.PlayerID == id);
     sRow = new Scoring
     {
         Date = date,
         First = player.First,
         Last = player.Last,
         Group = player.Group,
         STCPlayerID = player.PlayerID,
         Name = item.Player3
     };
     db1.Scores.Add(sRow);
     id = Convert.ToInt32(item.Player4ID);
     player = db3.OpusPlayers.Single(q => q.PlayerID == id);
     sRow = new Scoring
     {
         Date = date,
         First = player.First,
         Last = player.Last,
         Group = player.Group,
         STCPlayerID = player.PlayerID,
         Name = item.Player4
     };
     db1.Scores.Add(sRow);
 }
Ejemplo n.º 2
0
        public ActionResult Index(string date, string sortOrder)
        {
            string sGroup = Session["Group"].ToString();
            //if (Session["playedDates"] == null)
            //{
                // Get unique dates OPUS Played
                //List<SelectListItem> items = new List<SelectListItem>();
                //var dates = db.Assignments;
                //var result = (from m in dates where m.Group.Equals(sGroup) select m.Date).Distinct().ToList();
                //foreach (var item in result) items.Add(new SelectListItem { Text = item, Value = item });
                //Session["playedDates"] = items;
            //}
            ViewBag.PlayedDates = util.GetCourtDates(sGroup);

            if (Session["playedDate"] == null)
            {
                if (date != null)
                {
                    Session["playedDate"] = date;
                }
            }
            else date = Session["playedDate"].ToString();

            var query = from a in db.Scores
                        where a.Date.Equals(date) && a.Group.Equals(sGroup)
                        select a;
            int i = 0;
            foreach (var item in query) i++;

            if (i == 0 && date != null)
            {
                OpusContext db1 = new OpusContext();
                //Add player data from Assignment table
                var assignmentData = from a in db.Assignments
                                     where a.Date.Equals(date) && a.Group.Equals(sGroup)
                                     select a;
                foreach (var item in assignmentData)
                {
                    //Load a record into Scores table for each player (4 per item found)
                    util.AddCourtToScoring(db1, db3, date, item);
                }
                db1.SaveChanges();
            }

            ViewBag.CurrentDate = date;
            ViewBag.OpusRankSortParm = String.IsNullOrEmpty(sortOrder) ? "stc_desc" : "";
            ViewBag.FirstSortParm = sortOrder == "First" ? "first_desc" : "First";
            ViewBag.LastSortParm = sortOrder == "Last" ? "last_desc" : "Last";
            //ViewBag.OpusRankSortParm = sortOrder == "OpusRank" ? "stc_desc" : "OpusRank";
            ViewBag.PercentWonSortParm = sortOrder == "PercentWon" ? "per_desc" : "PercentWon";
            ViewBag.OverallPercentWonSortParm = sortOrder == "OverallPercentWon" ? "oper_desc" : "OverallPercentWon";

            var scores = from s in db.Scores
                         where s.Date.Equals(date) && s.Group.Equals(sGroup)
                         select s;
            switch (sortOrder)
            {
                case "first_desc":
                    scores = scores.OrderByDescending(s => s.First);
                    break;
                case "First":
                    scores = scores.OrderBy(s => s.First);
                    break;
                case "last_desc":
                    scores = scores.OrderByDescending(s => s.Last);
                    break;
                case "Last":
                    scores = scores.OrderBy(s => s.Last);
                    break;
                case "stc_desc":
                    scores = scores.OrderByDescending(s => s.OpusRank);
                    break;
                //case "OpusRank":
                //    scores = scores.OrderBy(s => s.OpusRank);
                //    break;
                case "per_desc":
                    scores = scores.OrderByDescending(s => s.PercentWon);
                    break;
                case "PercentWon":
                    scores = scores.OrderBy(s => s.PercentWon);
                    break;
                case "oper_desc":
                    scores = scores.OrderByDescending(s => s.OverallPercentWon);
                    break;
                case "OverallPercentWon":
                    scores = scores.OrderBy(s => s.OverallPercentWon);
                    break;
                default:
                    scores = scores.OrderBy(s => s.OpusRank);
                    break;
            }
            if(sortOrder != string.Empty) return View(scores.ToList());
            return View(query.ToList());
        }