コード例 #1
0
        public ActionResult Create(RegisterCard competitor)
        {
            if (ModelState.IsValid)
            {
                db.RegisterCards.Add(competitor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(competitor));
        }
コード例 #2
0
        public ActionResult Create(Competition competition)
        {
            if (ModelState.IsValid)
            {
                db.Competitions.Add(competition);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(competition));
        }
コード例 #3
0
        public int CreateCompetition(string competitionName)
        {
            using (var db = new QueensFinalDb())
            {
                var competition = new Competition();
                competition.Name          = competitionName;
                competition.StartDateTime = DateTime.Now;

                db.Competitions.Add(competition);
                db.SaveChanges();

                return(competition.Id);
            }
        }
コード例 #4
0
        //public Competition GetCompetition(string competitionName)
        //{
        //	using (var db = new QueensFinalDb())
        //	{
        //		var competition = db.Competitions.Include(c => c.RegisterCards).FirstOrDefault(c => c.Name == competitionName);
        //		if (competition == null)
        //		{
        //			throw new Exception(String.Format("Could not find competition named {0}", competitionName));
        //		}

        //		return competition;
        //	}
        //}

        public void AddShot(int competitionId, int registerCardId, string distance, string shotNumber, Score score)
        {
            Debug.WriteLine("Competition: {0}, Competitor: {1}, Distance: {2}, Shot Number: {3}, Score: {4}",
                            competitionId, registerCardId, distance, shotNumber, score);

            using (var db = new QueensFinalDb())
            {
                var rc = db.RegisterCards.Find(registerCardId);

                // bit of reflection to avoid huge case statement
                var propName = distance
                               + (shotNumber.StartsWith("S") ? "Sighter" : "Shot")
                               + shotNumber.TrimStart(new[] { 'S' });
                var prop = typeof(RegisterCard).GetProperty(propName);
                prop.SetValue(rc, score);

                db.SaveChanges();

                Clients.All.RegisterShot(registerCardId, distance, shotNumber, score.DisplayValue(),
                                         rc.TotalPointsOff, rc.X900Total, rc.X1000Total, rc.GrandTotal);
            }
        }
コード例 #5
0
        public int AddRegisterCard(
            int competitionId,
            string competitorName,
            int competitorIndexNumber,
            int broughtForwardPoints,
            int broughtForwardVs)
        {
            using (var db = new QueensFinalDb())
            {
                var registerCard = new RegisterCard
                {
                    CompetitorName        = competitorName,
                    CompetitorIndexNumber = competitorIndexNumber,
                    BroughtForwardPoints  = broughtForwardPoints,
                    BroughtForwardVs      = broughtForwardVs
                };

                var competition = db.Competitions.Include(c => c.RegisterCards).Single(c => c.Id == competitionId);
                competition.RegisterCards.Add(registerCard);
                db.SaveChanges();

                return(registerCard.Id);
            }
        }