public IActionResult SaveRecordDetail(string json) { RecordDetail record = JsonConvert.DeserializeObject <RecordDetail>(json); List <RecordDetail> records = LoadFromFile(); if (record.id <= 0) { //New record //Not sure if I need all this.... int maxId = records.OrderByDescending(i => i.id).FirstOrDefault()?.id ?? 0; record.id = maxId + 1; records.Add(record); } else { //Existing record. Find old entry and replace it with the new one int index = records.FindIndex(r => r.id == record.id); if (index >= 0) { records[index] = record; } } SaveToFile(records); return(new JsonResult(new { id = record.id })); }
public IActionResult GetRecordDetail(int id) { List <RecordDetail> records = LoadFromFile(); RecordDetail record = records.SingleOrDefault(r => r.id == id); return(new JsonResult(record)); }