public PhotoEntity GetPhoto(int id) { using (MvcApplicationDB _context = new MvcApplicationDB()) { return(_context.Photos.FirstOrDefault(p => p.PhotoEntityId == id)); } }
public AlbumEntity Get(int albumId) { using (MvcApplicationDB _context = new MvcApplicationDB()) { return(_context.Albums.FirstOrDefault(a => a.AlbumEntityId == albumId)); } }
public List <AlbumEntity> GetAll() { using (MvcApplicationDB _context = new MvcApplicationDB()) { return(_context.Albums.ToList()); } }
public List <PhotoEntity> RetrieveAll() { using (MvcApplicationDB _context = new MvcApplicationDB()) { List <PhotoEntity> allPhotosFromDB = _context.Photos.ToList(); return(allPhotosFromDB); } }
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(); } }
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(); } }
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); } }