Exemple #1
0
        private void displayImage(Img photo)
        {
            try
            {
                var uriSource = new Uri(photo.Path, UriKind.Absolute);
                ImageNameLabel.Content = photo.name;
                Image.Source           = new BitmapImage(uriSource);

                IdText.Text       = "Id: " + photo.ID;
                CreationDate.Text = "Date: " + photo.date;
                AlbumID.Text      = "Album Id: " + photo.albumID.ToString();
                photoName.Text    = "Name: " + photo.name;

                List <string> usersList = api.getTaggedUsers(photo);
                UsersTags.Text = "";
                int i = 0;
                for (i = 0; i < usersList.Count() - 1; i++)
                {
                    UsersTags.Text += usersList[i];

                    // Add new line after 4 names in a row.
                    if ((i + 1) % 4 == 0)
                    {
                        UsersTags.Text += System.Environment.NewLine;
                    }
                    else
                    {
                        UsersTags.Text += ", ";
                    }
                }
                if (usersList.Count() > 0)
                {
                    UsersTags.Text += usersList[i];
                }

                TagsAmount.Text = "Tags amount: " + usersList.Count().ToString();

                // If photo is not of user hide delete button.
                if (_userId != api.getPhotoOwner(photo).ToString())
                {
                    ChangePhoto.Visibility = System.Windows.Visibility.Hidden;
                }
            }
            catch
            {
                throw;
            }
        }
        private void acceptBTN_Click(object sender, RoutedEventArgs e)
        {
            if (this._newAlbum)// If its new albums option.
            {
                if (AlbumName.Text.Length == 0)
                {
                    AlbumName.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("Album Name Empty");
                    return;
                }
                else if (api.CheckAlbumName(AlbumName.Text))
                {
                    AlbumName.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("Album Name Taken");
                    return;
                }
                else
                {
                    Album newAlbum = new Album();
                    newAlbum.name    = AlbumName.Text;
                    newAlbum.ownerID = this._ownerID;

                    var      dataTime  = new CultureInfo("en-GB");
                    DateTime localDate = DateTime.Now;
                    newAlbum.date = localDate.ToString(dataTime);
                    try
                    {
                        api.createAlbum(newAlbum);
                        MessageBox.Show("New Album was added.");
                        this.Close();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
            }
            else if (!this._NewPic) // If its Un/Tag user
            {
                if (Username.Text.Length == 0)
                {
                    Username.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("UserName Empty");
                }
                else if (!api.userExist(Username.Text))
                {
                    Username.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("UserName dosent exist.");
                }
                else
                {
                    if (!this._tag)
                    {
                        List <string> users = api.getTaggedUsers(this._photo);
                        if (users.IndexOf(Username.Text) == -1)
                        {
                            Username.BorderBrush = System.Windows.Media.Brushes.Red;
                            MessageBox.Show("UserName isnt tagged.");
                            return;
                        }
                    }
                    else
                    {
                        List <string> users = api.getTaggedUsers(this._photo);
                        if (users.IndexOf(Username.Text) != -1)
                        {
                            Username.BorderBrush = System.Windows.Media.Brushes.Red;
                            MessageBox.Show("UserName is tagged.");
                            return;
                        }
                    }
                    try
                    {
                        if (this._tag)
                        {
                            api.addTag(_photo.ID.ToString(), api.getUserId(Username.Text));
                            MessageBox.Show("Tag was created.");
                            this.Close();
                        }
                        else
                        {
                            api.deleteTag(_photo.ID.ToString(), api.getUserId(Username.Text));
                            MessageBox.Show("User was untaged.");
                            this.Close();
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                        this.Close();
                    }
                }
            }
            else // If its new picture.
            {
                if (PicName.Text.Length == 0)
                {
                    PicName.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("Photo Name empty.");
                    return;
                }
                else if (api.CheckNameInAlbum(this._album, PicName.Text))
                {
                    PicName.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("Name cannot be use.");
                    return;
                }
                else if (Location.Text.Length == 0)
                {
                    Location.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("Location empty.");
                    return;
                }
                else if (!System.IO.File.Exists(Location.Text))
                {
                    Location.BorderBrush = System.Windows.Media.Brushes.Red;
                    MessageBox.Show("File doesnt exist.");
                    return;
                }
                else
                {
                    Img newPhoto = new Img();
                    newPhoto.albumID = this._album.ID;
                    newPhoto.Path    = Location.Text;
                    newPhoto.name    = PicName.Text;
                    var      dataTime  = new CultureInfo("en-GB");
                    DateTime localDate = DateTime.Now;
                    newPhoto.date = localDate.ToString(dataTime);
                    try
                    {
                        api.createImage(newPhoto);
                        MessageBox.Show("New photo was added.");
                        this.Close();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
            }
        }