public IActionResult Index()
        {
            PictureContext context = HttpContext.RequestServices.GetService(typeof(ConnectString.Models.PictureContext))
                                     as PictureContext;

            return(View(context.GetAllPicture()));
        }
Beispiel #2
0
        // Delete image and all it's details
        public async void deleteImage(int id, string pictureName)
        {
            // Get access to database
            using (var db = new PictureContext())
            {
                // Find id in database
                var image = db.Pictures.Single(i => i.pictureId == id);

                // Remove data from database
                db.Remove(image);

                // Save chanages to database
                await db.SaveChangesAsync();

                // ===== DELETE FILE FROM LOCAL STORAGE =====

                try
                {
                    // Point to the local storage folder
                    StorageFile deleteFile = await ApplicationData.Current.LocalFolder.GetFileAsync(pictureName);

                    // If file exists then delete it
                    if (deleteFile != null)
                    {
                        await deleteFile.DeleteAsync();
                    }
                }
                catch (System.IO.FileNotFoundException) { }
            } // End using
        }     // End deleteImage
Beispiel #3
0
        }// End method SearchForFile

        // This method saves the image path and its label to the database
        private void SaveToDB_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Get access to resources for localisation
            var loader = new Windows.ApplicationModel.Resources.ResourceLoader();

            // Retrieve reqired strings
            var textValidation    = loader.GetString("ImageDetailsTextValidation");
            var noLabelValidation = loader.GetString("ImageDetailsNoLabelValidation");

            // Get text from label textbox
            string label = Label.Text;

            // Check that string is 20 characters or less
            if (label.Length <= 20)
            {
                // ----------  Adapted from https://msdn.microsoft.com/en-us/library/system.string.isnullorempty(v=vs.110).aspx  ----------
                // If the label textbox has text in it
                if (!String.IsNullOrEmpty(label))
                {
                    // ==========  SAVE TO DATABASE  ==========

                    // Get access to the database
                    using (var db = new PictureContext())
                    {
                        // Store image path and label into model
                        var picture = new Picture {
                            picturePath = imagePath, pictureLabel = label
                        };

                        // Add picture to table
                        db.Pictures.Add(picture);

                        // Save the database with the new picture
                        db.SaveChangesAsync();
                    }// End using

                    // Clear the textbox
                    label = "";

                    // Navigate back to main page
                    this.Frame.Navigate(typeof(MainPage));
                }// End if
                else
                {
                    // Display message to user saying the picture must have a label
                    TextValidation.Text = noLabelValidation;
                }// End if (String is empty or not)
            }
            else
            {
                // Display message to user saying it must be 20 characters or less
                TextValidation.Text = textValidation;
            }// End if (string is 20 characters or not)

            // Clear the textbox
            label = "";
        }// End SaveToDB_Click
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new PictureContext())
            {
                db.Database.Migrate();
            }
        }
Beispiel #5
0
        public static ObservableCollection <Picture> loadData()
        {
            // Load all data from database
            using (var context = new PictureContext())
            {
                // Load all data into a list
                var pictures = context.Pictures.ToList();

                // Convert list to observable collection
                ObservableCollection <Picture> oPictures = new ObservableCollection <Picture>(pictures);

                return(oPictures);
            } // End using
        }     // End loadData
Beispiel #6
0
        }     // End deleteImage

        // Update the label in the database
        public async void updateLabel(int id, string newLabel)
        {
            // Get access to database
            using (var db = new PictureContext())
            {
                // Find id in database
                var label = db.Pictures.Single(i => i.pictureId == id);

                // Update the label
                label.pictureLabel = newLabel;

                // Save changes
                await db.SaveChangesAsync();
            } //End using
        }     // End updateLabel
 public static void Initialize(PictureContext context)
 {
     if (!context.Pictures.Any())
     {
         context.Pictures.AddRange(
             new Picture
         {
             Name     = "3.jpg",
             Likes    = 0,
             Dislikes = 0,
             Grade    = 0
         },
             new Picture
         {
             Name     = "4.jpg",
             Likes    = 0,
             Dislikes = 0,
             Grade    = 0
         }
             );
         context.SaveChanges();
     }
 }
Beispiel #8
0
 public PictureController(PictureContext context)
 {
     db = context;
 }
Beispiel #9
0
 public PicturesController(PictureContext context)
 {
     _context = context;
 }
 public PictureEfService(PictureContext context)
 {
     _context = context;
 }