public List <AlbumDataModel> GetAlbums() { using (TheContext ctx = new TheContext()) { var albumList = ctx.Albums.Include("Photos").ToList(); return(albumList); } }
public PhotoDataModel GetPhotoById(Guid id) { using (TheContext ctx = new TheContext()) { var photo = ctx.Photos.Include("Comments").FirstOrDefault(x => x.PhotoId == id); return(photo); } }
public AlbumDataModel GetAlbumById(Guid id) { using (TheContext ctx = new TheContext()) { var album = ctx.Albums.Include("Photos").FirstOrDefault(a => a.AlbumId == id); return(album); } }
public IEnumerable <PhotoDataModel> GetRecentUploads(int count) { using (TheContext ctx = new TheContext()) { var list = ctx.Photos.OrderByDescending(x => x.UploadDate).Take(count).ToList(); return(list); } }
public void AddNewPhoto(PhotoDataModel photo) { using (TheContext ctx = new TheContext()) { ctx.Photos.Add(photo); ctx.SaveChanges(); } }
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); } }
public List <PhotoDataModel> GetPhotos() { using (TheContext ctx = new TheContext()) { var list = ctx.Photos.ToList(); return(list); } }
public UserDataModel GetUserById(Guid id) { using (TheContext ctx = new TheContext()) { var currentUser = ctx.Users.Include("Albums").Single(u => u.UserId == id); return(currentUser); } }
public void AddNewUser(UserDataModel user) { using (TheContext ctx = new TheContext()) { ctx.Users.Add(user); ctx.SaveChanges(); } }
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()); } }
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()); } }
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(); } }
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(); } }
public List <CommentDataModel> GetPhotoComments(Guid id) { using (TheContext ctx = new TheContext()) { var comments = ctx.Comments.Where(c => c.PhotoId == id).ToList(); return(comments); } }
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(); } }
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(); } }
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(); } }
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(); } }