예제 #1
0
        /// <summary>
        /// Initialises a new instance of the <see cref="PointsTableRowViewModel"/> class.
        /// </summary>
        /// <param name="athleteSeasonDetails">
        /// The model object for an athlete in the current season.
        /// </param>
        /// <param name="athleteDetails">
        /// The model object for an athlete.
        /// </param>
        /// <param name="pointsChanged">
        /// Callback method. This is intended to be called when the points change, to allow the
        /// parent view model to reorder the rows.
        /// </param>
        public PointsTableRowViewModel(
            IAthleteSeasonDetails athleteSeasonDetails,
            AthleteDetails athleteDetails,
            Action pointsChanged)
            : base(athleteDetails.Key, athleteDetails.Name)
        {
            this.athleteSeasonDetails = athleteSeasonDetails;
            this.athleteSeasonPoints  = athleteSeasonDetails.Points;
            this.athleteDetails       = athleteDetails;

            this.PB              = this.athleteDetails.PB.ToString();
            this.Points          = this.athleteSeasonPoints.TotalPoints;
            this.FinishingPoints = this.athleteSeasonPoints.FinishingPoints;
            this.PositionPoints  = this.athleteSeasonPoints.PositionPoints;
            this.BestPoints      = this.athleteSeasonPoints.BestPoints;
            this.RaceNumber      = this.athleteDetails.PrimaryNumber;
            this.NumberOfRuns    = this.athleteSeasonDetails.NumberOfAppearances;
            this.SB              = this.athleteSeasonDetails.SB.ToString();
            this.Sex             = this.athleteDetails.Sex.ToString();

            this.athleteSeasonDetails.ModelUpdateEvent += this.AthleteSeasonDetailsModelUpdateEvent;
            this.athleteSeasonPoints.ModelUpdateEvent  += this.AthleteSeasonPointsModelUpdateEvent;
            this.athleteDetails.ModelUpdateEvent       += this.AthleteDetailsModelUpdateEvent;
            this.pointsChangedCallback = pointsChanged;
        }
예제 #2
0
        // GET: Athlete/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Athlete athlete = db.Athletes.SqlQuery("select * from athletes where athleteid = @AthleteID", new SqlParameter("@AthleteID", id)).FirstOrDefault();

            if (athlete == null)
            {
                return(HttpNotFound());
            }

            // lvlup - create queries for  information about the coaches and events the athletes is involved with
            string       query         = "select * from coaches inner join coachathletes on coaches.coachid = coachathletes.coach_coachid where athlete_athleteid = @id";
            SqlParameter param         = new SqlParameter("@id", id);
            List <Coach> CoachAthletes = db.Coaches.SqlQuery(query, param).ToList();

            string            disQuery           = "select * from disciplines inner join disciplineathletes on disciplines.disciplineid = disciplineathletes.discipline_disciplineid where athlete_athleteid = @id";
            SqlParameter      sqlParam           = new SqlParameter("@id", id);
            List <Discipline> DisciplineAthletes = db.Disciplines.SqlQuery(disQuery, sqlParam).ToList();

            AthleteDetails viewmodel = new AthleteDetails();

            viewmodel.athlete     = athlete;
            viewmodel.coaches     = CoachAthletes;
            viewmodel.disciplines = DisciplineAthletes;


            return(View(viewmodel));
        }
        public ActionResult Athlete()
        {
            AthleteDetails athlete = new AthleteDetails
            {
                Name = "John smith",
                Age  = 29,
                City = "Boston"
            };

            return(View(athlete));
        }
예제 #4
0
        /// <summary>
        /// Calculate and populate the athletes points table.
        /// </summary>
        private void PopulatePointsTable()
        {
            Athletes athletesModel = this.model.Athletes;

            foreach (IAthleteSeasonDetails athlete in this.seasonModel.Athletes)
            {
                if (athlete.Points.TotalPoints > 0)
                {
                    double averagePoints = 0;
                    if (athlete.NumberOfAppearances > 0)
                    {
                        averagePoints = (double)athlete.Points.TotalPoints / (double)athlete.NumberOfAppearances;
                    }

                    TimeType pb            = athletesModel.GetPB(athlete.Key);
                    string   runningNumber =
                        athletesModel.GetAthleteRunningNumber(
                            athlete.Key);

                    AthleteDetails athleteModel =
                        athletesModel.GetAthlete(
                            athlete.Key);

                    if (athleteModel == null)
                    {
                        // TODO: Unexpected, it should be logged.
                        continue;
                    }

                    PointsTableRowViewModel newRow =
                        new PointsTableRowViewModel(
                            athlete,
                            athleteModel,
                            this.OrderTable);

                    this.PointsTable.Add(newRow);
                }
            }

            this.PointsTable =
                new ObservableCollection <PointsTableRowViewModel>(
                    this.PointsTable.OrderByDescending(
                        order => order.Points));
        }
