コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,name,releasedate")] Album album)
        {
            if (ModelState.IsValid)
            {
                AlbumDB.Add(album);
                return(RedirectToAction("Index"));
            }

            return(View(album));
        }
コード例 #2
0
        public IActionResult PostAlbums([FromBody] Album album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            albumRepo.Add(album);

            return(CreatedAtAction("GetAlbums", new { id = album.AlbumId }, album));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "AlbumID,Title,Price,ArtistID,RowVersion")] Album album)
        {
            if (ModelState.IsValid)
            {
                repo.Add(album);
                repo.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistID = new SelectList(artistrepo.GetAll(), "ArtistID", "Name", album.ArtistID);
            return(View(album));
        }
コード例 #4
0
        public ActionResult Create(Album album)
        {
            var flag = TryValidateModel(album);

            if (ModelState.IsValid)
            {
                albumRepository.Add(album);
                var list = albumRepository.List();
                return(Redirect("Index"));
            }
            return(View(album));
        }
        public void Add_Album_AddsAlbumToDatabase()
        {
            var album = new Album
            {
                Id = Guid.NewGuid()
            };

            _albumRepository.Add(album);

            var albums = _context.Albums.ToList();

            Assert.IsTrue(albums.Contains(album));
        }
コード例 #6
0
ファイル: AlbumManager.cs プロジェクト: ThuAungMyat/myrepo
        public Album UpsertAlbum(Album Album)
        {
            Context         ctx           = new Context();
            AlbumRepository albumRepo     = new AlbumRepository(ctx);
            Album           UpdatedEntity = null;

            if (Album.ID > 0)
            {
                UpdatedEntity = albumRepo.update(Album);
            }
            else
            {
                UpdatedEntity = albumRepo.Add(Album);
            }
            return(UpdatedEntity);
        }
コード例 #7
0
ファイル: Gallery.cs プロジェクト: vbraziel/GalleryServer
        /// <summary>
        /// Verify the current gallery has a root album, creating one if necessary. The root album is returned.
        /// </summary>
        /// <returns>An instance of <see cref="AlbumDto" />.</returns>
        private AlbumDto ConfigureAlbumTable()
        {
            using (var repo = new AlbumRepository())
            {
                var rootAlbumDto = repo.Where(a => a.FKGalleryId == GalleryId && a.FKAlbumParentId == null).FirstOrDefault();

                if (rootAlbumDto == null)
                {
                    rootAlbumDto = new AlbumDto
                    {
                        FKGalleryId            = GalleryId,
                        FKAlbumParentId        = null,
                        DirectoryName          = String.Empty,
                        ThumbnailMediaObjectId = 0,
                        SortByMetaName         = MetadataItemName.DateAdded,
                        SortAscending          = true,
                        Seq              = 0,
                        DateAdded        = DateTime.UtcNow,
                        CreatedBy        = GlobalConstants.SystemUserName,
                        LastModifiedBy   = GlobalConstants.SystemUserName,
                        DateLastModified = DateTime.UtcNow,
                        OwnedBy          = String.Empty,
                        OwnerRoleName    = String.Empty,
                        IsPrivate        = false,
                        Metadata         = new Collection <MetadataDto>
                        {
                            new MetadataDto {
                                MetaName = MetadataItemName.Caption, Value = Resources.Root_Album_Default_Summary
                            },
                            new MetadataDto {
                                MetaName = MetadataItemName.Title, Value = Resources.Root_Album_Default_Title
                            }
                        }
                    };

                    repo.Add(rootAlbumDto);
                    repo.Save();
                }

                return(rootAlbumDto);
            }
        }
コード例 #8
0
ファイル: AddAlbum.cs プロジェクト: NhatTanVu/myalbum
        public async Task AddAlbum()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <MyAlbumDbContext>()
                          .UseInMemoryDatabase(databaseName: "AlbumRepository_AddAlbum_MyAlbumDatabase")
                          .Options;

            using (var context = new MyAlbumDbContext(options))
            {
                UnitOfWork      unitOfWork       = new UnitOfWork(context);
                AlbumRepository albumRepository  = new AlbumRepository(context);
                string          seed             = Guid.NewGuid().ToString();
                string          seedUserId       = Guid.NewGuid().ToString();
                int             seedAlbumId      = new Random().Next(1, 100);
                string          expectedUserName = string.Format("test_{0}@gmail.com", seed);
                Album           originalAlbum    = new Album()
                {
                    Id     = seedAlbumId,
                    Author = new User()
                    {
                        Id       = seedUserId,
                        UserName = expectedUserName
                    }
                };
                // Act
                albumRepository.Add(originalAlbum);
                await unitOfWork.CompleteAsync();

                // Assert
                Assert.Equal(1, await context.Albums.CountAsync(c => true));
                var savedAlbum = await context.Albums.FirstAsync(c => true);

                Assert.NotEqual(0, savedAlbum.Id);
                Assert.Equal(originalAlbum.Name, savedAlbum.Name);
                Assert.Equal(originalAlbum.Author.Id, savedAlbum.Author.Id);
                Assert.Equal(originalAlbum.Author.UserName, savedAlbum.Author.UserName);
            }
        }
