public string AddAthlete(string gymName, string athleteType, string athleteName, string motivation, int numberOfMedals) { IAthlete athlete; IGym gym = this.gyms.First(x => x.Name == gymName); if (athleteType == nameof(Boxer)) { athlete = new Boxer(athleteName, motivation, numberOfMedals); } else if (athleteType == nameof(Weightlifter)) { athlete = new Weightlifter(athleteName, motivation, numberOfMedals); } else { throw new InvalidOperationException(InvalidAthleteType); } var notAppropriateForBoxer = !(gym.GetType().Name == nameof(BoxingGym) && athleteType == nameof(Boxer)); var notAppropriateForWeightlifter = !(gym.GetType().Name == nameof(WeightliftingGym) && athleteType == nameof(Weightlifter)); if (notAppropriateForBoxer && notAppropriateForWeightlifter) { return(InappropriateGym); } gym.AddAthlete(athlete); return(string.Format(EntityAddedToGym, athleteType, gymName)); }
public string AddAthlete(string gymName, string athleteType, string athleteName, string motivation, int numberOfMedals) { IAthlete athlete; switch (athleteType) { case nameof(Boxer): athlete = new Boxer(athleteName, motivation, numberOfMedals); break; case nameof(Weightlifter): athlete = new Weightlifter(athleteName, motivation, numberOfMedals); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidAthleteType); } IGym gym = this.gyms.First(g => g.Name == gymName); if (athlete.GetType().Name == nameof(Boxer) && gym.GetType().Name == nameof(BoxingGym)) { gym.AddAthlete(athlete); } else if (athlete.GetType().Name == nameof(Weightlifter) && gym.GetType().Name == nameof(WeightliftingGym)) { gym.AddAthlete(athlete); } else { return(OutputMessages.InappropriateGym); } return(string.Format(OutputMessages.EntityAddedToGym, athleteType, gymName)); }
public string EquipmentWeight(string gymName) { IGym gym = this.gyms.First(g => g.Name == gymName); double value = gym.EquipmentWeight; return(string.Format(OutputMessages.EquipmentTotalWeight, gymName, value)); }
public string TrainAthletes(string gymName) { IGym gym = this.gyms.First(g => g.Name == gymName); gym.Exercise(); return(string.Format(OutputMessages.AthleteExercise, gym.Athletes.Count)); }
public static GymContext ConvertToGymContext(this IGym gym) { GymContext context = new GymContext(); context.Id = gym.Id.ToString(); context.UserName = gym.UserName; context.UserType = gym.UserType; context.Created = gym.Created; context.IsActive = gym.IsActive; context.Email = gym.Email; context.Description = gym.Description; context.Location = gym.Location.ConvertToLocationContext(); context.Modified = gym.Modified; context.Password = gym.Password; context.PhoneNumber = gym.PhoneNumber; context.PhoneVisibility = gym.PhoneVisibility; context.UserVisibility = gym.UserVisibility; context.ExperienceYears = gym.ExperienceYears; context.Expertise = gym.Expertise; context.ParkingLot = gym.ParkingLot; context.Price = gym.Price; context.Showers = gym.Showers; context.Reputation = gym.Reputation; context.Name = gym.Name; context.Birthday = gym.Birthday; return(context); }
public string TrainAthletes(string gymName) { IGym gym = this.gyms.First(x => x.Name == gymName); gym.Exercise(); return(string.Format(AthleteExercise, gym.Athletes.Count)); }
public void Setup() { this.gym = new FitGym(); this.mem1 = new Member(1, "a", new DateTime(2020, 3, 3), 2); this.mem2 = new Member(2, "b", new DateTime(2020, 2, 2), 1); this.mem3 = new Member(3, "c", new DateTime(2020, 1, 1), 3); this.mem4 = new Member(4, "c", new DateTime(2010, 1, 1), 3); this.mem5 = new Member(5, "d", new DateTime(2022, 1, 1), 3); this.train1 = new Trainer(1, "a", 2); this.train2 = new Trainer(2, "b", 3); this.train3 = new Trainer(3, "c", 1); this.train4 = new Trainer(4, "d", 0); this.train5 = new Trainer(5, "d", 99); }
public async Task <ServiceResponse> HatchSaveAsync(Type textResource, IGym gym, IPokemon pokemon, IRaidboss raidboss, int interactiveLimit) { var beforeSpawnTime = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromMinutes(90)).ToUnixTimeSeconds(); var raid = await RaidRepository.FindAsync(e => e.FortId == gym.Id && e.TimeSpawn > beforeSpawnTime); if (raid == null) { return(new ServiceResponse(false, LocalizationService.Get(textResource, "Raids_Errors_Hatch_NoEntryFound", gym.Name))); } raid.PokemonId = (short)raidboss.Id; await RaidRepository.SaveAsync(); return(new ServiceResponse(true, LocalizationService.Get(textResource, "Raids_Messages_BossHatched", pokemon.Name, gym.Name))); }
private async Task <string> GetLocationNameFromLocationAsync(IGym gym) { var languageCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; Console.WriteLine("GetLocationNameFromLocationAsync enter with: " + languageCode); if (LocationLookupCache.TryGetValue(new KeyValuePair <int, string>(gym.Id, languageCode), out string value)) { return(value); } var fallback = string.Concat(gym.Latitude, ", ", gym.Longitude); Console.WriteLine("GLNFL: Fallback defined as " + fallback); var config = ConfigurationService.GetAppConfiguration(); if (config.GoogleMapsApiKeys == null) { Console.WriteLine("GLNFL: No GoogleMapsApiKeys Config Section found"); return(fallback); } var apiKey = config.GoogleMapsApiKeys.FirstOrDefault(); if (string.IsNullOrWhiteSpace(apiKey)) { Console.WriteLine("GLNFL: No Api-Key found"); return(fallback); } IGeocoder geocoder = new GoogleGeocoder { ApiKey = apiKey, Language = languageCode }; var addresses = await geocoder.ReverseGeocodeAsync(gym.Latitude, gym.Longitude); if (addresses == null) { Console.WriteLine("GLNFL: Google Api returend null"); return(fallback); } var address = addresses.FirstOrDefault(); if (address == null) { Console.WriteLine("GLNFL: Google Api returend no addresses"); return(fallback); } LocationLookupCache.AddOrUpdate(new KeyValuePair <int, string>(gym.Id, languageCode), address.FormattedAddress, i => address.FormattedAddress); return(address.FormattedAddress); }
public string InsertEquipment(string gymName, string equipmentType) { IEquipment equip = this.equipment.FindByType(equipmentType); if (equip == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.InexistentEquipment, equipmentType)); } IGym gym = this.gyms.FirstOrDefault(g => g.Name == gymName); gym.AddEquipment(equip); this.equipment.Remove(equip); return(string.Format(OutputMessages.EntityAddedToGym, equipmentType, gym.Name)); }
public async Task <string> GetGymNameWithAdditionAsync(IGym gym, List <IGym> gymList) { // Check if there is only one gym wth this name if (gymList.Count(e => e.Name.Trim() == gym.Name.Trim()) == 1) { return(gym.Name); } string nameAddition = await GetLocationNameFromLocationAsync(gym); var stringBuilder = new StringBuilder(); stringBuilder.Append(gym.Name); stringBuilder.Append(" ("); stringBuilder.Append(nameAddition); stringBuilder.Append(")"); return(stringBuilder.ToString()); }
public async Task UpdateGymAsync(IGym gym) { var fortSightings = await FortSightingRepository.FindAll(e => e.FortId == gym.Id).Take(1).ToListAsync(); //Yuck -- we only store unix time as an int in this table! int now = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (fortSightings == null || fortSightings.Count == 0) { var fortSighting = FortSightingRepository.CreateInstance(); fortSighting.FortId = gym.Id; fortSighting.Team = 0; fortSighting.LastModified = now; fortSighting.Updated = now; FortSightingRepository.Add(fortSighting); } else { var fortSighting = fortSightings[0]; fortSighting.LastModified = now; fortSighting.Updated = now; } await FortSightingRepository.SaveAsync(); }
public string EquipmentWeight(string gymName) { IGym gym = this.gyms.First(x => x.Name == gymName); return(string.Format(EquipmentTotalWeight, gymName, gym.EquipmentWeight)); }
private async Task <ServiceResponse> AddSaveAsync(Type textResource, ZonedDateTime requestStartInUtc, DateTimeZone userZone, IGym gym, byte level, IPokemon pokemon, IRaidboss raidboss, TimeSpan timeSpan) { var utcNowAfterProcessing = SystemClock.Instance.GetCurrentInstant().InUtc(); var processingTime = utcNowAfterProcessing.Minus(requestStartInUtc); var durationMinusProcessing = Duration.FromTimeSpan(timeSpan).Minus(processingTime); var expiry = utcNowAfterProcessing.Plus(durationMinusProcessing).ToInstant(); // Create the raid entry var beforeSpawnTime = utcNowAfterProcessing.Minus(Duration.FromMinutes(105)).ToInstant().ToUnixTimeSeconds(); var raid = await RaidRepository.FindAsync(e => e.FortId == gym.Id && e.TimeSpawn > beforeSpawnTime); if (raid == null) { raid = RaidRepository.CreateInstance(); raid.ExternalId = ThreadLocalRandom.NextLong(); raid.FortId = gym.Id; RaidRepository.Add(raid); } string message; if (raidboss == null) { raid.Level = level; raid.TimeSpawn = (int)expiry.Minus(_eggDuration).ToUnixTimeSeconds(); raid.TimeBattle = (int)expiry.ToUnixTimeSeconds(); raid.TimeEnd = (int)expiry.Plus(_raidDuration).ToUnixTimeSeconds(); message = LocalizationService.Get(textResource, "Raids_Messages_EggAdded", level, gym.Name, FormatExpiry(expiry, userZone)); } else { raid.PokemonId = (short)raidboss.Id; raid.Level = level; raid.TimeSpawn = (int)expiry.Minus(Duration.FromMinutes(105)).ToUnixTimeSeconds(); raid.TimeBattle = (int)expiry.Minus(Duration.FromMinutes(45)).ToUnixTimeSeconds(); raid.TimeEnd = (int)expiry.ToUnixTimeSeconds(); message = LocalizationService.Get(textResource, "Raids_Messages_BossAdded", pokemon.Name, gym.Name, FormatExpiry(expiry, userZone)); } await RaidRepository.SaveAsync(); await GymService.UpdateGymAsync(gym); return(new ServiceResponse(true, message)); }