예제 #5
0
        /// <summary>
        /// Reads the athlete details xml from file and decodes it.
        /// </summary>
        /// <param name="fileName">name of xml file</param>
        /// <returns>decoded athlete's details</returns>
        public Athletes ReadAthleteData(string fileName)
        {
            Athletes athleteData = new Athletes(this.seriesConfigManager);

            if (!File.Exists(fileName))
            {
                string error = string.Format("Athlete Data file missing, one created - {0}", fileName);
                Messenger.Default.Send(
                    new HandicapErrorMessage(
                        error));
                this.logger.WriteLog(error);
                SaveAthleteData(fileName, new Athletes(this.seriesConfigManager));
            }

            try
            {
                XDocument reader             = XDocument.Load(fileName);
                XElement  rootElement        = reader.Root;
                XElement  athleteListElement = rootElement.Element(c_athleteListLabel);

                var athleteList = from Athlete in athleteListElement.Elements(c_athleteLabel)
                                  select new
                {
                    key  = (string)Athlete.Attribute(c_keyLabel),
                    name = (string)Athlete.Attribute(c_nameLabel),
                    club = (string)Athlete.Attribute(c_clubLabel),
                    predeclaredHandicap = (string)Athlete.Attribute(predeclaredHandicapLabel),
                    sex            = (string)Athlete.Attribute(c_sexLabel),
                    signedConsent  = (string)Athlete.Attribute(SignedConsentAttribute),
                    active         = (string)Athlete.Attribute(activeLabel),
                    birthYear      = (string)Athlete.Attribute(birthYearAttribute),
                    birthMonth     = (string)Athlete.Attribute(birthMonthAttribute),
                    birthDay       = (string)Athlete.Attribute(birthDayAttribute),
                    runningNumbers = from RunningNumbers in Athlete.Elements(c_runningNumbersElement)
                                     select new
                    {
                        numbers = from Numbers in RunningNumbers.Elements(c_numberElement)
                                  select new
                        {
                            number = (string)Numbers.Attribute(c_numberAttribute)
                        }
                    },
                    timeList = from TimeList in Athlete.Elements(c_appearancesLabel)
                               select new
                    {
                        time = from Time in TimeList.Elements(c_timeLabel)
                               select new
                        {
                            time = (string)Time.Attribute(c_raceTimeLabel),
                            date = (string)Time.Attribute(c_raceDateLabel)
                        }
                    }
                };

                foreach (var athlete in athleteList)
                {
                    bool signedConsent = this.ConvertBool(athlete.signedConsent);
                    bool isActive      = this.ConvertBool(athlete.active);

                    int athleteKey =
                        (int)StringToIntConverter.ConvertStringToInt(
                            athlete.key);
                    TimeType athleteTime =
                        new TimeType(
                            athlete.predeclaredHandicap);
                    SexType            athleteSex         = StringToSexType.ConvertStringToSexType(athlete.sex);
                    List <Appearances> athleteAppearances = new List <Appearances>();

                    AthleteDetails athleteDetails =
                        new AthleteDetails(
                            athleteKey,
                            athlete.name,
                            athlete.club,
                            athleteTime,
                            athleteSex,
                            signedConsent,
                            isActive,
                            athleteAppearances,
                            athlete.birthYear,
                            athlete.birthMonth,
                            athlete.birthDay,
                            this.normalisationConfigManager);

                    foreach (var runningNumbers in athlete.runningNumbers)
                    {
                        foreach (var number in runningNumbers.numbers)
                        {
                            athleteDetails.AddNewNumber(number.number);
                        }
                    }

                    foreach (var raceTimeList in athlete.timeList)
                    {
                        foreach (var raceTime in raceTimeList.time)
                        {
                            athleteDetails.AddRaceTime(new Appearances(new RaceTimeType(raceTime.time),
                                                                       new DateType(raceTime.date)));
                        }
                    }

                    athleteData.SetNewAthlete(athleteDetails);
                }
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error reading athlete data: " + ex.ToString());

                athleteData = new Athletes(this.seriesConfigManager);
            }

            return(athleteData);
        }