Beispiel #1
0
 public void AddEventResults(EventResult eventResult)
 {
     var query = new List<EventResultDto>();
     foreach (var result in eventResult.Results)
     {
             
         if (result.User.DateOfBirth.Equals(DateTime.MinValue))
         {
             var dataObject = Tools.Serialize(result);
             Console.WriteLine(dataObject);
             Console.WriteLine(result.Time);
             Console.WriteLine("*******");
             var tempResult = new TempResultDto
             {
                 Data = dataObject,
                 Registered = DateTime.Now,
                 UserId = result.User.Id,
                 EventId = eventResult.Event.Id
             };
             _resultDataService.AddTempResult(tempResult);
         }
         else
         {
             var time = CalculateTime(result.Time);
             var eventResultDto = CreateEventResultDto(eventResult.Event, result, time);                    
             query.Add(eventResultDto);
         }
     }
     _resultDataService.AddEventResults(query);
 }
        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);
        }
 public void AddEventResults(EventResult eventResult)
 {
     throw new NotImplementedException();
 }
        public void UpdateTempResults()
        {
            var tempResults = _eventService.GetAllTempResults();
            var invalidUsers = _userService.GetAllUsersWithInvalidDate();
            var itemsToDelete = (from tempResult in tempResults let userId = tempResult.UserId let resultHasInvalidUser = invalidUsers.FirstOrDefault(t => t.Id.Equals(userId)) where resultHasInvalidUser == null select tempResult).ToList();
            foreach (var itemToDelete in itemsToDelete)
            {
                Console.WriteLine("------------------------");
                var result = Tools.Deserializate<Result>(itemToDelete.Data);
                var eventId = itemToDelete.EventId;
                var userId = itemToDelete.UserId;
                var user = _userService.FindUser(userId);

                if (user == null)
                {
                    Console.WriteLine("Invalid user, deleting: " + userId);
                    _eventService.DeleteTempResult(itemToDelete);
                    continue;
                };
                result.User = user;
                var ev = _eventService.GetEvent(eventId);
                // Event has been deleted
                if (ev == null)
                {
                    Console.WriteLine("Invalid event: " + eventId + "; User: "******"Added entry for user: "******"Event: " + ev.DisplayName);
                

            }
        }