public void SaveRule() { if (UnitTest.HttpRequestUnitTest == null) { var newHttpRequestUnitTest = new HttpRequestUnitTest { UnitTestId = UnitTest.Id, UnitTest = UnitTest }; UnitTest.HttpRequestUnitTest = newHttpRequestUnitTest; } var rule = UnitTest.HttpRequestUnitTest.Rules.FirstOrDefault(); if (rule == null) { rule = new HttpRequestUnitTestRule() { Id = Guid.NewGuid(), HttpRequestUnitTest = UnitTest.HttpRequestUnitTest }; UnitTest.HttpRequestUnitTest.Rules.Add(rule); } rule.DisplayName = UnitTest.DisplayName; rule.SortNumber = 0; rule.TimeoutSeconds = TimeOutSeconds; rule.Method = Method; rule.Url = new Uri(Url).AbsoluteUri; rule.ResponseCode = ResponseCode; rule.SuccessHtml = SuccessHtml; rule.ErrorHtml = ErrorHtml; foreach (var data in rule.Datas.ToArray()) { rule.Datas.Remove(data); AccountDbContext.Entry(data).State = System.Data.Entity.EntityState.Deleted; } if (RequestHeaders != null) { RequestHeaders.ForEach(x => AddRuleData(rule, x, HttpRequestUnitTestRuleDataType.RequestHeader)); } if (RequestCookies != null) { RequestCookies.ForEach(x => AddRuleData(rule, x, HttpRequestUnitTestRuleDataType.RequestCookie)); } if (WebFormDatas != null) { WebFormDatas.ForEach(x => AddRuleData(rule, x, HttpRequestUnitTestRuleDataType.WebFormData)); } }