Пример #1
0
 public List <AlbumDataModel> GetAlbums()
 {
     using (TheContext ctx = new TheContext())
     {
         var albumList = ctx.Albums.Include("Photos").ToList();
         return(albumList);
     }
 }
Пример #2
0
 public PhotoDataModel GetPhotoById(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var photo = ctx.Photos.Include("Comments").FirstOrDefault(x => x.PhotoId == id);
         return(photo);
     }
 }
Пример #3
0
 public AlbumDataModel GetAlbumById(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id);
         return(album);
     }
 }
Пример #4
0
 public IEnumerable <PhotoDataModel> GetRecentUploads(int count)
 {
     using (TheContext ctx = new TheContext())
     {
         var list = ctx.Photos.OrderByDescending(x => x.UploadDate).Take(count).ToList();
         return(list);
     }
 }
Пример #5
0
 public void AddNewPhoto(PhotoDataModel photo)
 {
     using (TheContext ctx = new TheContext())
     {
         ctx.Photos.Add(photo);
         ctx.SaveChanges();
     }
 }
Пример #6
0
 public UserDataModel LoginUser(UserDataModel user)
 {
     using (TheContext ctx = new TheContext())
     {
         var userToLogin = ctx.Users.FirstOrDefault(x => x.Mail == user.Mail && x.Password == user.Password);
         return(userToLogin);
     }
 }
Пример #7
0
 public List <PhotoDataModel> GetPhotos()
 {
     using (TheContext ctx = new TheContext())
     {
         var list = ctx.Photos.ToList();
         return(list);
     }
 }
Пример #8
0
 public UserDataModel GetUserById(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var currentUser = ctx.Users.Include("Albums").Single(u => u.UserId == id);
         return(currentUser);
     }
 }
Пример #9
0
 public void AddNewUser(UserDataModel user)
 {
     using (TheContext ctx = new TheContext())
     {
         ctx.Users.Add(user);
         ctx.SaveChanges();
     }
 }
Пример #10
0
 public List <AlbumDataModel> GetUserAlbum(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var userAlbum = ctx.Users.Include("Albums").FirstOrDefault(u => u.UserId == id);
         return(userAlbum.Albums.ToList());
     }
 }
Пример #11
0
 public List <PhotoDataModel> GetAlbumPhotos(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.Include("Photos").FirstOrDefault(x => x.AlbumId == id);
         return(album.Photos.ToList());
     }
 }
Пример #12
0
 public void DeleteAlbum(Guid id)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id);
         ctx.Albums.Remove(album);
         ctx.SaveChanges();
     }
 }
Пример #13
0
 public void SavePhotoInAlbum(Guid id, PhotoDataModel photo)
 {
     using (TheContext ctx = new TheContext())
     {
         var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id);
         album.Photos.Add(photo);
         ctx.SaveChanges();
     }
 }
Пример #14
0
        public List <CommentDataModel> GetPhotoComments(Guid id)
        {
            using (TheContext ctx = new TheContext())
            {
                var comments = ctx.Comments.Where(c => c.PhotoId == id).ToList();

                return(comments);
            }
        }
Пример #15
0
 public void AddNewAlbum(AlbumDataModel album, Guid userId)
 {
     using (TheContext ctx = new TheContext())
     {
         ctx.Albums.Add(album);
         var user = ctx.Users.Include("Albums").FirstOrDefault(x => x.UserId == userId);
         user.Albums.Add(album);
         ctx.SaveChanges();
     }
 }
Пример #16
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();
            }
        }
Пример #17
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();
            }
        }
Пример #18
0
        public void AddNewComment(Guid photoId, CommentDataModel 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();
            }
        }