public void MapToDetailRep_DoesNotReturnNull_WithValidInput() { ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.NotNull(result); }
/// <summary> /// Initializes a DataAccessFacade, reading the connection string and instantiating a new /// ArtistMapper with the connection string /// </summary> public DataAccessFacade() { // TODO: Read from config file!! connectionString = @"Data Source=ARYA\SQLEXPRESS;Initial Catalog=MusicCollection;Integrated Security=True"; artistMapper = new ArtistMapper(connectionString); }
public SongsDiscoverModel DiscoverRelatedSongs(string name, string userToken, int maxCount) { var userAuthorization = AuthorizationCache.Instance.GetByToken(userToken); var songRecommendationsResult = _songRepository.GetSimilarByTitle(name, userAuthorization.Id, maxCount); return(new SongsDiscoverModel { MatchedSong = string.IsNullOrEmpty(songRecommendationsResult.MatchedSongId) ? null : new SongItemModel { Id = songRecommendationsResult.MatchedSongId, Name = songRecommendationsResult.MatchedSongTitle, Artist = ArtistMapper.ToArtistModel(songRecommendationsResult.MatchedSongArtist) }, RecommendedSongs = songRecommendationsResult.RecommendedSongs.Select( sr => new SongItemModel { Id = sr.Song.Id, Name = sr.Song.Title, Artist = ArtistMapper.ToArtistModel(sr.Artist) }) }); }
public void MapToDetailRep_HasExpectedBioText_WithValidInput() { ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.Equal(_validDbArtist.BioText, result.BioText); }
public void Add(ArtistModel artistModel) { if (string.IsNullOrEmpty(artistModel.Name)) { throw new ValidationException(Messages.ArtistNameRequired); } if (string.IsNullOrEmpty(artistModel.Description)) { throw new ValidationException(Messages.ArtistDescriptionRequired); } var artistByName = _artistRepository.GetByName(artistModel.Name); if (artistByName != null) { throw new ConflictException(Messages.ArtistNameAlreadyExists); } var artist = ArtistMapper.ToArtist(artistModel); artist.Id = SecurityUtils.GenerateEntityId(); _artistRepository.Add(artist); }
public void Update(string id, ArtistModel artistModel) { if (string.IsNullOrEmpty(artistModel.Name)) { throw new ValidationException(Messages.ArtistNameRequired); } if (string.IsNullOrEmpty(artistModel.Description)) { throw new ValidationException(Messages.ArtistDescriptionRequired); } var artist = _artistRepository.GetById(id); if (artist == null) { throw new NotFoundException(Messages.InvalidArtistId); } var artistByName = _artistRepository.GetByName(artist.Name); if (artistByName != null && artistByName.Id != id) { throw new ConflictException(Messages.ArtistNameAlreadyExists); } ArtistMapper.RefreshArtist(artist, artistModel); _artistRepository.Update(artist); }
/// <summary> /// Retrieves the form/data for the selected artist based off of Artist ID /// </summary> /// <returns></returns> public ActionResult UpdateArtist(int artistID) { ActionResult oResponse = null; // Ensures user is authenticated and is an Admin/SuperUser for Updating Priveleges if (Session["Email"] != null && (int)Session["Role"] >= 4) { var artistVM = new ArtistViewModel(); // Retrieves an artist by its ID IArtistDO artistDO = artistDA.ViewArtistByID(artistID); // Maps artistDO from Data Object to Presentation Objects for Updating artistVM.Artist = ArtistMapper.MapArtistDOtoPO(artistDO); //PopulateDropDownLists(artistVM); oResponse = View(artistVM); } else { // User doesn't have priveleges to this page redirect to home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public void ArtistEdit(Models.Artist art) { var dbArtist = ArtistMapper.ToDatabase(art); _dbContext.Artist.Update(dbArtist); _dbContext.SaveChanges(); }
public void Save(Models.Artist artist) { var dbArtist = ArtistMapper.ToDatabase(artist); _dbContext.Artist.Add(dbArtist); _dbContext.SaveChanges(); }
public async Task DeleteAsync(int id) { var result = await _dbContext.Artist.SingleAsync(x => x.Id == id); var art = ArtistMapper.FromDatabase(result); _dbContext.Artist.Remove(result); _dbContext.SaveChanges(); }
public void MapToDetailRep_HasExpectedBioImageUrl_WithValidInput() { DbArtist sourceObj = _validDbArtist; sourceObj.BioImageId = 1515; ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.Equal("/api/image/1515", result.BioImageUrl); }
public void MapToDetailRep_HasNullBioImageId_WithNullInput() { DbArtist sourceObj = _validDbArtist; sourceObj.BioImageId = null; ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.Null(result.BioImageId); }
public ArtistModel GetById(string id) { var artist = _artistRepository.GetById(id); if (artist == null) { throw new NotFoundException(Messages.InvalidArtistId); } return(ArtistMapper.ToArtistModel(artist)); }
public void MapToDetailRep_HasPublishedStatus_WithValidInput(DbPublishedStatus publishedStatusTestCase) { DbArtist sourceObj = _validDbArtist; sourceObj.PublishStatus = publishedStatusTestCase; PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); ArtistMapper mapper = new ArtistMapper(); PublishStatus expetedStatus = statusMapper.Map(publishedStatusTestCase); ArtistDetail result = mapper.MapToDetailRep(sourceObj); ICollection <string> dbGenres = _validDbArtist.ArtistGenres.Select(x => x.Genre.Name).ToList(); Assert.Equal(expetedStatus, result.PublishedStatus); }
public IEnumerable <SongItemModel> GetSongRecommendations(string songId, string userToken, int maxCount) { var userAuthorization = AuthorizationCache.Instance.GetByToken(userToken); var songRecommendations = _songRepository.GetSimilarById(songId, userAuthorization.Id, maxCount); return (songRecommendations.RecommendedSongs.Select( sr => new SongItemModel { Id = sr.Song.Id, Name = sr.Song.Title, Artist = ArtistMapper.ToArtistModel(sr.Artist) })); }
/// <summary> /// Will modify the changes made to a given artist based off of their Artist ID /// </summary> /// <returns></returns> public ActionResult UpdateArtist(ArtistViewModel iViewModel) { ActionResult oResponse = null; // Ensures the user is Authenticated and is an Admin/SuperUser for Updating an Artist if (Session["Email"] != null && (int)Session["Role"] >= 4) { if (ModelState.IsValid) { try { // Maps Artist from Presenation Object to Data Object IArtistDO lArtistForm = ArtistMapper.MapArtistPOtoDO(iViewModel.Artist); // Passes lArtistForm properties to map From Presentation Objects to Data Objects for Update submission artistDA.UpdateArtistInformation(lArtistForm); oResponse = RedirectToAction("ViewAllArtists", "Artist"); } catch (Exception ex) { using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "Sorry, something went wrong. Please try again."; // Mapp all data to appropriate types to populate drop down //PopulateDropDownLists(iViewModel); oResponse = View(iViewModel); } } else { oResponse = View(iViewModel); } } else { // User doesn't have privileges to Update an Artist, redirect to home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
/// <summary> /// Creates and stores the artist submitted to the site /// </summary> /// <returns></returns> public ActionResult CreateArtist(ArtistViewModel iViewModel) { ActionResult oResponse = null; // Ensures the user is authenticated and is an Admin/SuperUser for creating an artist if (Session["Email"] != null && (int)Session["Role"] >= 4) { if (ModelState.IsValid) { try { // Maps Artist properties from Presentation Objects to Data Objects for creation IArtistDO lArtistForm = ArtistMapper.MapArtistPOtoDO(iViewModel.Artist); // Passes lArtistForm to the AddArtist method artistDA.AddArtist(lArtistForm); oResponse = RedirectToAction("ViewAllArtists", "Artist"); } catch (Exception ex) { using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "We apologize, but are unable to handle request at this time.."; // Map data to populate form drop down //PopulateDropDownLists(iViewModel); oResponse = View(iViewModel); } } else { oResponse = View(iViewModel); } } else { // User doesn't have access redirect to home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
/// <summary> /// Retrieves the details for the selected Artist based off of their Artist ID /// </summary> /// <returns></returns> public ActionResult Details(int id) { var selectedArtist = new ArtistViewModel(); ActionResult oResponse = null; if (ModelState.IsValid) { try { // Stores Artist Details by ID to iArtist IArtistDO iArtist = (IArtistDO)artistDA.ArtistDetails(id); // Maps iArtist from Data Objects to Presentation Objects selectedArtist.Artist = ArtistMapper.MapArtistDOtoPO(iArtist); oResponse = View(selectedArtist); } catch (Exception ex) { // Catch the exception; log it and store in View Model using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } selectedArtist.ErrorMessage = "We apologize, but we are unable to handle your request at this time."; oResponse = View(selectedArtist); } } else { oResponse = View(selectedArtist); } return(oResponse); }
/// <summary> /// Retrieves all of the Artists that are stored within the Site's database /// </summary> /// <returns></returns> public ActionResult ViewAllArtists() { var ViewAllArtistVM = new ArtistViewModel(); ActionResult oResponse = null; // Ensures both an Authenticated and Non-Registered use can view all of the artists if (Session["Email"] != null || Session["Email"] == null) { try { // Calls ViewAllArtists from Data Access layer and stores into allArtists List <IArtistDO> allArtists = artistDA.ViewAllArtists(); // Maps from Data Objects to Presentation Objects. Passes allArtists properties for mapping ViewAllArtistVM.ListOfArtistPO = ArtistMapper.MapListOfDOsToListOfPOs(allArtists); oResponse = View(ViewAllArtistVM); } catch (Exception ex) { // Catch exception and show error message to user using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } ViewAllArtistVM.ErrorMessage = "We apologize, but we were unable to handle your request"; oResponse = View(ViewAllArtistVM); } } else { oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public Artist BrowseArtist(string link, bool mapTracks) { Login(); logger.Debug("Artist Browse started for link {0}", link); const string prefix = "spotify:artist:"; var browseTypeEnum = mapTracks ? sp_artistbrowse_type.FULL : sp_artistbrowse_type.NO_TRACKS; using (var artist = session.ParseLink(prefix + link).As <IArtist>()) using (var browse = artist.Browse(browseTypeEnum)) { browse.WaitForCompletion(); if (!browse.IsComplete) { logger.Error("Artist Browse timed out"); } var albums = browse.Albums .Where(a => a.IsAvailable) .Select(a => albumMapper.Map(a, this)) .ToArray(); var artistResult = new ArtistMapper().Map(artist, this); artistResult.Profile = new ArtistProfile { Biography = browse.Biography, SimilarArtists = browse.SimilarArtists .Select(a => new ArtistMapper().Map(a, this)) .ToArray() }; artistResult.Albums = albums; logger.Debug("Artist Browse completed for link {0}", link); return(artistResult); } }
static MapperRegistry() { Albums = new AlbumMapper(); Artists = new ArtistMapper(); }
public async Task <Models.Artist> GetAsync(int id) { var result = await _dbContext.Artist.SingleOrDefaultAsync(x => x.Id == id); return(ArtistMapper.FromDatabase(result)); }
public IEnumerable <Models.Artist> GetAll() { return(_dbContext.Artist.Select(x => ArtistMapper.FromDatabase(x))); }
public ArtistRepository(MusicStoreDbContext context, ArtistMapper mapper) { _context = context; _mapper = mapper; }
public Artist BrowseArtist(string link, bool mapTracks) { Login(); logger.Debug("Artist Browse started for link {0}", link); const string prefix = "spotify:artist:"; var browseTypeEnum = mapTracks ? sp_artistbrowse_type.FULL : sp_artistbrowse_type.NO_TRACKS; using (var artist = session.ParseLink(prefix + link).As<IArtist>()) using (var browse = artist.Browse(browseTypeEnum)) { browse.WaitForCompletion(); if (!browse.IsComplete) logger.Error("Artist Browse timed out"); var artistResult = new ArtistMapper().Map(artist); artistResult.LoadStatus = mapTracks? Artist.LoadedState.FullWithTracks: Artist.LoadedState.FullNoTracks; artistResult.Profile = new ArtistProfile { Biography = browse.Biography, SimilarArtists = browse.SimilarArtists .Select(a => new ArtistMapper().Map(a)) .ToArray() }; artistResult.Albums = browse.Albums .Where(a => a.IsAvailable) .Select(a => new AlbumMapper().Map(a)) .ToArray(); if (mapTracks) { artistResult.Tracks = browse.Tracks .Where(a => a.IsAvailable) .Select(a => new TrackMapper().Map(a, true)) .ToArray(); } logger.Info("Artist Browse completed for link {0}", link); return artistResult; } }
public void MapToDetailRep_ThrowsNullReferenceException_WithNullInput() { ArtistMapper mapper = new ArtistMapper(); Assert.Throws <NullReferenceException>(() => mapper.MapToDetailRep(null)); }
public ArtistController(IArtistRepository repo, ILogger <ArtistController> logger) { _artistMapper = new ArtistMapper(); _repo = repo; _logger = logger; }