Example #1
0
        private void AddPhoto(object parameter)
        {
            IMessageBoxService msg      = new MessageBoxService();
            string             filename = msg.OpenFileDlg("Select the file containing the asset's photo", true, false, "Asset Photos(*.PNG; *.JPG)| *.PNG; *.JPG", string.Empty, null);

            if (!string.IsNullOrEmpty(filename) && !string.IsNullOrWhiteSpace(filename))
            {
                FileInfo fi = new FileInfo(filename);
                if (fi.Length > Defaults.MaxPhotoSize)
                {
                    msg.ShowMessage("The photo file size is too large (" + (Defaults.MaxPhotoSize / 1000).ToString() + " kB)", "Photo Size", GenericMessageBoxButton.OK, GenericMessageBoxIcon.Information);
                }
                else
                {
                    //PhotoModel Photo = new PhotoModel(){ ID = 0, AssetID = Asset.ID, Photo = File.ReadAllBytes(filename), PhotoFileName = filename };

                    filename = Path.GetFileName(filename);

                    PhotoModel Photo = new PhotoModel()
                    {
                        ID = 0, AssetID = Asset.ID, PhotoFileName = filename
                    };

                    Photo.ID = SQLiteQueries.AddPhoto(Photo);

                    if (Photo.ID > 0)
                    {
                        Photos.Add(Photo);
                        SelectedPhotoIndex = Photos.Count - 1;
                    }
                }
            }
            else
            {
                //not added
            }
        }