public IActionResult DotnetRegex(RegexViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ViewBag.NavigationZone = NavigationZone.Tools; if (ModelState.IsValid) { model.Execute(); if (model.InvalidRegexOptions) { ModelState.AddModelError("options", "Invalid combination of RegEx options (most likely due to ECMA Script)"); } } else { model.HasErrors = true; LogValidationErrors(); } return(View(model)); }
public JsonResult NewRegexForRecord(RegexViewModel regex, int[] Ids) { var recordManager = new RecordManager(); AjaxResult result = recordManager.NewRegexForRecord(regex, Ids, ModelState); return(Json(result)); }
public void NewRegexForRecord_Successfull() { // 0. Init const int recordId = 2; const int subtypeId = 10; const string regex = "unknown"; var ids = new[] { recordId, 3 }; // 1. First ensure we have 2 records to be processed var record2 = GetRecord(ids[0]); Assert.AreEqual(record2.SubtypeId, 0); var record3 = GetRecord(ids[1]); Assert.AreEqual(record3.SubtypeId, 0); //regex exists // 2. Call controller action var viewModel = new RegexViewModel { RegexId = recordId, SubtypeId = subtypeId, Name = regex }; var result = controller.NewRegexForRecord(viewModel, ids); // Assert result var res = result.Data as AjaxResult; Assert.IsNotNull(res); Assert.IsTrue(res.Result, "Should return true when everything is OK"); // 3. Now verify the data has been changed record2 = GetRecord(ids[0]); Assert.AreEqual(record2.SubtypeId, subtypeId); record3 = GetRecord(ids[1]); Assert.AreEqual(record3.SubtypeId, subtypeId); // TODO: Also verify regex count has incremented and new regex exists }
public RegularExpressionWindow() { InitializeComponent(); DataContext = new RegexViewModel(); }
public AjaxResult NewRegexForRecord(RegexViewModel regex, int[] Ids, ModelStateDictionary modelState) { const int recordId = 0; if (modelState.IsValid) { string message = string.Empty; var addRegexParameters = new[] { new SqlParameter("@SubtypeId", regex.SubtypeId), new SqlParameter("@Regex", regex.Name), new SqlParameter("@Result", -1) { Direction = ParameterDirection.Output } }; var res = Database.StoredProcedure(Settings.StoredProcedures.RegexAdd, addRegexParameters, "@Result") as ProcedureIdentityResult; if (res.Status == Status.Success) { StaticData.LoadRegex(); var parameter = (new List <SqlParameter> { new SqlParameter("@RecordIds", string.Join(", ", Ids)) }).ToArray(); IEnumerable <Record> records = DataBase <Record> .GetModel <Record>(Settings.StoredProcedures.RecordsGetById, parameter).Values; // Iterate through each record found matchchig regex foreach (Record record in records) { // Do only for those records, that match newly created mask and have 0 as SubtypeId if (record.SubtypeId == 0) { var parameters = new List <SqlParameter> { new SqlParameter("@RecordId", record.RecordId), new SqlParameter("@SubtypeId", regex.SubtypeId), new SqlParameter("@Comment", record.Comment), new SqlParameter("@Result", -1) { Direction = ParameterDirection.Output } }; // Call to database to update parameter var result = new RecordManager().UpdateRecord(parameters); if (result < 1) { message += "Failes to update"; } } } if (message.Length == 0) { // Return AjaxResult = OK return(new AjaxResult(modelState, recordId)); } return(new AjaxResult(modelState, recordId, "Error while adding new filter")); } return(new AjaxResult(modelState, recordId, res.ErrorMessage)); } return(new AjaxResult(modelState, recordId)); }
public RecordRegex(RegexViewModel viewModel) { RegexId = viewModel.RegexId; SubtypeId = viewModel.SubtypeId; Name = viewModel.Name; }