public async static Task <TimeSpan> GetPredictor(RaceDistance raceDistance, TimeSpan fiveKm) { TimeSpan ret = default(TimeSpan); using (var puppeteer = new PuppeteerHelper()) { await puppeteer.StartAsync(); await puppeteer.OpenAsync(url, async (page, response) => { // select the option on the target race distance await puppeteer.SelectOptionAsync(page, "#frace", GetRaceDistanceValue(raceDistance)); // select the base race distance of the submitted time await puppeteer.SelectOptionAsync(page, "#r1", GetRaceDistanceValue(RaceDistance.FiveKm)); // enter the hours, minutes, seconds of the base race await puppeteer.EnterTextAsync(page, "#r1t_hours", fiveKm.Hours.ToString()); await puppeteer.EnterTextAsync(page, "#r1t_minutes", fiveKm.Minutes.ToString()); await puppeteer.EnterTextAsync(page, "#r1t_seconds", fiveKm.Seconds.ToString()); // click the 'Calculate' button. await puppeteer.HitButtonAsync(page, ".form-submit", true); // get the results var result = await puppeteer.GetInnerHtmlAsync(page, "#results"); // parse the results html ret = ParseResults(result); }); } return(ret); }
public void Update(string oldLabel, string newLabel, RaceDistance newRaceDistance, string newWebsite, string newIcon) { var race = RaceFinder.FindRace(oldLabel); race.Label = newLabel; race.Distance = newRaceDistance; race.Website = newWebsite; race.Icon = newIcon; }
public RaceEvent CreateEvent(DateTime date, RaceDistance raceDistance) { var raceEvent = new RaceEvent() { Distance = (int)raceDistance, Results = new List <Dto.RacePersonTime>() }; raceEvent.SetDate(date); return(raceEvent); }
public static async Task <Time> GetTimeAsync(RaceDistance raceDistance, TimeSpan backup5kmTime, TimeSpan?timeSpan = null) { if ((!timeSpan.HasValue || timeSpan == TimeSpan.Zero) && backup5kmTime != TimeSpan.Zero) { timeSpan = await RaceTimePredictor.GetPredictor(raceDistance, backup5kmTime); } var time = new Time(); time.SetTime(timeSpan == null ? TimeSpan.Zero : timeSpan.Value); return(time); }
private async Task <bool> AddRaceDistanceWherePreviousExists(RaceViewModel model, ICollection <RaceDistance> RaceDistances, IQueryable <Distance> distances) { bool isSaveSuccess = true; List <RaceDistance> assignedRaceDistances = new List <RaceDistance>(); //foreach (var recordId in model.DistanceIds) //{ // var currentRolePermission = distances.Where(a => a.Id == recordId).FirstOrDefault(); // if (currentRolePermission != null) // { // if (!RaceDistances.Any(a => a.DistanceId == recordId)) // { // // var currentUserRoleID = currentMenuRoles.First(a => a.Distance.RoleID == currentRolePermission.RoleID).RegionID; // var RaceDistanceRepo = new RaceDistance(); // //assignedRaceDistances.Add(RaceDistanceRepo.ToEntity(recordId, model.Id, model.SessionUserId)); // } // } //} for (int row = 0; row < model.DistanceIds.Count(); row++) { if (model.EventDateTimes[row] != null) { var currentDistance = distances.Where(a => a.Id == model.DistanceIds[row]).FirstOrDefault(); if (currentDistance != null) { if (!RaceDistances.Any(a => a.DistanceId == model.DistanceIds[row])) { var RaceDistanceRepo = new RaceDistance(); assignedRaceDistances.Add(RaceDistanceRepo.ToEntity((int)model.DistanceIds[row], model.Id, (DateTime)model.EventDateTimes[row], model.SessionUserId)); } } } } if (assignedRaceDistances.Count > 0) { await _context.RaceDistance.AddRangeAsync(assignedRaceDistances); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }
private async Task <SaveResult> EditEntityAsync(RaceViewModel model, RaceDistance record) { var saveResult = new SaveResult(); var editRaceDistance = await _context.RaceDistance.FindAsync(record.Id); // editRaceDistance.ToEntity(record.DistanceId, model.Id, model.SessionUserId); _context.Update(editRaceDistance); await _context.SaveChangesAsync(); saveResult.IsSuccess = true; return(saveResult); }
public async Task <SaveResult> SaveEntityList(RaceResultViewModel model, RaceDistance parentEntity) { SaveResult saveResult = new SaveResult(); var currentEntities = parentEntity.RaceResults; if (model.MemberIds == null) { if (currentEntities.Any()) { var RaceResultIds = currentEntities.ToList().ToList().Select(b => b.Id); var toDeleteList = _context.RaceResult.Where(a => RaceResultIds.Contains(a.Id)); _context.RaceResult.RemoveRange(toDeleteList); await _context.SaveChangesAsync(); saveResult.IsSuccess = true; } else { saveResult.IsSuccess = true; } } else { var memberList = _context.Member.Include(a => a.Person) .Where(a => model.MemberIds.Contains(a.Id)); if (currentEntities.Any()) { saveResult.IsSuccess = await AddRaceResultWherePreviousExists(model, currentEntities, memberList); if (saveResult.IsSuccess) { saveResult = await ManageExistingRaceResult(model, currentEntities, memberList); } } else { saveResult.IsSuccess = await AddEntity(model, currentEntities, memberList); } } return(saveResult); }
private static string GetRaceDistanceValue(RaceDistance raceDistance) { switch (raceDistance) { case RaceDistance.FiveKm: return("5k"); case RaceDistance.TenKm: return("10k"); case RaceDistance.TenMiles: return("10m"); case RaceDistance.HalfMarathon: return("half"); default: throw new ArgumentOutOfRangeException(nameof(raceDistance)); } }
public static Race CreateSingleEventRace(string label, DateTime date, RaceDistance raceDistance) { var race = new Race() { Label = label, Distance = raceDistance }; var raceEvent = new RaceEvent() { Distance = (int)raceDistance }; raceEvent.SetDate(date); race.Events.Add(raceEvent); return(race); }
private async Task <int> CalculateAge(Member memberEntity, int raceDistanceId) { RaceDistance raceDistanceEntity = await _context.RaceDistance.FindAsync(raceDistanceId); if (raceDistanceEntity == null) { throw new ArgumentNullException("Race Distance not found"); } int age = raceDistanceEntity.EventDate.Year - memberEntity.Person.BirthDate.Year; AgeGroup ageGroupEntity = await _context.AgeGroup.FirstOrDefaultAsync(a => a.MinValue < age && age <= a.MaxValue); if (ageGroupEntity == null) { throw new ArgumentNullException("Agre Group not found"); } return(ageGroupEntity.Id); }
public static RaceDistance ToEntity(this RaceDistance entity, int referralId, int containerId, DateTime eventDateTime, string sessionUserID) { if (entity.Id > 0) { entity.UpdatedUserId = sessionUserID; entity.UpdatedTimestamp = DateTime.Now; } else { entity.RaceId = containerId; entity.DistanceId = referralId; entity.CreatedUserId = sessionUserID; entity.EventDate = eventDateTime; } return(entity); }
private async Task <bool> AddEntity(RaceViewModel model, ICollection <RaceDistance> raceDistances, IQueryable <Distance> distances) { bool isSaveSuccess = true; List <RaceDistance> RaceDistanceList = new List <RaceDistance>(); //foreach (var record in model.DistanceIds) //{ // var currentDistance = distances.Any(a => a.Id == record); // if (currentDistance) // { // RaceDistance raceDistance = new RaceDistance(); // RaceDistanceList.Add(raceDistance.ToEntity(record, model.Id, model.SessionUserId)); // } //} for (int row = 0; row < model.DistanceIds.Count(); row++) { if (model.EventDateTimes[row] != null) { var currentDistance = distances.Any(a => a.Id == model.DistanceIds[row]); if (currentDistance) { RaceDistance raceDistance = new RaceDistance(); RaceDistanceList.Add(raceDistance.ToEntity((int)model.DistanceIds[row], model.Id, (DateTime)model.EventDateTimes[row], model.SessionUserId)); } } } if (RaceDistanceList.Count > 0) { await _context.RaceDistance.AddRangeAsync(RaceDistanceList); await _context.SaveChangesAsync(); isSaveSuccess = true; } return(isSaveSuccess); }
public async Task <SaveResult> SaveEntity(RaceResultViewModel viewModel) { SaveResult saveResult = new SaveResult(); Dictionary <bool, string> dictionary = new Dictionary <bool, string>(); try { RaceDistance parentEntity = await _context.RaceDistance.IgnoreQueryFilters().FirstOrDefaultAsync(a => a.Id == viewModel.RaceDistanceId); saveResult = await _raceResultMappingBL.SaveEntityList(viewModel, parentEntity); } catch (DbUpdateException upDateEx) { var results = upDateEx.GetSqlerrorNo(); string msg = results == (int)SqlErrNo.FK ? ConstEntity.MissingValueMsg : ConstEntity.UniqueKeyMsg; saveResult = dictionary.GetValidateEntityResults(msg).ToSaveResult(); } catch (Exception ex) { saveResult.Message = CrudError.SaveErrorMsg; } return(saveResult); }
public override int GetHashCode() { return(RaceDate.GetHashCode() ^ RaceDistance.GetHashCode() ^ WonPlace.GetHashCode()); }