Ejemplo n.º 1
0
        private AddOrUpdateLoadtestsResponse AddOrUpdateLoadtests(AddOrUpdateLoadtestsRequest addOrUpdateLoadtestsRequest)
        {
            AddOrUpdateLoadtestsResponse resp = new AddOrUpdateLoadtestsResponse();

            try
            {
                //assign ID if not present, assume to be insertion
                foreach (LoadtestViewModel ltvm in addOrUpdateLoadtestsRequest.Loadtests)
                {
                    if (ltvm.Id == null || ltvm.Id == default(Guid))
                    {
                        ltvm.Id = Guid.NewGuid();
                    }
                }
                List <LoadtestViewModel> sortedByDate    = addOrUpdateLoadtestsRequest.Loadtests.OrderBy(lt => lt.StartDateUtc).ToList();
                LoadtestViewModel        last            = sortedByDate.Last();
                IList <Loadtest>         loadtests       = _timetableRepository.GetLoadtestsForTimePeriod(sortedByDate.First().StartDateUtc, last.StartDateUtc.AddSeconds(last.DurationSec));
                Timetable        timetable               = new Timetable(loadtests);
                IList <Loadtest> loadtestsAddedOrUpdated = _timetableViewModelRepository.ConvertToDomain(addOrUpdateLoadtestsRequest.Loadtests);
                AddOrUpdateLoadtestsValidationResult validationResult = timetable.AddOrUpdateLoadtests(loadtestsAddedOrUpdated);
                _timetableRepository.AddOrUpdateLoadtests(validationResult);
                resp.AddOrUpdateLoadtestsValidationResult = validationResult;
            }
            catch (Exception ex)
            {
                resp.Exception = ex;
            }
            return(resp);
        }