public void WhenPassedComplexScenario_MapsCorrectly() { // Arrange var testBuilder = new AlbumMapperListBuilder() .WithAlbum(1, "First") .WithAlbum(2, "Second") .WithAlbum(3, "Third") .WithAlbum(4, "Fourth") .WithPhoto(1, 1) .WithPhoto(1, 2) .WithPhoto(1, 3) .WithPhoto(2, 4) .WithPhoto(2, 5) .WithPhoto(4, 6); var sut = new AlbumMapper(); // Act sut.MapItems(testBuilder.Albums, testBuilder.Photos); // Assert Assert.AreEqual(testBuilder.Albums[0].Photos.Count, 3); Assert.AreEqual(testBuilder.Albums[1].Photos.Count, 2); Assert.AreEqual(testBuilder.Albums[2].Photos.Count, 0); Assert.AreEqual(testBuilder.Albums[3].Photos.Count, 1); }
public ActionResult AddAlbum(AlbumPO form) { ActionResult response = null; if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3) { if (ModelState.IsValid) { try { _dataAccess.AddAlbum(AlbumMapper.AlbumPOtoDO(form)); response = RedirectToAction("ViewAlbums", "Albums"); } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } } else { response = View(form); } } else { TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting."; response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult Delete(long albumId) { List <AlbumPO> mappedAlbums = new List <AlbumPO>(); ActionResult oResponse = RedirectToAction("Index", "Album", new { mappedAlbums }); if (ModelState.IsValid) { try { dataAccess.DeleteAlbum(albumId); List <AlbumDO> albums = dataAccess.ReadAlbum(); mappedAlbums = AlbumMapper.MapDoToPO(albums); TempData["Message"] = "Album successfully deleted."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Delete", ex.StackTrace); //Returns albumId to view. oResponse = View(albumId); } } else { //Returns albumId to view. oResponse = View(albumId); } return(oResponse); }
public ActionResult UpdateAlbum(int albumID) { ActionResult response = null; if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3) { try { AlbumPO useralbums = new AlbumPO(); useralbums = AlbumMapper.AlbumDOtoPO(_dataAccess.ReadAlbumByID(albumID)); useralbums.UserSelectList = FillUsersListDropDown(); response = View(useralbums); } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } } else { TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting."; response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult Update(AlbumPO album) { //Defaulting redirect to index of album controller ActionResult OResponse = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Updates album in datatable using valid user input. dataAccess.UpdateAlbum(AlbumMapper.MapPoToDO(album)); TempData["Message"] = "Album successfully updated."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Update", ex.StackTrace); OResponse = View(album); } } else { //Returns album to view. OResponse = View(album); } return(OResponse); }
public ActionResult ViewAlbums() { ActionResult response = null; List <AlbumDO> albumList = new List <AlbumDO>(); List <List <AlbumPO> > listalbums = new List <List <AlbumPO> >(); if (Session["RoleID"] != null && (byte)Session["RoleID"] >= 1) { try { albumList = _dataAccess.ReadAllAlbums(); for (int i = 0; i < (float)albumList.Count / 3; i++) { listalbums.Add(AlbumMapper.ListAlbumDOtoPO(albumList.Skip(i * 3).Take(3).ToList())); } } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } response = View(listalbums); } else { TempData["Statement"] = "Please register to view this page."; response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult ViewPhotosInAlbum(int albumID) { ActionResult response = null; List <AlbumDO> photoAlbumList = new List <AlbumDO>(); if (Session["RoleId"] != null && (byte)Session["RoleID"] >= 1) { try { photoAlbumList = _dataAccess.ViewPhotosInAlbum(albumID); } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } response = View(AlbumMapper.ListAlbumDOtoPO(photoAlbumList)); } else { TempData["Statement"] = "Please register to view this page."; response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult AlbumDetails(string id) { var album = albumRepository.GetAlbumByID(id); DetailAlbumViewModel model = AlbumMapper.MapDetailAlbumViewModel(album); return(PartialView("_AlbumDetails", model)); }
public ActionResult Index() { List <Album> albumsDB = albumRepository.GettAllAlbumsByUserID(userID); List <ListAlbumViewModel> albums = new List <ListAlbumViewModel>(); albumsDB.ForEach(x => albums.Add(AlbumMapper.MapListAlbumViewModel(x))); return(View(albums)); }
public void WhenPassedNulls_ThrowsArgumentException() { // Arrange var sut = new AlbumMapper(); // Act + Assert Assert.Throws <ArgumentException>(() => sut.MapItems(null, null)); }
public ActionResult Create(EditAlbumViewModel model) { if (ModelState.IsValid) { Album album = AlbumMapper.MapEditAlbumViewModel(model, userID); albumRepository.AddAlbum(album); } return(Content(model.Name)); }
public ActionResult Edit(EditAlbumViewModel model, FormCollection collection) { if (ModelState.IsValid) { Album album = AlbumMapper.MapEditAlbumViewModel(model, userID); albumRepository.UpdateAlbum(album); } return(Content(model.Name)); }
public async Task <AlbumApplication> GetAsync(int id) { var entity = await _albumRepository.GetAsync(id); if (entity == null) { return(null); } return(AlbumMapper.Map(entity)); }
public ActionResult Delete(EditAlbumViewModel model, FormCollection collection) { Album album = AlbumMapper.MapEditAlbumViewModel(model, userID); albumRepository.DeleteAlbum(album); List <Album> albumsDB = albumRepository.GettAllAlbumsByUserID(userID); List <ListAlbumViewModel> albums = new List <ListAlbumViewModel>(); albumsDB.ForEach(x => albums.Add(AlbumMapper.MapListAlbumViewModel(x))); return(PartialView("_Items", albums)); }
public ActionResult Delete(EditAlbumViewModel model) { Album album = albumRepository.GetAlbumByID(model.Id); model = AlbumMapper.MapEditAlbumViewModel(album); if (album.UserID == userID) { return(View(model)); } return(View()); }
public List <SelectListItem> FillAlbumsListDropDown() { List <AlbumPO> albums = AlbumMapper.ListAlbumDOtoPO(_dataAccess.ReadAllAlbums()); List <SelectListItem> AlbumSelectList = new List <SelectListItem>(); foreach (AlbumPO album in albums) { AlbumSelectList.Add(new SelectListItem { Text = album.AlbumName, Value = album.AlbumID.ToString() }); } return(AlbumSelectList); }
public void WhenPassedOneToOneMappings_MapsCorrectly() { // Arrange var testBuilder = new AlbumMapperListBuilder() .WithAlbum(1, "First") .WithPhoto(1, 1); var sut = new AlbumMapper(); // Act sut.MapItems(testBuilder.Albums, testBuilder.Photos); // Assert Assert.AreEqual(testBuilder.Albums[0].Photos.Count, 1); }
public void WhenPassedNoAlbums_MapsCorrectly() { // Arrange var testBuilder = new AlbumMapperListBuilder() .WithPhoto(1, 1) .WithPhoto(2, 2); var sut = new AlbumMapper(); // Act sut.MapItems(testBuilder.Albums, testBuilder.Photos); // Assert Assert.AreEqual(testBuilder.Albums.Count, 0); }
public void WhenPassedNoPhotos_MapsCorrectly() { // Arrange var testBuilder = new AlbumMapperListBuilder() .WithAlbum(1, "First") .WithAlbum(2, "Second"); var sut = new AlbumMapper(); // Act sut.MapItems(testBuilder.Albums, testBuilder.Photos); // Assert Assert.AreEqual(testBuilder.Albums[0].Photos.Count, 0); Assert.AreEqual(testBuilder.Albums[1].Photos.Count, 0); }
/// <summary> /// Constructor used to restore from database /// </summary> /// <param name="id"></param> public Album(int id) { AlbumMapper albumDataContent = AlbumQuery.GetAlbum(id); this.id = id; this.title = albumDataContent.Name; this.lastUsed = albumDataContent.LastUsed; this.slideShows = new ObservableCollection <SlideShow>(); //Get slideshows and restrore those List <int> slideShowIds = SlideShowQuery.GetSlideShows(id); foreach (int slideShowId in slideShowIds) { SlideShow slideShow = new SlideShow(slideShowId); this.slideShows.Add(slideShow); } }
public ActionResult Media(string Search, string Filter) { if (Filter == "photo") { List <Photo> photosFromDB = photoRepository.GetSearchPhotosFromDb(Search); List <IndexPhotoViewModel> photos = new List <IndexPhotoViewModel>(); photosFromDB.ForEach(x => photos.Add(PhotoMapper.MapIndexPhotoViewModel(x))); return(PartialView("_thumbnails", photos)); } else { List <Album> albumsFromDB = albumRepository.GetSearchAlbumsFromDB(Search).Where(x => x.Photos.Count() > 0).ToList(); List <AlbumViewModel> albums = new List <AlbumViewModel>(); albumsFromDB.ForEach(x => albums.Add(AlbumMapper.MapAlbumViewModel(x, photoRepository))); return(PartialView("_thumbnailsAlbum", albums)); } }
public ActionResult Update(long albumId) { AlbumPO mappedAlbum = new AlbumPO(); ViewBag.DropDown = new List <SelectListItem>(); //Defaults redirect to view. ActionResult oResponse = View(); if (ModelState.IsValid) { try { //List username and Id in the viewbag as to use for a dropdown list in view. List <UserDO> dataObjects = userData.ReadUsers(); mappedAlbum = AlbumMapper.MapDoToPO(dataAccess.ViewAlbumById(albumId)); foreach (UserDO user in dataObjects) { //Adds username and user Id to a dropdown list of users in viewbag. ViewBag.DropDown.Add(new SelectListItem() { Text = user.Username, Value = user.UserId.ToString() }); } //Returns mappedalbum to view. oResponse = View(mappedAlbum); } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Update", ex.StackTrace); //Sets redirect to index of album controller. oResponse = RedirectToAction("Index", "Album"); } } else { //Returns albumId to view. oResponse = View(albumId); } return(oResponse); }
public ActionResult Index() { List <AlbumPO> mappedItems = new List <AlbumPO>(); try { //Business Logic BusinessLogic countPhotos = new BusinessLogic(); List <PhotosBO> fromBL = countPhotos.CountPhotosInAlbum(allPhotos.ReadPhotosForCount()); ViewBag.PhotoCount = new List <PhotosBO>(); foreach (PhotosBO item in fromBL) { ViewBag.PhotoCount.Add(new PhotosBO() { AlbumId = item.AlbumId, PhotoCount = item.PhotoCount }); } if ((long)Session["RoleId"] <= 2) { //User is an Admin. Viewing all albums List <AlbumDO> dataObjects = dataAccess.ReadAlbum(); mappedItems = AlbumMapper.MapDoToPO(dataObjects); } else { //Display albums that belong to user and provide actions to authenticated users. List <AlbumDO> dataObjects = dataAccess.ViewAlbumByUserId((long)Session["UserId"]); mappedItems = AlbumMapper.MapDoToPO(dataObjects); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Index", ex.StackTrace); } return(View(mappedItems)); }
static MapperRegistry() { Albums = new AlbumMapper(); Artists = new ArtistMapper(); }
public ActionResult Create(AlbumPO album) { //Defaults redirect to index of album controller. ActionResult oResponse = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Adds album to datatable using valid album. dataAccess.CreateAlbum(AlbumMapper.MapPoToDO(album)); TempData["Message"] = "Album successfully created."; } catch (Exception e) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", e.Message, "AlbumController", "Create", e.StackTrace); try { List <UserDO> dataObjects = userData.ReadUsers(); ViewBag.DropDown = new List <SelectListItem>(); foreach (UserDO user in dataObjects) { //Adds username and user Id to a dropdown list of users in viewbag. ViewBag.DropDown.Add(new SelectListItem() { Text = user.Username, Value = user.UserId.ToString() }); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Create", ex.StackTrace); } oResponse = View(album); } } else { //Modelstate was invalid. try { List <UserDO> dataObjects = userData.ReadUsers(); ViewBag.DropDown = new List <SelectListItem>(); foreach (UserDO user in dataObjects) { //Adds username and user Id to a dropdown list of users in viewbag. ViewBag.DropDown.Add(new SelectListItem() { Text = user.Username, Value = user.UserId.ToString() }); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Create", ex.StackTrace); } oResponse = View(album); } return(oResponse); }
public async Task <AlbumApplication> UpdateAsync(AlbumApplication entity) { var result = await _albumRepository.UpdateAsync(AlbumMapper.Map(entity)); return(AlbumMapper.Map(result)); }
public Album BrowseAlbum(string link) { Login(); logger.Debug("Album Browse started for link {0}", link); const string prefix = "spotify:album:"; using (var album = session.ParseLink(prefix + link).As<IAlbum>()) using (var browse = album.Browse()) { browse.WaitForCompletion(); if (!browse.IsComplete) { logger.Error("Album Browse timed out"); return null; } var albumResult = new AlbumMapper().Map(album, true); var trackMapper = new TrackMapper(); var tracks = browse.Tracks .Select(t => trackMapper.Map(t, false, true)) .ToArray(); albumResult.Tracks = tracks; logger.Info("Album Browse completed for link {0}", link); return albumResult; } }
public AlbumRepository(MusicStoreDbContext context, AlbumMapper mapper) { _context = context; _mapper = mapper; }