Exemplo n.º 1
0
        public void ShowPersonalMessage(int id)
        {
            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();
            Trainer me = trainers.Where(t => t.Id == id).First();

            ConsoleUI.ShowLine($"Hello {me.FirstName} {me.LastName}");
        }
Exemplo n.º 2
0
        public static bool IsEmptyDB()
        {
            int UserSize       = DBUser.ReadUsers().Count();
            int AssignmentSize = DBAssignment.ReadAssignments().Count();
            int StudentSize    = DBStudent.ReadStudents().Count();
            int CourseSize     = DBCourse.ReadCourses().Count();
            int TrainerSize    = DBTrainer.ReadTrainers().Count();

            bool basicEntities = UserSize == 0 &&
                                 AssignmentSize == 0 &&
                                 StudentSize == 0 &&
                                 CourseSize == 0 &&
                                 TrainerSize == 0;


            return(basicEntities);
        }
Exemplo n.º 3
0
        public void Read()
        {
            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("no trainers yet");
            }
            else
            {
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }
            ConsoleUI.ReadKey();
            ConsoleUI.Clear();
        }
Exemplo n.º 4
0
        public void Delete()
        {
            bool exit;


            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("no trainers yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select trainer to delete, type 0 to exit");
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }


            exit = ConsoleUI.GetInt(out int TrainerID, "give trainer id: ");
            if (exit)
            {
                return;
            }

            Trainer trainer;

            try
            {
                trainer = trainers.Where(t => t.Id == TrainerID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO TRAINER FOUND WITH ID: {TrainerID}");
                ConsoleUI.ReadKey();
                return;
            }

            bool confirmed = ConsoleUI.GetConfirmation($"are you sure you want to delete trainer {trainer.FirstName} {trainer.LastName}? [y/n]: ");

            int result = 0;

            if (confirmed)
            {
                try
                {
                    result = DBTrainer.DeleteTrainer(TrainerID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete trainer");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                try
                {
                    result = DBUser.DeleteUser(TrainerID);
                    if (result == 0)
                    {
                        throw new Exception("could NOT delete user");
                    }
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }

                ConsoleUI.ShowLine("trainer deleted successfully");

                ConsoleUI.ReadKey();
            }
        }
Exemplo n.º 5
0
        public void Update()
        {
            bool exit;


            ICollection <Trainer> trainers = DBTrainer.ReadTrainers();

            if (trainers.Count() == 0)
            {
                ConsoleUI.ShowLine("No trainers yet");
                ConsoleUI.ReadKey();
                ConsoleUI.Clear();
                return;
            }
            else
            {
                ConsoleUI.ShowLine("select trainer to update, type 0 to exit");
                foreach (Trainer t in trainers)
                {
                    ConsoleUI.ShowLine(t);
                }
            }


            exit = ConsoleUI.GetInt(out int TrainerID, "give trainer id: ");
            if (exit)
            {
                return;
            }

            ConsoleUI.Clear();

            Trainer trainer;

            try
            {
                trainer = trainers.Where(t => t.Id == TrainerID).First();
            }
            catch (Exception)
            {
                ConsoleUI.ShowLine($"NO TRAINER FOUND WITH ID: {TrainerID}");
                ConsoleUI.ReadKey();
                return;
            }

            ConsoleUI.ShowLine($"you selected to edit trainer: {trainer.FirstName} {trainer.LastName}");

            ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit");
            ConsoleUI.ShowLine("1. Username");
            ConsoleUI.ShowLine("2. Password");
            ConsoleUI.ShowLine("3. First name");
            ConsoleUI.ShowLine("4. Last name");
            ConsoleUI.ShowLine("5. Subject");

            exit = ConsoleUI.GetInt(out int choice);
            if (exit)
            {
                return;
            }
            ConsoleUI.Clear();

            Object attribute;

            if (choice == 1 || choice == 2)
            {
                attribute = (UserAttributes)choice;
            }
            else
            {
                attribute = (TrainerAttributes)choice;
            }

            string newInput = "";


            bool entitySpecificUpdate = false;

            switch (attribute)
            {
            case TrainerAttributes.Fname:
                exit = ConsoleUI.GetString(out newInput, "enter new first name: ");
                entitySpecificUpdate = true;
                break;

            case TrainerAttributes.Lname:
                exit = ConsoleUI.GetString(out newInput, "enter new last name: ");
                entitySpecificUpdate = true;
                break;

            case TrainerAttributes.Subject:
                exit = ConsoleUI.GetString(out newInput, "enter new subject: ");
                entitySpecificUpdate = true;
                break;

            case UserAttributes.Username:
                exit = ConsoleUI.GetString(out newInput, "enter new username: "******"enter new password: "******"trainer update failed");
                    }
                    ConsoleUI.ShowLine("trainer updated successfully");
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }
            }
            else
            {
                try
                {
                    result = DBUser.UpdateUser(TrainerID, attribute, newInput);
                    if (result == 0)
                    {
                        throw new Exception("user update failed");
                    }
                    ConsoleUI.ShowLine("user updated successfully");
                }
                catch (Exception e)
                {
                    ConsoleUI.ShowLine(e.Message);
                    ConsoleUI.ReadKey();
                    return;
                }
            }


            ConsoleUI.ReadKey();
        }