예제 #1
0
 public PhotoEntity GetPhoto(int id)
 {
     using (MvcApplicationDB _context = new MvcApplicationDB())
     {
         return(_context.Photos.FirstOrDefault(p => p.PhotoEntityId == id));
     }
 }
예제 #2
0
 public AlbumEntity Get(int albumId)
 {
     using (MvcApplicationDB _context = new MvcApplicationDB())
     {
         return(_context.Albums.FirstOrDefault(a => a.AlbumEntityId == albumId));
     }
 }
예제 #3
0
 public List <AlbumEntity> GetAll()
 {
     using (MvcApplicationDB _context = new MvcApplicationDB())
     {
         return(_context.Albums.ToList());
     }
 }
예제 #4
0
        public List <PhotoEntity> RetrieveAll()
        {
            using (MvcApplicationDB _context = new MvcApplicationDB())
            {
                List <PhotoEntity> allPhotosFromDB = _context.Photos.ToList();

                return(allPhotosFromDB);
            }
        }
예제 #5
0
        public void NewAlbumComment(int albumid, CommentEntity newAlbumComment)
        {
            using (MvcApplicationDB _context = new MvcApplicationDB())
            {
                var albumEntity = _context.Albums.FirstOrDefault(a => a.AlbumEntityId == albumid);

                albumEntity.Comments.Add(newAlbumComment);

                _context.SaveChanges();
            }
        }
예제 #6
0
        public void DeletePhoto(PhotoEntity photo)
        {
            using (MvcApplicationDB _context = new MvcApplicationDB())
            {
                PhotoEntity photoToBeRemoved = _context.Photos
                                               .FirstOrDefault(p => p.PhotoEntityId == photo.PhotoEntityId);

                _context.Photos.Remove(photoToBeRemoved);

                _context.SaveChanges();
            }
        }
예제 #7
0
        public AlbumEntity Add(AlbumEntity newAlbum, int userId)
        {
            using (MvcApplicationDB _context = new MvcApplicationDB())
            {
                //get the owner of the album
                var albumUser = _context.Users.Where(u => u.UserEntityId == userId)
                                .FirstOrDefault();

                //set some properties of the new album
                //newAlbum.AlbumId = Guid.NewGuid();
                newAlbum.DateCreated = DateTime.Now;
                newAlbum.Photos      = new List <PhotoEntity>();
                newAlbum.User        = albumUser;
                newAlbum.Comments    = new List <CommentEntity>();

                //add the album to the users albums
                albumUser.Albums.Add(newAlbum);
                //_context.Albums.Add(newAlbum);

                _context.SaveChanges();

                return(newAlbum);
            }
        }