public void AddAward(Awards award) { FileExists(); var listOfAwards = File.ReadAllLines(FileAwardsPath).ToList(); var hashAwards = new HashSet <string>(); if (listOfAwards.Count == 0) { award.Id = 0; } else { foreach (var item in listOfAwards) { string[] infoAward = item.Split(' '); hashAwards.Add(infoAward[1]); if (int.TryParse(infoAward[0], out int id) && this.max < id) { this.max = id; } } award.Id = ++this.max; this.max = 0; } if (hashAwards.Add(award.Title)) { listOfAwards.Add(award.ToString()); File.WriteAllLines(FileAwardsPath, listOfAwards); } }
public bool UpdAward(Awards award) { FileExists(); var arrayOfAwards = File.ReadAllLines(FileAwardsPath); List <string> listOfAwards = arrayOfAwards.ToList(); if (listOfAwards.Count != 0) { foreach (var item in listOfAwards.ToList()) { string[] infoAward = item.Split(' '); if (award.Id == int.Parse(infoAward[0])) { listOfAwards.Remove(item); listOfAwards.Add(award.ToString()); File.WriteAllLines(FileAwardsPath, listOfAwards.ToArray()); return(true); } } } return(false); }