Esempio n. 1
0
        public void DeleteByAwardID(int awardID)
        {
            int count_Iteration = 0;

            using (var reader = new StreamReader(LocalDataPath + TablePath))
                while (!reader.EndOfStream)
                {
                    count_Iteration++;
                    Task7._1._1.Entities.Table_Users_Awards table_Users_Awards = JsonConvert.DeserializeObject <Task7._1._1.Entities.Table_Users_Awards>(reader.ReadLine());
                    if (table_Users_Awards.Award_ID != awardID)
                    {
                        using (var writter = new StreamWriter(LocalDataPath + TablePath + ".tmp", true))
                        {
                            Task7._1._1.Entities.Table_Users_Awards new_table_Users_Awards = new Task7._1._1.Entities.Table_Users_Awards();
                            new_table_Users_Awards.Award_ID = table_Users_Awards.Award_ID;
                            new_table_Users_Awards.User_ID  = table_Users_Awards.User_ID;
                            var newTableJson = JsonConvert.SerializeObject(new_table_Users_Awards);
                            writter.WriteLine(newTableJson);
                        }
                    }
                }
            if (count_Iteration > 1)
            {
                File.Delete(LocalDataPath + TablePath);
                File.Move(LocalDataPath + TablePath + ".tmp", LocalDataPath + TablePath);
            }
            else
            {
                File.Delete(LocalDataPath + TablePath);
                File.Create(LocalDataPath + TablePath).Close();
            }
        }
Esempio n. 2
0
        public IEnumerable <User> GetUsersByAwardID(int awardID)
        {
            List <int>  usersID = new List <int>();
            List <User> users   = new List <User>();

            using (var reader = new StreamReader(LocalDataPath + TablePath))
                while (!reader.EndOfStream)
                {
                    Task7._1._1.Entities.Table_Users_Awards table_Users_Awards = JsonConvert.DeserializeObject <Task7._1._1.Entities.Table_Users_Awards>(reader.ReadLine());
                    if (table_Users_Awards.Award_ID == awardID)
                    {
                        if (usersID.IndexOf(table_Users_Awards.User_ID) == -1)
                        {
                            usersID.Add(table_Users_Awards.User_ID);
                        }
                    }
                }

            for (int i = 0; i < usersID.Count; i++)
            {
                using (var reader = new StreamReader(LocalDataPath + UsersPath + "User_" + usersID[i] + ".json"))
                    users.Add(JsonConvert.DeserializeObject <User>(reader.ReadToEnd()));
            }
            return(users);
        }
Esempio n. 3
0
 public void Delete(int awardID, int userID)
 {
     using (var reader = new StreamReader(LocalDataPath + TablePath))
         while (!reader.EndOfStream)
         {
             Task7._1._1.Entities.Table_Users_Awards table_Users_Awards = JsonConvert.DeserializeObject <Task7._1._1.Entities.Table_Users_Awards>(reader.ReadLine());
             if (table_Users_Awards.Award_ID == awardID && table_Users_Awards.User_ID == userID)
             {
                 continue;
             }
             else
             {
                 using (var writter = new StreamWriter(LocalDataPath + TablePath + ".tmp", true))
                 {
                     Task7._1._1.Entities.Table_Users_Awards new_table_Users_Awards = new Task7._1._1.Entities.Table_Users_Awards();
                     new_table_Users_Awards.Award_ID = table_Users_Awards.Award_ID;
                     new_table_Users_Awards.User_ID  = table_Users_Awards.User_ID;
                     var newTableJson = JsonConvert.SerializeObject(new_table_Users_Awards);
                     writter.WriteLine(newTableJson);
                 }
             }
         }
     File.Delete(LocalDataPath + TablePath);
     File.Move(LocalDataPath + TablePath + ".tmp", LocalDataPath + TablePath);
 }
Esempio n. 4
0
        public IEnumerable <Award> GetAwardsByUserID(int userID)
        {
            if (!File.Exists(LocalDataPath + TablePath))
            {
                var table = File.Create(LocalDataPath + TablePath);
                table.Close();
            }
            List <int>   awardsID = new List <int>();
            List <Award> awards   = new List <Award>();

            using (var reader = new StreamReader(LocalDataPath + TablePath))
                while (!reader.EndOfStream)
                {
                    Task7._1._1.Entities.Table_Users_Awards table_Users_Awards = JsonConvert.DeserializeObject <Task7._1._1.Entities.Table_Users_Awards>(reader.ReadLine());
                    if (table_Users_Awards.User_ID == userID)
                    {
                        awardsID.Add(table_Users_Awards.Award_ID);
                    }
                }

            for (int i = 0; i < awardsID.Count; i++)
            {
                using (var reader = new StreamReader(LocalDataPath + AwardsPath + "Award_" + awardsID[i] + ".json"))
                    awards.Add(JsonConvert.DeserializeObject <Award>(reader.ReadToEnd()));
            }
            return(awards);
        }