Esempio n. 1
0
 public Photo GetPhotoById(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var image = ctx.Photos.Include("Comments").FirstOrDefault(x => x.PhotoId == id);
         return(image);
     }
 }
Esempio n. 2
0
 public Album GettAlbumById(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id);
         return(album);
     }
 }
Esempio n. 3
0
 internal object GetRecentUploads(int count)
 {
     using (TheContext ctx = new TheContext())
     {
         var list = ctx.Photos.OrderByDescending(x => x.UploadDate).Take(count).ToList();
         return(list);
     }
 }
Esempio n. 4
0
 public void AddNewPhoto(Photo photo)
 {
     using (TheContext ctx = new TheContext())
     {
         ctx.Photos.Add(photo);
         ctx.SaveChanges();
     }
 }
Esempio n. 5
0
 public User LoginUser(User user)
 {
     using (TheContext ctx = new TheContext())
     {
         var userToLogin = ctx.Users.FirstOrDefault(x => x.Mail == user.Mail && x.Password == user.Password);
         return(userToLogin);
     }
 }
Esempio n. 6
0
 public User GettUserByID(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var currentUser = ctx.Users.Include("Albums").Single(u => u.UserId == id);
         return(currentUser);
     }
 }
Esempio n. 7
0
 public void AddNewUser(User user)
 {
     using (TheContext ctx = new TheContext())
     {
         ctx.Users.Add(user);
         ctx.SaveChanges();
     }
 }
Esempio n. 8
0
 public List <Photo> GetPhotos()
 {
     using (TheContext ctx = new TheContext())
     {
         var list = ctx.Photos.ToList();
         return(list);
     }
 }
Esempio n. 9
0
        public List <Album> GetAlbums()
        {
            using (TheContext ctx = new TheContext())
            {
                var albumList = ctx.Albums.Include("Photos").ToList();

                return(albumList);
            }
        }
Esempio n. 10
0
 public void DeleteAlbum(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.FirstOrDefault(a => a.AlbumId == id);
         ctx.Albums.Remove(album);
         ctx.SaveChanges();
     }
 }
Esempio n. 11
0
        public void SavePhotoInAlbum(Guid id, Photo photo)
        {
            using (TheContext ctx = new TheContext())
            {
                var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id);

                album.Photos.Add(photo);
                ctx.SaveChanges();
            }
        }
Esempio n. 12
0
        public void DeletePhoto(Guid id)
        {
            using (TheContext ctx = new TheContext())
            {
                var photo = ctx.Photos.FirstOrDefault(p => p.PhotoId == id);

                ctx.Photos.Remove(photo);
                ctx.SaveChanges();
            }
        }
Esempio n. 13
0
        public void DeleteComment(Guid commentId)
        {
            using (TheContext ctx = new TheContext())
            {
                var comment = ctx.Comments.FirstOrDefault(c => c.CommentId == commentId);

                ctx.Comments.Remove(comment);
                ctx.SaveChanges();
            }
        }
Esempio n. 14
0
        public void AddNewAlbum(Album album, Guid userId)
        {
            using (TheContext ctx = new TheContext())
            {
                ctx.Albums.Add(album);

                var user = ctx.Users.FirstOrDefault(x => x.UserId == userId);
                user.Albums.Add(album);
                ctx.SaveChanges();
            }
        }
Esempio n. 15
0
        public void AddNewComment(Guid photoId, Comment comment)
        {
            using (TheContext ctx = new TheContext())
            {
                var photo = ctx.Photos.Single(p => p.PhotoId == photoId);
                photo.Comments.Add(comment);

                ctx.Comments.Add(comment);
                ctx.SaveChanges();
            }
        }