Exemple #1
0
 public void AddMeme(Meme meme)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             context.Memes.Add(meme);
             context.SaveChanges();
             MemesChanged?.Invoke(meme);
         }
         catch (Exception)
         {
             throw new Exception("Error during adding meme to database.");
         }
     }
 }
Exemple #2
0
 public void DeleteMeme(Meme meme)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             var memeInDB = context.Memes.First(m => m.Id == meme.Id);
             context.Memes.Remove(memeInDB);
             context.SaveChanges();
             MemesChanged?.Invoke(meme);
         }
         catch (Exception)
         {
             throw new Exception("No delete was provided succesfully.");
         }
     }
 }
Exemple #3
0
 public void EditMeme(Meme editedmeme, string name, int year, string description, string imagePath)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             context.Memes.ToList().Find(m => m.Id == editedmeme.Id).Name        = name;
             context.Memes.ToList().Find(m => m.Id == editedmeme.Id).Year        = year;
             context.Memes.ToList().Find(m => m.Id == editedmeme.Id).Description = description;
             context.Memes.ToList().Find(m => m.Id == editedmeme.Id).ImagePath   = imagePath;
             context.SaveChanges();
             MemesChanged?.Invoke(editedmeme);
         }
         catch (Exception)
         {
             throw new Exception("Editing was provided incorrectly.");
         }
     }
 }