[HttpPut] public JsonResult EditConfigurationData() { try { List configurations = new(); bool result = true; int idData = 0; IFormCollection data = HttpContext.Request.Form; var dict = new Dictionary(); foreach (var key in data.Keys) { StringValues @value = new(); data.TryGetValue(key, out @value); dict.Add(key, @value.ToString()); } //data[999][template] foreach(var entry in dict) { string id = entry.Key.ToString(); if (id == "action") break; int firstIndex = entry.Key.ToString().LastIndexOf('[') + 1; int secondIndex = entry.Key.ToString().Length - firstIndex - 1; idData = Convert.ToInt32(Regex.Match(id, @"\d+").Value); string valueData = entry.Key.ToString().Substring(firstIndex, secondIndex); string changeData = entry.Value.ToString(); // change the data value with the associated object in the db and then return the full object to the view result = _dataRepository.EditConfigData(idData, valueData, changeData); } if (result) { DRXREF config = _dataRepository.GetSingleConfig(idData); ConfigurationTableModel model = new() { ID = config.ID, NAME = config.NAME, RSDRAW = config.RSDRAW, RDDRAW = config.RDDRAW, LASDRAW = config.LASDRAW, LAADRAW = config.LAADRAW, GRPDES = config.GRPDES, ECRNUM = config.ECRNUM, REVLEVEL = config.REVLEVEL, REVDATE = config.REVDATE.ToShortDateString(), REVINIT = config.REVINIT, COMPLETE = config.COMPLETE }; configurations.Add(model); return Json(new { data = configurations }); } else return Json(new { error = "Failed to update entry." }); } catch (Exception ex) { return Json(new { error = ex.Message.ToString() }); } }