public IActionResult Add([FromBody] Run run) { if (ModelState.IsValid) { _runRepo.Add(run); return(CreatedAtRoute("GetRun", new { Controller = "Run", run.RunID }, run)); } else { return(BadRequest()); } }
/// <summary> /// Creates run from template /// </summary> /// <param name="templateRun"></param> /// <param name="runRepository"></param> /// <returns></returns> private Run CreateRunFromTemplate(Run templateRun, IRunRepository runRepository) { using (var scope = _repositoryFactory.BeginRepositoryScope()) { // Get sales areas for the run var salesAreaRepository = scope.CreateRepository <ISalesAreaRepository>(); var salesAreas = RunManager.GetSalesAreas(templateRun, salesAreaRepository.GetAll()); // Set the default run start date time using today's date and time from template run, use it as the starting point to try and // find some schedule data. DateTime startingDateTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, templateRun.StartDate.Hour, templateRun.StartDate.Minute, templateRun.StartDate.Second, templateRun.StartDate.Millisecond, templateRun.StartDate.Kind); // Clone template run, reset it, set date range Run cloneRun = (Run)templateRun.Clone(); cloneRun.Id = Guid.NewGuid(); cloneRun.Description = $"Deployment Test ({GetVersion().Version})"; cloneRun.CreatedDateTime = DateTime.UtcNow; cloneRun.ExecuteStartedDateTime = null; cloneRun.LastModifiedDateTime = cloneRun.CreatedDateTime; cloneRun.IsLocked = false; cloneRun.Scenarios.ForEach(scenario => scenario.ResetToPendingStatus()); cloneRun.StartDate = GetRunStartDate(startingDateTime, salesAreas, 90); if (cloneRun.StartDate == DateTime.MaxValue) { throw new Exception("Unable to determine start date for test run due to insufficient data"); } cloneRun.EndDate = cloneRun.StartDate.AddDays(1); cloneRun.Real = false; // Flag that it's not a real run // Clear IDs so that we can assign new ones //IdUpdater.ClearIds(cloneRun); cloneRun.Id = Guid.Empty; cloneRun.CustomId = 0; // Set new IDs IdUpdater.SetIds(cloneRun, _identityGeneratorResolver); // Save run runRepository.Add(cloneRun); runRepository.SaveChanges(); return(cloneRun); } }
public Run Add(Run model) { _runRepository.Add(model); return(model); }