Exemplo n.º 1
0
 public ActionResult Create(Artist artist)
 {
     if (!ModelState.IsValid)
     {
         return(View(artist));
     }
     repository.Add(artist);
     repository.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public async Task should_add_new_item(Artist artist)
        {
            artist.ArtistId = Guid.NewGuid();
            var sut = new ArtistRepository(_factory.ContextInstance);

            sut.Add(artist);
            await sut.UnitOfWork.SaveEntitiesAsync();

            _factory.ContextInstance.Artists.FirstOrDefault(x => x.ArtistId == artist.ArtistId)
            .ShouldNotBeNull();
        }
        public IActionResult PostArtist([FromBody] Artist artist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            artistRepo.Add(artist);

            return(CreatedAtAction("GetAlbums", new { id = artist.ArtistId }, artist));
        }
        public void Add_Artist_AddsArtistToDatabase()
        {
            var artist = new Artist {
                Id = Guid.NewGuid()
            };

            _artistRepository.Add(artist);

            var artists = _context.Artists.ToList();

            Assert.IsTrue(artists.Contains(artist));
        }
        public ActionResult Add(Artist artist)
        {
            ValidateArtist(artist);

            if (ModelState.IsValid)
            {
                ArtistRepository.Add(artist);

                TempData["Message"] = "Your artist was successfully added!";

                return(RedirectToAction("Detail", new { id = artist.Id }));
            }

            return(View(artist));
        }
Exemplo n.º 6
0
        public async Task should_add_new_item(object jsonPayload)
        {
            var artist = JsonConvert.DeserializeObject <Artist>(jsonPayload.ToString());

            artist.ArtistId = Guid.NewGuid();

            var sut = new ArtistRepository(_testDataContextFactory.ContextInstance);

            sut.Add(artist);

            await sut.UnitOfWork.SaveEntitiesAsync();

            _testDataContextFactory.ContextInstance.Artists
            .FirstOrDefault(x => x.ArtistId == artist.ArtistId)
            .ShouldNotBeNull();
        }
Exemplo n.º 7
0
        public Artist UpsertArtist(Artist Artist)
        {
            Context          ctx           = new Context();
            ArtistRepository artistRepo    = new ArtistRepository(ctx);
            Artist           UpdatedEntity = null;

            if (Artist.ID > 0)
            {
                UpdatedEntity = artistRepo.update(Artist);
            }
            else
            {
                UpdatedEntity = artistRepo.Add(Artist);
            }
            return(UpdatedEntity);
        }
Exemplo n.º 8
0
        private static void AddOrUpdateArtistIfExists(ArtistRepository artistRepo)
        {
            var artist = Artist.Generate("First artist", Address.Generate("1", "BB Street"), "The first artist");
            artist.Add(Album.Generate("First Title"));
            artist.Add(Album.Generate("Second Title"));

            var existingArtist = artistRepo.GetByName(artist.Name).FirstOrDefault();

            if (existingArtist == null)
            {
                artistRepo.Add(artist);
            }
            else
            {
                existingArtist.SetNickName(string.Format("Artist updated {0}", DateTime.Now));
                artistRepo.Update(existingArtist);
            }

            artistRepo.SaveChanges();
        }
Exemplo n.º 9
0
        private static void AddOrUpdateArtistIfExists(ArtistRepository artistRepo)
        {
            var artist = Artist.Generate("First artist", Address.Generate("1", "BB Street"), "The first artist");

            artist.Add(Album.Generate("First Title"));
            artist.Add(Album.Generate("Second Title"));

            var existingArtist = artistRepo.GetByName(artist.Name).FirstOrDefault();

            if (existingArtist == null)
            {
                artistRepo.Add(artist);
            }
            else
            {
                existingArtist.SetNickName(string.Format("Artist updated {0}", DateTime.Now));
                artistRepo.Update(existingArtist);
            }

            artistRepo.SaveChanges();
        }
Exemplo n.º 10
0
        public bool InsertArtist([FromBody] Artist entity)
        {
            ArtistRepository repo = new ArtistRepository();

            return(repo.Add(entity));
        }
Exemplo n.º 11
0
        /// <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();

        }
Exemplo n.º 12
0
        public void Add_SingleValidArtist_ShouldBeInserted()
        {
            _artistRepository.Add(_testArtistOne);

            var retrievedArtist = _mongoDatabaseUtilities.FindRecordById(_testArtistOne.Id);

            ArtistAssertor.New()
            .Expected(_testArtistOne)
            .Actual(retrievedArtist[0])
            .DoAssert();
        }