/// <summary>
        /// Adds the photo.
        /// </summary>
        public static void AddPhoto()
        {
            string thumbnailPath = ConfigurationManager.AppSettings["thumbnailDirectory"].ToString();
            string connectionString = ConnectionStringHelper.GetActualConnectionString();

            OpenFileDialog openImage = new OpenFileDialog();
            openImage.Filter = "Pliki obrazów (*.jpg, *.png, *.crt, *.tiff)|*.jpg;*.JPG;*.jpeg;*.JPEG;*.png;*.PNG;*.crt;*.CRT;*.tiff;*.TIFF|Wszystkie pliki (*.*)|*.*";
            openImage.ShowDialog();

            if (openImage.CheckFileExists && !string.IsNullOrWhiteSpace(openImage.FileName))
            {
                string openedImageName = openImage.FileName;
                string fileName = Path.GetFileName(openedImageName);
                string filePath = openedImageName.Substring(0, openedImageName.Length - fileName.Length);
                string newFilePath = ChangePath(filePath);

                Bitmap image = AForge.Imaging.Image.FromFile(openedImageName);

                int[] thumbnailSizes = GetThumbnailSize(image.Width, image.Height);

                int thumbnailWidth = thumbnailSizes[0];
                int thumbnailHeight = thumbnailSizes[1];

                AForge.Imaging.Filters.ResizeBicubic filter = new AForge.Imaging.Filters.ResizeBicubic(thumbnailWidth, thumbnailHeight);
                Bitmap thumbnail = filter.Apply(image);

                string thumbnailFileName = LookForFreeFilename(thumbnailPath, fileName);
                string thumbnailSavedPath = Path.Combine(thumbnailPath, thumbnailFileName);

                thumbnail.Save(thumbnailSavedPath);
                newFilePath = newFilePath + fileName;

                PhotosDataSource db = new PhotosDataSource(connectionString);
                Photo photoObject = new Photo();

                photoObject.FilePath = newFilePath;
                photoObject.ThumbnailPath = thumbnailSavedPath;

                photoObject.Title = fileName;
                photoObject.Description = string.Empty;

                photoObject.Archive = null;
                photoObject.Attribute = null;

                db.AddPhoto(photoObject);
            }
        }
        private void FixupPhoto(Photo previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.Tags2Photos.Contains(this))
            {
                previousValue.Tags2Photos.Remove(this);
            }

            if (Photo != null)
            {
                if (!Photo.Tags2Photos.Contains(this))
                {
                    Photo.Tags2Photos.Add(this);
                }

                PhotoID = Photo.ID;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Photo")
                    && (ChangeTracker.OriginalValues["Photo"] == Photo))
                {
                    ChangeTracker.OriginalValues.Remove("Photo");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Photo", previousValue);
                }
                if (Photo != null && !Photo.ChangeTracker.ChangeTrackingEnabled)
                {
                    Photo.StartTracking();
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the CloseButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            selectedPhoto = null;
            close = true;

            ((MainWindow)Application.Current.MainWindow).UpdateTagCloud();

            PhotosDataSource dataSource = new PhotosDataSource(ConnectionStringHelper.GetActualConnectionString());
            ((MainWindow)Application.Current.MainWindow).GetAndShowImagesFromDatabase(dataSource.GetAllPhotos());

            PhotoThumbnail.Source = errorImage.Source;

            Close();
        }
 /// <summary>
 /// Refresh window.
 /// </summary>
 /// <param name="parameter">Selected photo.</param>
 public void Refresh(Object parameter)
 {
     selectedPhoto = (Entities.Photo)parameter;
     ViewThumbnail();
     ViewPhotoTags();
 }
 /// <summary>
 /// Delete selected Photo.
 /// </summary>
 /// <param name="toDelete">Photo to delete.</param>
 /// <returns>Deleting photo operation state.</returns>
 public static bool DeletePhoto(Photo toDelete)
 {
     PhotosDataSource db = new PhotosDataSource(ConnectionStringHelper.GetActualConnectionString());
     return db.DeletePhoto(toDelete.ID);
 }