// methode to modift the list //i need to modify this ------------------------------------------------------- public bool updateList(SaveWork em) { bool isUpdated = false; for (int i = 0; i < saveWorkList.Count; i++) { if (saveWorkList[i].NameSave == em.NameSave) { saveWorkList[i] = em; isUpdated = true; break; } } return(isUpdated); }
// methode to add the employee in the list and return true if it worked public bool addSaveWork(SaveWork save) { if ((!Regex.IsMatch(save.NameSave, @"^[a-zA-Z0-9 _]+$"))) { throw new ArgumentException("Please only make use of alphanumeric characters, spaces or underscores."); } if (!Regex.IsMatch(save.SrcPath, @"^[a-zA-Z]:(?:\/[a-zA-Z0-9 _]+)*$")) { throw new ArgumentException("Please enter a valid absolute path."); } if (!Regex.IsMatch(save.DestPath, @"^[a-zA-Z]:(?:\/[a-zA-Z0-9 _]+)*$")) { throw new ArgumentException("Please enter a valid absolute path."); } if (save.Type != "complete" && save.Type != "differential") { throw new ArgumentException("You can only choose between complete and differential"); } if (!File.Exists("state.json")) { saveWorkList.Add(save); String stringjson = JsonConvert.SerializeObject(saveWorkList, Formatting.Indented); File.WriteAllText("state.json", stringjson); } else { string json = File.ReadAllText("state.json"); //Console.WriteLine(json); saveWorkList = JsonConvert.DeserializeObject <List <SaveWork> >(json); saveWorkList.Add(save); String stringjson = JsonConvert.SerializeObject(saveWorkList, Formatting.Indented); File.WriteAllText("state.json", stringjson); } CreateLogLine("Creation of a new save work , name : " + save.NameSave + ", source path : " + save.SrcPath + ", destination path : " + save.DestPath + ", type : " + save.Type); return(true); }