public ICollection<Event> GetEvents(string name, int year) { List<Event> eventer = new List<Event>(); var ev1 = new Event() { Id = 1, Date = new DateTime(2015, 4, 14), Name = "Folkeparken" }; var ev2 = new Event() { Id = 1, Date = new DateTime(2015, 5, 11), Name = "Krokenmila" }; var ev3 = new Event() { Id = 1, Date = new DateTime(2015, 6, 8), Name = "Folkeparken" }; eventer.Add(ev1); eventer.Add(ev2); eventer.Add(ev3); return eventer; }
public void InsertResultInEvent(ICollection<UserEventInfo> deltakere, Event ev) { if (string.IsNullOrEmpty(ev.Name)) { ev = _eventService.GetEvent(ev.Id); } var eventResult = new EventResult {Event = ev}; // Hvis bruker ikke fins blir dato satt til DateTime.MinValue, resultat vil legges inn i tempresult var usernames = deltakere.Select(deltaker => new User { Name = deltaker.Name, Gender = deltaker.Gender.ToUpper(), DateOfBirth = DateTime.MinValue }).ToList(); var watch = new Stopwatch(); watch.Start(); var users = _userService.CreateAndGetUsers(usernames, new StreamWriter(Console.OpenStandardOutput())); watch.Stop(); var results = new List<Result>(); for (var i = 0; i < deltakere.Count; i++) { var deltaker = deltakere.ToList()[i]; var result = new Result { User = users.First(t => t.Name.Equals(deltaker.Name)), Position = Convert.ToInt32(deltaker.Place) }; var time = deltaker.Time; try { time = deltaker.Time.Substring(0, deltaker.Time.IndexOf(".", StringComparison.Ordinal)); } catch (ArgumentOutOfRangeException) { } if (time.Length < 6) { time = "0:" + time; } result.Time = TimeSpan.Parse(time); // For å hindre at bogus tid blir lagt inn. Står 0.00 flere steder i importfil if (result.Time.TotalSeconds > 10) { results.Add(result); } } eventResult.Results = results; _eventService.AddEventResults(eventResult); }
private static string GetAgeCategory(User user, Event ev) { var age = ev.Date.Year - user.DateOfBirth.Year; if (age < 20) { return "J"; } else if (age < 35) { return "S"; } else if (age < 40) { return "A35"; } else if (age < 45) { return "A40"; } else if (age < 50) { return "A45"; } else if (age < 55) { return "A50"; } else if (age < 60) { return "A55"; } else if (age < 65) { return "A60"; } else if (age < 70) { return "A65"; } else if (age < 75) { return "A70"; } else if (age < 80) { return "A75"; } else { return "A80"; } }
private EventResultDto CreateEventResultDto(Event ev, Result result, int time) { var eventResultDto = new EventResultDto { EventId = ev.Id, AgeCategory = GetAgeCategory(result.User, ev), AgeGrade = GetAgeGrade(result.User, result.Time, ev), DateCreated = DateTime.Now, Gender = result.User.Gender, UserId = result.User.Id, Time = time, Position = result.Position }; return eventResultDto; }
private double GetAgeGrade(User user, TimeSpan time, Event @event) { var age = user.DateOfBirth.Age(DateTime.Now); var distance = @event.Distance; var result = _scriptRunner.CalculateAgeGrade(age, distance, time, user.Gender); return result; }