コード例 #1
0
        internal void GetTournamentStats(Tournament tournament)
        {
            TournamentStats tournamentStats = new TournamentStats
            {
                TournamentId = tournament.TournamentId,
                TournamentName = tournament.TournamentName,
                TournamentDetails = string.Format("{0} ({1} - {2})", tournament.Venue.VenueName, tournament.StartDate.ToShortDateString(), tournament.EndDate.ToShortDateString()),
                TotalCompetitors = tournament.Competitors.Count,
                TotalDivisions = tournament.TournamentDivisions.Count,
                CompletedDivisions = tournament.TournamentDivisions.Count(m => m.IsCompleted),
                MedalsAwarded = tournament.TournamentDivisions.Count(m => m.MedalsReceived)
            };

            ViewBag.TournamentStats = tournamentStats;
        }
コード例 #2
0
        public ActionResult Create(Tournament tournament)
        {
            if (ModelState.IsValid)
            {
                populateDivisions(tournament);

                db.Tournaments.AddObject(tournament);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                initViewBag(tournament);
            }

            return View(tournament);
        }
コード例 #3
0
 private void initViewBag(Tournament tournament)
 {
     if (tournament.TournamentId != 0)
     {
         GetTournamentStats(tournament);
     }
     ViewBag.DivisionList = db.Divisions.OrderBy(m => m.RankId).ThenBy(m => m.DivisionTypeId).ThenBy(m => m.AgeGroup.FromAge).ThenBy(m => m.AgeGroup.ToAge);
     ViewBag.VenueId = new SelectList(db.Venues, "VenueId", "VenueName", tournament.VenueId);
     ViewBag.GrandChampionList = db.GrandChampions.OrderBy(m => m.RankId);
 }
コード例 #4
0
 private static void populateGrandChampions(Tournament tournament, WKSAEntities db)
 {
     tournament.GrandChampions.Clear();
     if (tournament.SelectedGrandChampionIds != null)
     {
         foreach (int grandChampionId in tournament.SelectedGrandChampionIds)
         {
             if (!tournament.GrandChampions.Any(m => m.GrandChampionId == grandChampionId))
             {
                 tournament.GrandChampions.Add(db.GrandChampions.Single(m => m.GrandChampionId == grandChampionId));
             }
         }
     }
 }
コード例 #5
0
 private static void populateDivisions(Tournament tournament)
 {
     if (tournament.SelectedDivisionIds != null)
     {
         foreach (int divisionId in tournament.SelectedDivisionIds)
         {
             if (!tournament.TournamentDivisions.Any(m => m.DivisionId == divisionId))
             {
                 tournament.TournamentDivisions.Add(new TournamentDivision
                 {
                     TournamentId = tournament.TournamentId,
                     DivisionId = divisionId
                 });
             }
         }
     }
 }
コード例 #6
0
        public ActionResult Edit(Tournament tournament)
        {
            if (ModelState.IsValid)
            {
                db.Tournaments.Attach(tournament);

                populateDivisions(tournament);
                populateGrandChampions(tournament, db);

                db.ObjectStateManager.ChangeObjectState(tournament, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Details", new { id = tournament.TournamentId });
            }
            else
            {
                initViewBag(tournament);
            }

            return View(tournament);
        }
コード例 #7
0
 /// <summary>
 /// Create a new Tournament object.
 /// </summary>
 /// <param name="tournamentId">Initial value of the TournamentId property.</param>
 /// <param name="tournamentName">Initial value of the TournamentName property.</param>
 /// <param name="venueId">Initial value of the VenueId property.</param>
 /// <param name="startDate">Initial value of the StartDate property.</param>
 /// <param name="endDate">Initial value of the EndDate property.</param>
 public static Tournament CreateTournament(global::System.Int32 tournamentId, global::System.String tournamentName, global::System.Int32 venueId, global::System.DateTime startDate, global::System.DateTime endDate)
 {
     Tournament tournament = new Tournament();
     tournament.TournamentId = tournamentId;
     tournament.TournamentName = tournamentName;
     tournament.VenueId = venueId;
     tournament.StartDate = startDate;
     tournament.EndDate = endDate;
     return tournament;
 }
コード例 #8
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Tournaments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTournaments(Tournament tournament)
 {
     base.AddObject("Tournaments", tournament);
 }