예제 #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;
            }
        }
예제 #2
0
        private void PhotoOpenClick(object sender, RoutedEventArgs e)
        {
            Img item = ((sender as ListBox).SelectedItem as List <Img>)[0];

            if (item != null)
            {
                try
                {
                    ShowPhoto photoOpen = new ShowPhoto(item, _userID);
                    photoOpen.Show();
                }
                catch
                {
                    MessageBox.Show("Failed to load image");
                }
            }
        }
예제 #3
0
        /*
         * The function return the location of the last 4 photos.
         * (HomePage)
         */
        public List <Img> getLastPhotos()
        {
            List <Img> photosList = new List <Img>();

            // Create the get request msg
            string condition = url + "*/Pictures/LIMIT 4";

            // Get the response from the server.
            string rsponse;

            try
            {
                rsponse = getRequest(condition);
            }
            catch (Exception err)
            {
                throw err;
            }

            // Convert data to json.
            JObject json = JObject.Parse(rsponse);
            JArray  data = (JArray)json.SelectToken("data"); // Take the only the "data"

            foreach (var field in data)
            {
                Img photo = new Img();
                photo.name    = field.SelectToken("Name").ToString();
                photo.ID      = int.Parse(field.SelectToken("ID").ToString());
                photo.date    = field.SelectToken("Creation_date").ToString();
                photo.Path    = field.SelectToken("Location").ToString();
                photo.albumID = int.Parse(field.SelectToken("Album_id").ToString());

                photosList.Add(photo);
            }

            return(photosList);
        }
예제 #4
0
        /*
         * The function create new photo
         */
        public void createImage(Img newPhoto)
        {
            string urlCreate = this.url + "picture/";
            string data      = "name=" + newPhoto.name + "&creation_date=" + newPhoto.date + "&location=" + newPhoto.Path + "&album_id=" + newPhoto.albumID;

            string response;

            try
            {
                response = postRequest(urlCreate, data);
            }
            catch (Exception err)
            {
                throw err;
            }

            // Convert data to json.
            JObject json = JObject.Parse(response);

            if (json.ContainsKey("error"))
            {
                throw new Exception("Error while creating the photo.");
            }
        }
예제 #5
0
        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);
                    }
                }
            }
        }