Ejemplo n.º 1
0
        public void Delete(UserAward userAward)
        {
            var temp = JsonSerializer.Deserialize <HashSet <UserAward> >(FileIo.Read(_pathToFile));

            temp.Remove(userAward);
            FileIo.Write(_pathToFile, JsonSerializer.Serialize(temp));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
 public List <Award> GetAll()
 {
     return(JsonSerializer.Deserialize <List <Award> >(FileIo.Read(_pathToFile)));
 }
Ejemplo n.º 9
0
        public List <UserAward> GetAll()
        {
            var temp = JsonSerializer.Deserialize <HashSet <UserAward> >(FileIo.Read(_pathToFile));

            return(new List <UserAward>(temp));
        }