Ejemplo n.º 1
0
        public static void DoPwdAction()
        {
            string            choose   = ChoosePasswordMenu();
            string            title    = null;
            string            password = null;
            int               id       = 0;
            Pwd               pwd      = null;
            Student           student  = null;
            IEnumerable <Pwd> pwds     = null;

            try
            {
                switch (choose)
                {
                case "1":
                    Console.Write("Entrez le titre : ");
                    title = Console.ReadLine();
                    Console.Write("Entrez le mot de passe : ");
                    password = Console.ReadLine();

                    do
                    {
                        Console.Write("Entrez le campusid de l'étudiant : ");
                        id      = int.Parse(Console.ReadLine());
                        student = Manager.StudentDAO.Find(id);
                    }while (student == null);



                    pwd = new Pwd()
                    {
                        Title     = password,
                        Password  = title,
                        StudentId = student.Id
                    };
                    Manager.PwdDAO.Add(pwd);
                    Console.WriteLine("Enregistrement effectué avec succès !");
                    System.Threading.Thread.Sleep(1000);
                    DoPwdAction();
                    break;

                case "2":
                    Console.Write("Entrer le titre : ");
                    title = Console.ReadLine();
                    pwds  = Manager.PwdDAO.FindAll(title);
                    Pwd.ChowPassword(pwds);

                    Console.ReadKey();
                    DoStudentAction();

                    break;

                case "3":
                    pwds = Manager.PwdDAO.FindAll();
                    Pwd.ChowPassword(pwds);
                    Console.WriteLine("\n");
                    Console.Write("Entrer l'id : ");
                    id  = int.Parse(Console.ReadLine());
                    pwd = Manager.PwdDAO.Find(id);
                    if (pwd != null)
                    {
                        Console.Write("Entrez le titre : ");
                        title = Console.ReadLine();
                        Console.Write("Entrez le mot de passe : ");
                        password = Console.ReadLine();

                        do
                        {
                            Console.Write("Entrez le campusid de l'étudiant : ");
                            string myid = Console.ReadLine();
                            if (string.IsNullOrEmpty(myid))
                            {
                                myid = pwd.Id.ToString();
                            }
                            id      = int.Parse(myid);
                            student = Manager.StudentDAO.Find(id);
                        }while (student == null);

                        pwd.Title     = string.IsNullOrEmpty(title)? pwd.Title : title;
                        pwd.Password  = string.IsNullOrEmpty(password)  ? pwd.Password : password;
                        pwd.StudentId = student.Id;

                        Manager.PwdDAO.Edit(pwd);
                        Console.WriteLine("Enregistrement effectué avec succès !");
                    }
                    else
                    {
                        Console.WriteLine("Aucun mot de passe trouvé !");
                    }
                    System.Threading.Thread.Sleep(1000);
                    DoPwdAction();
                    break;

                case "4":
                    pwds = Manager.PwdDAO.FindAll();
                    Pwd.ChowPassword(pwds);
                    Console.WriteLine("\n");

                    Console.Write("Entrer l'id : ");
                    id  = int.Parse(Console.ReadLine());
                    pwd = Manager.PwdDAO.Find(id);
                    if (pwd != null)
                    {
                        Manager.PwdDAO.Remove(pwd);
                        Console.WriteLine("Suppression effectué avec succès !");
                    }
                    else
                    {
                        Console.WriteLine("Aucun Mot de passe trouvé !");
                    }
                    System.Threading.Thread.Sleep(1000);
                    DoPwdAction();
                    break;

                default:
                    DoAction();
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }