public void UpdateState(StateDto stateToUpdate) { var statesList = ReadAllStates(); var existingState = statesList.First(s => s.StateAbbreviaton == stateToUpdate.StateAbbreviaton); statesList.Remove(existingState); statesList.Add(stateToUpdate); OverwriteFile(statesList); }
public List<StateDto> ReadAllStates() { List<StateDto> statesList = new List<StateDto>(); var reader = File.ReadAllLines(FilePath); for (int i = 1; i < reader.Length; i++) { var columns = reader[i].Split(','); var state = new StateDto(); state.StateAbbreviaton = columns[0]; state.StateName = columns[1]; state.TaxRate = decimal.Parse(columns[2]); statesList.Add(state); } return statesList; }
public void CreateState(StateDto inStateDto) { var statesList = ReadAllStates(); statesList.Add(inStateDto); OverwriteFile(statesList); }