public bool VerifBdd(User newUser)
        {
            var pseudo = RequestWebApi.GetUserPseudo(newUser.Pseudo);
            var email  = RequestWebApi.GetUserEmail(newUser.Email);

            if (pseudo == null && email == null)
            {
                RequestWebApi.PostUser(newUser);
                return(false);
            }
            else if (pseudo != null)
            {
                EmptyField emptyField = new EmptyField("Username already exist !");
                emptyField.ShowDialog();
                return(true);
            }
            else if (email != null)
            {
                EmptyField emptyField = new EmptyField("Email already exist !");
                emptyField.ShowDialog();
                return(true);
            }
            else
            {
                return(true);
            }
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)

        {
            if (listBox1.SelectedItem != null)
            {
                var itemSelected = listBox1.SelectedIndex;
                RequestWebApi.DeleteTask(ListItems[itemSelected].Id);
                ListItems.RemoveAt(itemSelected);
            }
            else
            {
                NoItemSelected error = new NoItemSelected();
                error.ShowDialog();
            }
        }
        private void Button_Login_Click(object sender, RoutedEventArgs e)
        {
            var test = RequestWebApi.GetUser(TBUsername.Text, PBPsw.Password.ToString());

            if (test != null)
            {
                CurrentUser.currentUser = test;
                LaListe liste = new LaListe();
                liste.Show();
                this.Close();
            }
            else
            {
                EmptyField emptyField = new EmptyField("Username or Password is not valid !");
                emptyField.ShowDialog();
            }
        }
        public LaListe()
        {
            InitializeComponent();
            var todolist = RequestWebApi.GetToDoList(CurrentUser.currentUser.Id).FirstOrDefault();

            textboxtitlelist.Text = todolist.Title;
            Listprivate.Id        = todolist.Id;
            var tasks = RequestWebApi.GetTasks(todolist.Id).ToList();

            textblockpseudo.Text = CurrentUser.currentUser.Pseudo;

            //Add list to observable collection
            foreach (var item in tasks)
            {
                ListItems.Add(item);
            }

            listBox1.ItemsSource = ListItems;
        }
        private void add_Click(object sender, RoutedEventArgs e)

        {
            string messagetest = textBox1.Text.Trim(' ');

            if (messagetest != "")
            {
                Task newTask = new Task {
                    Content = textBox1.Text, IdList = Listprivate.Id, Position = ListItems.Count
                };
                RequestWebApi.PostTask(newTask);
                newTask.Id = RequestWebApi.GetLastTask().Id;
                ListItems.Add(newTask);
                textBox1.Text = "";
            }
            else
            {
                EmptyField error = new EmptyField("Empty field !");
                error.ShowDialog();
                textBox1.Text = "";
            }
        }
 public void button_valider_click(object sender, RoutedEventArgs e)
 {
     selectedtask.Content = textBox1.Text;
     RequestWebApi.PutTask(selectedtask);
     this.Close();
 }
        private void Button_SignUp_Click(object sender, RoutedEventArgs e)
        {
            string strEMail = textboxEmail.Text;

            bool isMailValid = false;

            try
            {
                var addr = new MailAddress(strEMail);
                //addr.Address == strEMail;
                isMailValid = true;
            }

            catch
            {
                isMailValid = false;
            }

            if (textboxUsername.Text.Trim(' ') != "" &&
                textboxUsername.Text.Length >= 4 &&
                textboxUsername.Text.Length <= 20 &&
                textboxEmail.Text.Trim(' ') != "" &&
                isMailValid &&
                textboxPassword.Password.ToString() == textboxConfirmationPassword.Password.ToString() &&
                textboxPassword.Password.ToString().Trim(' ') != "" &&
                textboxPassword.Password.ToString().Length >= 6)
            {
                User newUser = new User {
                    Pseudo = textboxUsername.Text, Email = textboxEmail.Text, Psw = textboxPassword.Password.ToString()
                };
                if (!VerifBdd(newUser))
                {
                    CurrentUser.currentUser = RequestWebApi.GetLastUser();
                    RequestWebApi.PostList(new ToDoList {
                        IdUser = CurrentUser.currentUser.Id, Title = "Title of my list"
                    });
                    LaListe liste = new LaListe();
                    this.Close();
                    liste.Show();
                }
            }
            else if (textboxUsername.Text.Trim(' ') == "")
            {
                EmptyField emptyField = new EmptyField("Username is empty !");
                emptyField.ShowDialog();
            }
            else if (textboxUsername.Text.Length < 4 || textboxUsername.Text.Length > 20)
            {
                EmptyField emptyField = new EmptyField("Username need to have more than 4 characters and less than 20 characters !");
                emptyField.ShowDialog();
            }
            else if (textboxEmail.Text.Trim(' ') == "")
            {
                EmptyField emptyField = new EmptyField("Email is empty !");
                emptyField.ShowDialog();
            }
            else if (isMailValid == false)
            {
                EmptyField emptyField = new EmptyField("Email is not an email !");
                emptyField.ShowDialog();
            }
            else if (textboxPassword.Password.ToString().Trim(' ') == "")
            {
                EmptyField emptyField = new EmptyField("Password is empty !");
                emptyField.ShowDialog();
            }
            else if (textboxPassword.Password.ToString().Length < 6)
            {
                EmptyField emptyField = new EmptyField("Password need to have more than 6 characters !");
                emptyField.ShowDialog();
            }
            else if (textboxPassword.Password.ToString() != textboxConfirmationPassword.Password.ToString())
            {
                EmptyField emptyField = new EmptyField("Confirmation password need to be the same as password !");
                emptyField.ShowDialog();
            }
        }