public void Delete(UserAward userAward) { var temp = JsonSerializer.Deserialize <HashSet <UserAward> >(FileIo.Read(_pathToFile)); temp.Remove(userAward); FileIo.Write(_pathToFile, JsonSerializer.Serialize(temp)); }
public void Delete(Award t) { var awards = JsonSerializer.Deserialize <List <Award> >(FileIo.Read(_pathToFile)); if (!awards.Remove(t)) { throw new ArgumentException("Can't delete field with this award!"); } _cashAwards.Remove(t); FileIo.Write(_pathToFile, JsonSerializer.Serialize(awards)); }
public void Delete(User user) { var users = JsonSerializer.Deserialize <List <User> >(FileIo.Read(_pathToFile)); if (!users.Remove(user)) { throw new ArgumentException("Can't delete field with this user!"); } _cashUsers.Remove(user); FileIo.Write(_pathToFile, JsonSerializer.Serialize(users)); }
public Award Get(int id) { if (_cashAwards.Any(user => user.Id == id)) { var temp = _cashAwards.First(a => a.Id == id); _cashAwards.Remove(temp); _cashAwards.Insert(0, temp); return(temp); } var awards = JsonSerializer.Deserialize <List <Award> >(FileIo.Read(_pathToFile)); return(awards.Find(a => a.Id == id)); }
public User Get(int id) { if (_cashUsers.Any(user => user.Id == id)) { var temp = _cashUsers.First(user => user.Id == id); _cashUsers.Remove(temp); _cashUsers.Insert(0, temp); return(temp); } var users = JsonSerializer.Deserialize <List <User> >(FileIo.Read(_pathToFile)); return(users.Find(user => user.Id == id)); }
public void Add(User user) { var users = JsonSerializer.Deserialize <List <User> >( FileIo.Read(_pathToFile)); if (user.Id == null) { user.Id = users.Max(user1 => user1.Id) + 1; } users.Add(user); _cashUsers.Insert(0, user); FileIo.Write(_pathToFile, JsonSerializer.Serialize(users)); if (_cashUsers.Count > MaxSizeCash) { _cashUsers.RemoveRange(MinSizeCash, _cashUsers.Count - MinSizeCash); } }
public void Add(Award t) { var awards = JsonSerializer.Deserialize <List <Award> >( FileIo.Read(_pathToFile)); if (t.Id == null) { t.Id = awards.Max(a => a.Id) + 1; } awards.Add(t); _cashAwards.Insert(0, t); FileIo.Write(_pathToFile, JsonSerializer.Serialize(awards)); if (_cashAwards.Count > MaxSizeCash) { _cashAwards.RemoveRange(MinSizeCash, _cashAwards.Count - MinSizeCash); } }
public List <Award> GetAll() { return(JsonSerializer.Deserialize <List <Award> >(FileIo.Read(_pathToFile))); }
public List <UserAward> GetAll() { var temp = JsonSerializer.Deserialize <HashSet <UserAward> >(FileIo.Read(_pathToFile)); return(new List <UserAward>(temp)); }