public void Add(UserEntity userToBeRegistered) { using (MvcApplicationDB _context = new MvcApplicationDB()) { _context.Users.Add(userToBeRegistered); _context.SaveChanges(); } }
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); } }