private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ButtonPressed = true;

            /// delete from database and update list

            if (fromControl == (int)ControlTypes.UserPanel)
            {
                UserControl uc = ((((this.Parent as Grid).Parent as Grid).Parent as Grid).Parent as UserControl);
                UserPanel   up = (uc as UserPanel);

                CustomMessageBox cmb = new CustomMessageBox((int)MessageBoxColorTypes.yellow, "Sunteti sigur ca doriti sa stergeti acest anunt?", up, MessageBoxButton.YesNo);


                if (cmb.ShowDialog() == true)
                {
                    if (ad.DeleteFromDataBase())
                    {
                        up.ads.RemoveAt(up.ads.FindIndex(x => x == adID));
                        up.ResetAds();

                        DeleteImages();

                        cmb = new CustomMessageBox((int)MessageBoxColorTypes.green, "Anuntul a fost sters cu succes!", up, MessageBoxButton.OK);
                        cmb.ShowDialog();
                    }
                    else
                    {
                        cmb = new CustomMessageBox((int)MessageBoxColorTypes.red, "A aparut o eroare, daca problema persista va rugam sa contactati un administrator!", up, MessageBoxButton.OK);
                        cmb.ShowDialog();
                    }
                }
            }
            else if (fromControl == (int)ControlTypes.AdvertisementsPage)
            {
                UserControl        uc = (((this.Parent as Grid).Parent as Grid).Parent as UserControl);
                AdvertisementsPage ac = (uc as AdvertisementsPage);

                CustomMessageBox cmb = new CustomMessageBox((int)MessageBoxColorTypes.yellow, "Sunteti sigur ca doriti sa stergeti acest anunt?", ac, MessageBoxButton.YesNo);

                if (cmb.ShowDialog() == true)
                {
                    if (ad.DeleteFromDataBase())
                    {
                        ac.adIds.RemoveAt(ac.adIds.FindIndex(x => x == adID));
                        ac.ResetAds();

                        DeleteImages();

                        cmb = new CustomMessageBox((int)MessageBoxColorTypes.green, "Anuntul a fost sters cu succes!", uc, MessageBoxButton.OK);
                        cmb.ShowDialog();
                    }
                    else
                    {
                        cmb = new CustomMessageBox((int)MessageBoxColorTypes.red, "A aparut o eroare, daca problema persista va rugam sa contactati un administrator!", uc, MessageBoxButton.OK);
                        cmb.ShowDialog();
                    }
                }
            }
        }
        private void Favorite_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ButtonPressed = true;

            if (isFav)
            {
                /// delete from database

                try
                {
                    Variables.conn.Open();

                    MySqlCommand cmd = new MySqlCommand();


                    cmd.CommandText = "delete from anunturi_favorite where idUtilizator = @idUtilizator and idAnunt = @idAnunt";
                    cmd.Connection  = Variables.conn;

                    cmd.Parameters.AddWithValue("idUtilizator", ConnectedUser.id);
                    cmd.Parameters.AddWithValue("idAnunt", adID);

                    if (cmd.ExecuteNonQuery() != 0)
                    {
                        Variables.conn.Close();

                        if (fromControl == (int)ControlTypes.AdvertisementsPage)
                        {
                            UserControl        uc = ((this.Parent as Grid).Parent as Grid).Parent as UserControl;
                            AdvertisementsPage ap = uc as AdvertisementsPage;


                            if (ap.cmbCats.SelectedIndex == (int)Categories.Favorite && ConnectedUser.loggedIn)
                            {
                                ap.adIds.RemoveAt(ap.adIds.FindIndex(x => x == adID));
                                ap.ResetAds();
                            }
                        }

                        Favorite.Source = (Resources["NotFavorite"] as ImageSource);
                        isFav           = false;
                    }
                }
                catch
                {
                    if (Variables.conn.State == System.Data.ConnectionState.Open)
                    {
                        Variables.conn.Close();
                    }
                }
            }
            else
            {
                /// isert  into database

                try
                {
                    Variables.conn.Open();

                    MySqlCommand cmd = new MySqlCommand();


                    cmd.CommandText = "insert into anunturi_favorite (idUtilizator, idAnunt) values (@idUtilizator, @idAnunt)";
                    cmd.Connection  = Variables.conn;

                    cmd.Parameters.AddWithValue("idUtilizator", ConnectedUser.id);
                    cmd.Parameters.AddWithValue("idAnunt", adID);

                    if (cmd.ExecuteNonQuery() != 0)
                    {
                        Variables.conn.Close();

                        isFav           = true;
                        Favorite.Source = (Resources["Favorite"] as ImageSource);
                    }
                }
                catch (Exception ex)
                {
                    if (Variables.conn.State == System.Data.ConnectionState.Open)
                    {
                        Variables.conn.Close();
                    }
                }
            }
        }