Beispiel #1
0
        private async Task EnsureCompetitorIsInFleet(dbObj.Competitor competitor, Fleet fleet)
        {
            var dbFleet = await _dbContext.Fleets.SingleAsync(f => f.Id == fleet.Id)
                          .ConfigureAwait(false);

            var Exists = dbFleet.CompetitorFleets != null &&
                         dbFleet.CompetitorFleets.Any(cf => cf.CompetitorId == competitor.Id);

            if (!Exists)
            {
                if (dbFleet.CompetitorFleets == null)
                {
                    dbFleet.CompetitorFleets = new List <dbObj.CompetitorFleet>();
                }
                dbFleet.CompetitorFleets.Add(new dbObj.CompetitorFleet
                {
                    FleetId      = dbFleet.Id,
                    CompetitorId = competitor.Id
                });
            }
        }
Beispiel #2
0
        private bool AreCompetitorsMatch(
            Competitor competitor,
            dbObj.Competitor dbComp)
        {
            bool matchFound;

            matchFound = competitor.Id != Guid.Empty &&
                         competitor.Id == dbComp.Id;

            matchFound = matchFound || !(String.IsNullOrWhiteSpace(competitor.SailNumber)) &&
                         !(String.IsNullOrWhiteSpace(dbComp.SailNumber)) &&
                         competitor.SailNumber.Equals(dbComp.SailNumber, StringComparison.InvariantCultureIgnoreCase);
            matchFound = matchFound || !(String.IsNullOrWhiteSpace(competitor.SailNumber)) &&
                         !(String.IsNullOrWhiteSpace(dbComp.AlternativeSailNumber)) &&
                         competitor.SailNumber.Equals(dbComp.AlternativeSailNumber, StringComparison.InvariantCultureIgnoreCase);

            matchFound = matchFound || !(String.IsNullOrWhiteSpace(competitor.AlternativeSailNumber)) &&
                         !(String.IsNullOrWhiteSpace(dbComp.SailNumber)) &&
                         competitor.AlternativeSailNumber.Equals(dbComp.SailNumber, StringComparison.InvariantCultureIgnoreCase);
            matchFound = matchFound || !(String.IsNullOrWhiteSpace(competitor.AlternativeSailNumber)) &&
                         !(String.IsNullOrWhiteSpace(dbComp.AlternativeSailNumber)) &&
                         competitor.AlternativeSailNumber.Equals(dbComp.AlternativeSailNumber, StringComparison.InvariantCultureIgnoreCase);
            return(matchFound);
        }
Beispiel #3
0
        private void AddFleetsToDbObject(CompetitorDto comp, Db.Competitor dbObject)
        {
            dbObject.CompetitorFleets ??= new List <Db.CompetitorFleet>();

            if (comp.FleetIds == null)
            {
                return;
            }
            // remove fleets
            foreach (var existingFleet in dbObject.CompetitorFleets.ToList())
            {
                if (comp.FleetIds.All(f => f != existingFleet.FleetId))
                {
                    dbObject.CompetitorFleets.Remove(existingFleet);
                }
            }

            // add fleets
            foreach (var fleetId in comp.FleetIds)
            {
                if (dbObject.CompetitorFleets
                    .Any(cf => cf.FleetId == fleetId))
                {
                    continue;
                }
                var dbFleet = _dbContext.Fleets
                              .SingleOrDefault(f => f.Id == fleetId &&
                                               f.ClubId == comp.ClubId);
                if (dbFleet != null)
                {
                    dbObject.CompetitorFleets.Add(new Db.CompetitorFleet
                    {
                        Competitor   = dbObject,
                        CompetitorId = dbObject.Id,
                        Fleet        = dbFleet,
                        FleetId      = dbFleet.Id
                    });
                }

                // Create new fleets here if needed.
            }

            //add built in club fleets
            var autoAddFleets = GetClubAutomaticFleets(
                comp.ClubId,
                comp.BoatClassId);

            foreach (var dbFleet in autoAddFleets)
            {
                if (dbObject.CompetitorFleets
                    .Any(cf => cf.FleetId == dbFleet.Id))
                {
                    continue;
                }
                dbObject.CompetitorFleets.Add(
                    new Db.CompetitorFleet
                {
                    Competitor = dbObject,
                    Fleet      = dbFleet
                });
            }
        }
Beispiel #4
0
        private void AddFleetsToDbObject(Competitor comp, Db.Competitor dbObject)
        {
            if (comp.Fleets == null)
            {
                return;
            }

            // remove fleets
            dbObject.CompetitorFleets ??= new List <Db.CompetitorFleet>();

            foreach (var existingFleet in dbObject.CompetitorFleets.ToList())
            {
                if (comp.Fleets.All(f => f.Id != existingFleet.FleetId))
                {
                    dbObject.CompetitorFleets.Remove(existingFleet);
                }
            }

            // add fleets
            foreach (var fleet in comp.Fleets)
            {
                if (dbObject.CompetitorFleets
                    .Any(cf => cf.FleetId == fleet.Id))
                {
                    // already there, so skip.
                    continue;
                }
                var dbFleet = _dbContext.Fleets
                              .SingleOrDefault(f => f.Id == fleet.Id &&
                                               f.ClubId == comp.ClubId &&
                                               f.FleetType != Api.Enumerations.FleetType.AllBoatsInClub &&
                                               f.FleetType != Api.Enumerations.FleetType.SelectedClasses);
                if (dbFleet != null)
                {
                    dbObject.CompetitorFleets.Add(new Db.CompetitorFleet
                    {
                        Competitor = dbObject,
                        Fleet      = dbFleet
                    });
                }
            }

            //add built in club fleets
            var autoAddFleets = GetClubAutomaticFleets(
                comp.ClubId,
                comp.BoatClassId);

            foreach (var dbFleet in autoAddFleets)
            {
                if (dbObject.CompetitorFleets
                    .Any(cf => cf.FleetId == dbFleet.Id))
                {
                    // already there, move on.
                    continue;
                }
                dbObject.CompetitorFleets.Add(
                    new Db.CompetitorFleet
                {
                    Competitor = dbObject,
                    Fleet      = dbFleet
                });
            }
        }