Beispiel #1
0
 public int IncreaseLikes(int likes, Meme meme)
 {
     using (var context = new ContextOfMemes())
     {
         likes++;
         var memeInDB = context.Memes.First(m => m.Id == meme.Id).Likes = likes;
         context.SaveChanges();
         OnLikesChanged?.Invoke(likes);
         return(likes);
     }
 }
Beispiel #2
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.");
         }
     }
 }
Beispiel #3
0
 public void AddUsersMeme(UsersMeme umeme)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             context.UserMemes.Add(umeme);
             context.SaveChanges();
             UsersMemesChanged?.Invoke(umeme);
         }
         catch (Exception)
         {
             throw new Exception("Error during adding group to database.");
         }
     }
 }
Beispiel #4
0
 public void AddGroup(Group group)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             context.Groups.Add(group);
             context.SaveChanges();
             GroupsChanged?.Invoke(group);
         }
         catch (Exception)
         {
             throw new Exception("Error during adding group to database.");
         }
     }
 }
Beispiel #5
0
 public void EditGroup(Group group, string url, string name)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             context.Groups.ToList().Find(g => g.Id == group.Id).Url  = url;
             context.Groups.ToList().Find(g => g.Id == group.Id).Name = name;
             context.SaveChanges();
             GroupsChanged?.Invoke(group);
         }
         catch (Exception)
         {
             throw new Exception("Error during editing group in database.");
         }
     }
 }
Beispiel #6
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.");
         }
     }
 }
Beispiel #7
0
 public void DeleteGroup(Group group)
 {
     using (var context = new ContextOfMemes())
     {
         try
         {
             var groupInDB = context.Groups.First(g => g.Id == group.Id);
             context.Groups.Remove(groupInDB);
             context.SaveChanges();
             GroupsChanged?.Invoke(group);
         }
         catch (Exception)
         {
             throw new Exception("No delete was provided succesfully.");
         }
     }
 }
Beispiel #8
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.");
         }
     }
 }