public async Task TestPage(string siteUrl, string url) { var responseTime = responseTimeTester.Test(url); var site = await repo.GetTestedSiteAsync(siteUrl); var page = site.Pages.SingleOrDefault(item => item.Url == url); if (page == null) { page = new TestedPage { Url = url, Site = site, Results = new List <TestResult>() }; repo.AddTestedPage(page); if (!await repo.SaveAllAsync()) { throw new Exception("Save error"); } } page.Results.Add(new TestResult(responseTime, page)); repo.Update(page); if (!await repo.SaveAllAsync()) { throw new Exception("Save error"); } }