コード例 #9
0
 // POST: api/Album
 public void Post([FromBody] Album album)
 {
     albumRepository.Add(album);
 }
コード例 #10
0
ファイル: LibraryManager.cs プロジェクト: manu3193/Odyssey
        /// <summary>
        /// Metodo encargado de interactuar con la capa de datos para realizar las inserciones en la base de datos local
        /// </summary>
        /// <param name="tracksToInsert">Lista de tracks por ingresar</param>
        private void InsertIntoDatabase(List<TrackInfo> tracksToInsert)
         {
            ArtistRepository artistRepo = new ArtistRepository();
            AlbumRepository albumRepo =new AlbumRepository();
            TrackRepository trackRepo =new TrackRepository();
            UserTrackRepository usertracksRepo = new UserTrackRepository();
            foreach (TrackInfo trackInfo in tracksToInsert)
            {
                Artist trackArtist = GetArtistByTitle(trackInfo.ArtistTitle);
                if (trackArtist == null)
                {
                    //Creates new artist and insert into database
                    trackArtist = new Artist() {ArtistID = Guid.NewGuid(), Title = trackInfo.ArtistTitle};
                    artistRepo.Add(trackArtist);
                    artistRepo.SaveChanges();

                }
                else
                {
                    //artistRepo.Attach(trackArtist);
                }
                
                Album trackAlbum = GetAlbumByTitleAndArtistTitle(trackInfo.AlbumTitle,trackArtist.Title);
                if (trackAlbum == null)
                {
                    //Set trackAlbum as new Album
                    trackAlbum= new Album() {AlbumID = Guid.NewGuid(),ArtistID = trackArtist.ArtistID,Title = trackInfo.AlbumTitle, ReleaseYear = trackInfo.Year};
                    albumRepo.Add(trackAlbum);
                    albumRepo.SaveChanges();
                }
                else
                {
                    //albumRepo.Attach(trackAlbum);
                }
                //Creates new track
                Track newTrack=new Track() {AlbumID = trackAlbum.AlbumID,Title = trackInfo.Title, Genre =trackInfo.Genre,Lyrics = trackInfo.Lyric,Path = trackInfo.SongPath,TrackID = trackInfo.TrackId};
                usertracksRepo.Add(new UserTrack() {UserID = SessionManager.Instance.UserId,TrackID = trackRepo.Add(newTrack).TrackID,IsSync = false});
                //artistRepo.SaveChanges();
                
                
                
                trackRepo.SaveChanges();
                
            }
            usertracksRepo.SaveChanges();
            artistRepo.Dispose();
            trackRepo.Dispose();
            usertracksRepo.Dispose();

        }
コード例 #11
0
ファイル: Gallery.cs プロジェクト: Jiyuu/galleryserverpro
        /// <summary>
        /// Verify the current gallery has a root album, creating one if necessary. The root album is returned.
        /// </summary>
        /// <returns>An instance of <see cref="AlbumDto" />.</returns>
        private AlbumDto ConfigureAlbumTable()
        {
            using (var repo = new AlbumRepository())
            {
                var rootAlbumDto = repo.Where(a => a.FKGalleryId == GalleryId && a.FKAlbumParentId == null).FirstOrDefault();

                if (rootAlbumDto == null)
                {
                    rootAlbumDto = new AlbumDto
                    {
                        FKGalleryId = GalleryId,
                        FKAlbumParentId = null,
                        DirectoryName = String.Empty,
                        ThumbnailMediaObjectId = 0,
                        SortByMetaName = MetadataItemName.DateAdded,
                        SortAscending = true,
                        Seq = 0,
                        DateAdded = DateTime.Now,
                        CreatedBy = GlobalConstants.SystemUserName,
                        LastModifiedBy = GlobalConstants.SystemUserName,
                        DateLastModified = DateTime.Now,
                        OwnedBy = String.Empty,
                        OwnerRoleName = String.Empty,
                        IsPrivate = false,
                        Metadata = new Collection<MetadataDto>
                        {
                            new MetadataDto {MetaName = MetadataItemName.Caption, Value = Resources.Root_Album_Default_Summary},
                            new MetadataDto {MetaName = MetadataItemName.Title, Value = Resources.Root_Album_Default_Title}
                        }
                    };

                    repo.Add(rootAlbumDto);
                    repo.Save();
                }

                return rootAlbumDto;
            }
        }