public IHttpActionResult SimulateCalls([FromBody] SimulatorCalls calls) { try { simulator.SimulateCalls(calls); return(Ok()); } catch (Exception e) { return(BadRequest()); } }
public async Task SimulateCalls(SimulatorCalls calls) { using (var client = new HttpClient { BaseAddress = uri }) { var response = await client.PostAsJsonAsync($"api/simulator/SimulateCalls", calls); if (!response.IsSuccessStatusCode) { throw new Exception("Could not post the calls. "); } } }
public void SimulateCalls(SimulatorCalls calls) { string[] destinations = repository.GetRandomNumbersFor(calls.CallerNumber, calls.DestinationOption, calls.Simulations); Random rand = new Random(); var rangeLength = (calls.MaxDuration - calls.MinDuration).TotalMinutes; var minDur = calls.MinDuration.TotalMinutes; var time = DateTime.Now; for (int i = 0; i < calls.Simulations; i++) { repository.AddCall(new Call { CallerNumber = calls.CallerNumber, DestinationNumber = destinations[i], Duration = TimeSpan.FromMinutes((rand.Next() / (double)int.MaxValue) * rangeLength + minDur), StartTime = time }); time = time.AddMinutes(5); } }