public async Task <IActionResult> NewRecord([FromBody] FitnessRecord newRecord) { if (await _dataStore.WriteRecord(newRecord)) { return(Ok("new record successfully written")); } return(StatusCode(400)); }
public async Task <bool> WriteRecord(FitnessRecord newRecord) { var records = await GetAllRecords(); if (records.Where(x => x.title.ToUpper().Equals(newRecord.title.ToUpper())).Count() > 0) { return(false); } using (StreamWriter sw = File.AppendText(FILE_PATH)) { var recordStr = JsonConvert.SerializeObject(newRecord); await sw.WriteLineAsync(recordStr); } return(true); }