Example #1
0
        // This method removes the class ID of the class a user attended,
        // from the Bruger.csv file.
        public void RemoveClassIDFromUserFile(FitnessClass classAttended)
        {
            List <string> lines = new List <string>();
            string        line;
            User          currentUser = FindUserFromLoginStatus();

            var path = Directory.GetCurrentDirectory() + @"\Bruger.csv";

            using (TextFieldParser csvParser = new TextFieldParser(path))
            {
                csvParser.SetDelimiters(new string[] { "," });
                csvParser.HasFieldsEnclosedInQuotes = false;

                while (!csvParser.EndOfData)
                {
                    int      i         = 0;
                    string[] fields    = csvParser.ReadFields();
                    string   id        = fields[0];
                    string   firstname = fields[1];
                    string   lastname  = fields[2];
                    string   password  = fields[3];
                    Int32.TryParse(id, out int memberId);

                    int[]  enrolledClasses       = new int[fields.Length - 4];
                    string enrolledClassesString = "";

                    for (i = 4; i < fields.Length; i++)
                    {
                        string classID = fields[i];
                        Int32.TryParse(classID, out int enrolledClass);

                        if (currentUser.MemberId != memberId)
                        {
                            enrolledClasses[i - 4] = enrolledClass;
                            enrolledClassesString += "," + enrolledClass;
                        }
                        else if (currentUser.MemberId == memberId && classAttended.ClassID != enrolledClass)
                        {
                            enrolledClasses[i - 4] = enrolledClass;
                            enrolledClassesString += "," + enrolledClass;
                        }
                        else if (currentUser.MemberId == memberId && classAttended.ClassID == enrolledClass)
                        {
                            enrolledClassesString += "";
                        }
                    }
                    line = string.Join("", memberId, ',', firstname, ',', lastname, ',', password, enrolledClassesString);
                    lines.Add(line);
                }
            }
            using (StreamWriter SW = new StreamWriter("Bruger.csv"))
            {
                foreach (string l in lines)
                {
                    SW.WriteLine(l);
                }
            }
        }
Example #2
0
 // This method finds and returns the class with the desired ID.
 public FitnessClass FindClassFromID(int classID)
 {
     try
     {
         FitnessClass found = AllTeams.Find(c => c.ClassID == classID);
         return(found);
     }
     catch
     {
         throw new ArgumentException("Class could not be found from classID");
     }
 }
Example #3
0
 // This method turns a string list into at FitnessClass list.
 public List <FitnessClass> FindClassFromStringList(List <string> stringList)
 {
     try
     {
         List <FitnessClass> fitnessClassList = new List <FitnessClass>();
         foreach (string s in stringList)
         {
             FitnessClass found = AllTeams.Find(t => t.Title == s);
             fitnessClassList.Add(found);
         }
         return(fitnessClassList);
     }
     catch
     {
         throw new ArgumentException("Class could not be found from string list");
     }
 }
Example #4
0
        // This method removes the user ID of the user who attended a class,
        // from the classes.csv file.
        public void RemoveUserIDFromClassFile(FitnessClass classAttended)
        {
            List <string> lines = new List <string>();
            string        line;
            User          currentUser = FindUserFromLoginStatus();

            var path = Directory.GetCurrentDirectory() + @"\classes.csv";

            using (TextFieldParser csvParser = new TextFieldParser(path))
            {
                int i = 0;
                csvParser.SetDelimiters(new string[] { ";" });
                csvParser.HasFieldsEnclosedInQuotes = false;

                while (!csvParser.EndOfData)
                {
                    string[] fields        = csvParser.ReadFields();
                    string   classIDString = fields[0];
                    Int32.TryParse(classIDString, out int classID);
                    string teamtitle         = fields[1];
                    string participantString = fields[2];
                    Int32.TryParse(participantString, out int numberofParticipants);
                    string time       = fields[3];
                    string date       = fields[4];
                    string roomString = fields[5];
                    Int32.TryParse(roomString, out int room);
                    string instructor = fields[6];

                    int[]  participantsEnrolled      = new int[fields.Length - 7];
                    string participantsClassesString = "";

                    for (i = 7; i < fields.Length; i++)
                    {
                        string participant = fields[i];
                        Int32.TryParse(participant, out int particpantEnrolled);

                        if (currentUser.MemberId != particpantEnrolled)
                        {
                            participantsEnrolled[i - 7] = particpantEnrolled;
                            participantsClassesString  += ";" + particpantEnrolled;
                        }
                        else if (currentUser.MemberId == particpantEnrolled && classAttended.ClassID != classID)
                        {
                            participantsEnrolled[i - 7] = particpantEnrolled;
                            participantsClassesString  += ";" + particpantEnrolled;
                        }
                        else if (currentUser.MemberId == particpantEnrolled && classAttended.ClassID == classID)
                        {
                            participantsClassesString += "";
                        }
                    }
                    line = string.Join("", classID, ';', teamtitle, ';', numberofParticipants, ';', time, ';', date, ';', room, ';', instructor, participantsClassesString);
                    lines.Add(line);
                }
            }

            using (StreamWriter SW = new StreamWriter("classes.csv"))
            {
                foreach (string l in lines)
                {
                    SW.WriteLine(l);
                }
            }
        }