Пример #1
0
        public void FindTrophy(Races racesWithTrophy)
        {
            /*
             * NOTES:
             * If a series, then go right into SS_ResultSummary
             * If a race #, then go into SS_Result
             * If a race # is specified, must be a place number specified.
             * A place number should always be specified (with the current implementation)
             * Both SS_ResultSummary and SS_Result rely on FleetSeriesID.  So need to find that right off.
             */

            // Initialize (in case of multiple calls)
            Error            = string.Empty; // no error encountered...  yet.
            RaceNumberAssign = null;
            //this.BoatId = null;
            BoatName   = string.Empty;
            SailNumber = string.Empty;
            Skipper    = string.Empty;

            var ctx = new SailTallyDataContext();

            // Get the FleetSeriesID
            var fleetSeriesId = (from fs in ctx.SS_FleetSeries
                                 where fs.SeasonID == SeasonId &&
                                 fs.FleetID == FleetId &&
                                 fs.SeriesID == SeriesId
                                 select new { fs.FleetSeriesID }).Single().FleetSeriesID;

            // Determine if a series result or specific race
            if (RaceNumber == null || RaceNumber < 0)
            {
                // series result
                try
                {
                    var resultSummaries = (from rs in ctx.SS_ResultSummaries
                                           join b in ctx.SS_Boats on rs.BoatID equals b.BoatID
                                           where rs.SeasonID == SeasonId &&
                                           rs.FleetSeriesID == fleetSeriesId &&
                                           rs.Position == Place &&
                                           b.IsRegistered
                                           select new { rs.BoatID, rs.BoatName, rs.SailNumber, rs.Skipper });

                    if (resultSummaries.Any())
                    {
                        //this.BoatId = resultSummaries.Single().BoatID;
                        BoatName   = resultSummaries.Single().BoatName;
                        SailNumber = resultSummaries.Single().SailNumber;
                        Skipper    = resultSummaries.Single().Skipper;
                    }
                    else
                    {
                        Error = "No Results Found";
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Looking up: SeasonID=" + SeasonId + "  fleetSeriesID=" + fleetSeriesId + "  place=" + Place + "  Error: " + ex);
                }
            }
            else
            {
                // race result
                var assignRace = new AssignRace(SeasonId, fleetSeriesId, RaceNumber, Place, FindNextIfUnavail, racesWithTrophy);
                var raceFound  = assignRace.FindRace(); // TODO: Change
                if (raceFound)
                {
                    //this.BoatId = raceAssign.BoatID;
                    BoatName         = assignRace.BoatName;
                    SailNumber       = assignRace.SailNumber;
                    RaceNumberAssign = assignRace.RaceNumberAssigned;
                    Skipper          = assignRace.Skipper;
                }
                else
                {
                    Error = "No Trophy Assigned";
                }
            }

            _trophySearched = true;
        }
Пример #2
0
        public AssignRace(int seasonId, int fleetSeriesId, int?raceNumber, int?place, bool findNextAvailable, Races racesAlreadyAssigned)
        {
            _seasonId                   = seasonId;
            _fleetSeriesId              = fleetSeriesId;
            _raceNumber                 = raceNumber;
            _place                      = place;
            _findNextAvailable          = findNextAvailable;
            _racesAlreadyAssignedTrophy = racesAlreadyAssigned;

            // Find the maximum races
            var ctx = new SailTallyDataContext();

            var raceNumbers = from r in ctx.SS_Results
                              where r.SeasonID == _seasonId &&
                              r.FleetSeriesID == _fleetSeriesId &&
                              r.FinishPlace == _place
                              select r.RaceNumber;

            _maxRaces = (raceNumbers.Any() ? raceNumbers.Max() : 0);

            // find the fleet ID and series ID for the given FleetSeriesID (since that is what trophies use)
            var fleetSery = (from fs in ctx.SS_FleetSeries
                             where fs.FleetSeriesID == _fleetSeriesId &&
                             fs.SeasonID == _seasonId
                             select new { fs.FleetID, fs.SeriesID }).Single();

            _fleetId  = fleetSery.FleetID;
            _seriesId = fleetSery.SeriesID;
        }