public MediaViewModel GetItem(int itemId)
        {
            var item = new MediaViewModel();

            using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
            {
                var _item = (db.Table <Media>().Where(
                                 c => c.Id == itemId)).Single();
                item.Id           = _item.Id;
                item.Name         = _item.Name;
                item.CreationDate = _item.CreationDate;
                item.VidOrPic     = _item.VidOrPic;
            }
            return(item);
        }
 public ObservableCollection<MediaViewModel> GetItems()
 {
     items = new ObservableCollection<MediaViewModel>();
     using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
     {
         var query = db.Table<Media>().OrderBy(c => c.Id);
         foreach (var _item in query)
         {
             var item = new MediaViewModel()
             {
                 Id = _item.Id,
                 Name = _item.Name,
                 CreationDate = _item.CreationDate,
                 VidOrPic = _item.VidOrPic
             };
             items.Add(item);
         }
     }
     return items;
 }
 public ObservableCollection <MediaViewModel> GetItems()
 {
     items = new ObservableCollection <MediaViewModel>();
     using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
     {
         var query = db.Table <Media>().OrderBy(c => c.Id);
         foreach (var _item in query)
         {
             var item = new MediaViewModel()
             {
                 Id           = _item.Id,
                 Name         = _item.Name,
                 CreationDate = _item.CreationDate,
                 VidOrPic     = _item.VidOrPic
             };
             items.Add(item);
         }
     }
     return(items);
 }
        public string SaveItem(MediaViewModel item)
        {
            string result = string.Empty;

            using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
            {
                try
                {
                    var existingItem = (db.Table <Media>().Where(
                                            c => c.Id == item.Id)).SingleOrDefault();

                    if (existingItem != null)
                    {
                        existingItem.Id       = item.Id;
                        existingItem.Name     = item.Name;
                        existingItem.VidOrPic = item.VidOrPic;

                        int success = db.Update(existingItem);
                    }
                    else
                    {
                        int success = db.Insert(new Media()
                        {
                            Id           = item.Id,
                            Name         = item.Name,
                            CreationDate = item.CreationDate,
                            VidOrPic     = item.VidOrPic
                        });
                    }
                    result = "Success";
                }
                catch
                {
                    result = "This item was not saved.";
                }
            }
            return(result);
        }
        /// <summary>
        /// Captures a single frame from the running webcam stream and executes the FaceDetector on the image. If successful calls SetupVisualization to display the results.
        /// </summary>
        /// <returns>Async Task object returning true if the capture was successful and false if an exception occurred.</returns>
        private async Task<bool> TakeSnapshotAndFindFaces()
        {
            bool successful = true;

            try
            {
                if (this.currentState != ScenarioState.Streaming)
                {
                    return false;
                }

                // TODO : photo and video option.

                if(videoOrPic)
                {
                    captureFile = await folder.CreateFileAsync("timeline.mp4", CreationCollisionOption.GenerateUniqueName);
                    await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p), captureFile);

                    //TODO : Link ViewModel
                    
                    media = new MediaViewModel();
                    media.SaveItem(new MediaViewModel
                    {
                        Name = captureFile.DisplayName,
                        CreationDate = captureFile.DateCreated.DateTime,
                        VidOrPic = true
                    });
                   
                }
                else
                {
                    captureFile = await folder.CreateFileAsync("timeline.jpeg", CreationCollisionOption.GenerateUniqueName);
                    await mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), captureFile);
                    //TODO : link ViewMOdel
                    media = new MediaViewModel();
                    media.SaveItem(new MediaViewModel
                    {
                        Name = captureFile.DisplayName,
                        CreationDate = captureFile.DateCreated.DateTime,
                        VidOrPic = false
                    });


                }

                // TODO
            }
            catch (Exception ex)
            {
                this.rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
                successful = false;
            }

            return successful;
        }
        public string SaveItem(MediaViewModel item)
        {
            string result = string.Empty;
            using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
            {
                try
                {
                    var existingItem = (db.Table<Media>().Where(
                        c => c.Id == item.Id)).SingleOrDefault();

                    if (existingItem != null)
                    {
                        existingItem.Id = item.Id;
                        existingItem.Name = item.Name;
                        existingItem.VidOrPic = item.VidOrPic;

                        int success = db.Update(existingItem);
                    }
                    else
                    {
                        int success = db.Insert(new Media()
                        {
                            Id = item.Id,
                            Name = item.Name,
                            CreationDate = item.CreationDate,
                            VidOrPic = item.VidOrPic
                        });
                    }
                    result = "Success";
                }
                catch
                {
                    result = "This item was not saved.";
                }
            }
            return result;
        }
 public MediaViewModel GetItem(int itemId)
 {
     var item = new MediaViewModel();
     using (var db = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
     {
         var _item = (db.Table<Media>().Where(
             c => c.Id == itemId)).Single();
         item.Id = _item.Id;
         item.Name = _item.Name;
         item.CreationDate = _item.CreationDate;
         item.VidOrPic = _item.VidOrPic;
     }
     return item;
 }