Esempio n. 1
0
        // GET: Tournament/Details/5
        // Define a list with divisions, fields and times.
        // Going through all the divisiosns, add some divisions with name and id.
        // Return a JSON object if there is a tournamet with a password, id, name, fields and divisions.
        // If there doesnt exist a tournament it will return a JSON object and get a error.
        public ActionResult Details(int id)
        {
            try
            {
                Validator validator = new Validator();
                Tournament t = db.TournamentSet.Find(id);
                List<object> divs = new List<object>();
                List<object> fields = new List<object>();
                List<object> times = new List<object>();

                //isScheduleReady - for frontend use.
                bool FrontendValidation = validator.IsScheduleReady(t.Id);

                // Get all divisions
                if (t.Divisions != null)
                {
                    foreach (Division d in t.Divisions)
                    {
                        divs.Add(new { Id = d.Id, Name = d.Name });
                    }
                }
                // Get all time intervals
                if (t.TimeIntervals != null)
                {
                    foreach (TimeInterval ti in t.TimeIntervals)
                    {
                        times.Add(new { Id = ti.Id, StartTime = ti.StartTime, EndTime = ti.EndTime });
                    }
                }
                // Get all fields
                if (t.Fields != null)
                {
                    foreach (Field f in t.Fields)
                    {
                        fields.Add(new { Id = f.Id, Name = f.Name, fieldSize = f.Size });
                    }
                }
                object obj = new { status = "success", Id = t.Id, Name = t.Name, Password = t.Password, Divisions = divs, TimeIntervals = times, Fields = fields, isValid = FrontendValidation, IsScheduled = t.IsScheduled };

                return Json(obj, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new { status = "error", message = "Could not find tournament", details = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 2
0
        // GET: Division/Details/5 - Fetches the details of the class, takes the "id" parameter to determine the corresponding Divison object.
        // Returns a Json object, which contains a copy of the corresponding Divisions variables.
        public ActionResult Details(int id)
        {
            try
            {
                Validator validator = new Validator();
                Division d = db.DivisionSet.Find(id);
                Tournament tourny = db.TournamentSet.Find(d.Tournament.Id);
                List<object> pools = new List<object>();
                List<object> teams = new List<object>();
                List<object> matches = new List<object>();
                List<object> finalslinks = new List<object>();

                bool FrontendValidation = validator.IsScheduleReady(tourny.Id);
                bool enoughTeams = false;

                // For finalstage
                string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

                // Get all pools in the division and their teams
                if (d.Pools != null)
                {
                    foreach (Pool p in d.Pools)
                    {
                        teams = new List<object>();
                        if (p.Teams.Count >= 2)
                        {
                            enoughTeams = true;
                        }

                        foreach (Team t in p.Teams)
                        {
                            teams.Add(new { Name = t.Name, Id = t.Id });
                        }
                        pools.Add(new { Id = p.Id, Name = p.Name, Teams = teams });
                    }
                }

                // Get matches in division
                if (d.DivisionTournament != null && d.DivisionTournament.TournamentStage.Count > 0)
                {
                    foreach (TournamentStage ts in d.DivisionTournament.TournamentStage)
                    {
                        if (ts.Matches.Count > 0)
                        {
                            foreach (Match m in ts.Matches)
                            {
                                Team team1 = m.Teams.ToList()[0];
                                Team team2 = m.Teams.ToList()[1];

                                matches.Add(new { Id = m.Id, Number = m.Number, StartTime = m.StartTime, /*FieldName = m.Field.Name,*/ Pool = new { Id = team1.Pool.Id, Name = team1.Pool.Name }, Team1 = new { name = team1.Name, Id = team1.Id }, Team2 = new { name = team2.Name, Id = team2.Id } });
                            }
                        }
                    }
                }

                // Get finals links
                if (d.FinalsLinks.Count > 0)
                {
                    foreach (FinalsLink fl in d.FinalsLinks)
                    {
                        finalslinks.Add(new { Id = fl.Id, PoolPlacement = fl.PoolPlacement, Finalsstage = letters[fl.Finalstage - 1] });
                    }
                }

                object obj = new { status = "success", Id = d.Id, Name = d.Name, FinalsStage = d.TournamentStructure, Pools = pools, Teams = teams, FieldSize = d.FieldSize, MatchDuration = d.MatchDuration, Matches = matches, FinalsLinks = finalslinks, isValid = FrontendValidation, isTeamsValid = enoughTeams };

                return Json(obj, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new
                {
                    status = "error",
                    message = "Could not find division",
                    details = ex.Message
                }, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 3
0
        // GET: Pool/Details/5 - The Details function will get the details of the Pool class, with the pools id as a parameter.
        // The function will get the details of the Teams, FavoriteFields and Matches for the pool.
        // A JSON object will be returned with the data and send an status message with it if it either have succeeded or failed.
        public ActionResult Details(int id)
        {
            try
            {
                Pool p = db.PoolSet.Find(id);
                Tournament tourny = db.TournamentSet.Find(p.Division.Tournament.Id);
                Validator validator = new Validator();

                List<object> teams = new List<object>();
                List<object> ffs = new List<object>();
                List<object> matches = new List<object>();

                bool FrontendValidation = validator.IsScheduleReady(tourny.Id);

                // Get teams in pool
                if (p.Teams != null)
                {
                    foreach (Team t in p.Teams)
                    {
                        teams.Add(new { Id = t.Id, Name = t.Name });
                    }
                }
                // Get favorite fields in pool
                if (p.FavoriteFields != null)
                {
                    foreach (Field f in p.FavoriteFields)
                    {
                        ffs.Add(new { Id = f.Id, Name = f.Name });
                    }
                }
                // Get matches in pool
                if (p.TournamentStage != null && p.TournamentStage.Matches.Count > 0)
                {
                    foreach (Match m in p.TournamentStage.Matches)
                    {
                        Team team1 = m.Teams.ToList()[0];
                        Team team2 = m.Teams.ToList()[1];
                        matches.Add(new { Id = m.Id, Number = m.Number, StartTime = m.StartTime, FieldName = m.Field.Name, Team1 = new { name = team1.Name, Id = team1.Id }, Team2 = new { name = team2.Name, Id = team2.Id } });
                    }
                }
                object obj = new { status = "success", Id = p.Id, Name = p.Name, FieldSize = p.Division.FieldSize, Teams = teams, FavoriteFields = ffs, Matches = matches, isValid = FrontendValidation };

                return Json(obj, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new { status = "error", message = "Could not find pool", details = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }