Exemplo n.º 1
0
        public IActionResult Details()
        {
            string albumId = this.Request.QueryData["albumId"].ToString();
            Album  album   = this.albumsService.GetAlbumById(albumId);

            if (album == null)
            {
                this.ViewModel.Data["Error"] = "No such album";
                return(this.View());
            }
            else
            {
                AlbumDetailsViewModel albumDetailsViewModel = new AlbumDetailsViewModel {
                    Id          = album.Id,
                    Name        = album.Name,
                    Price       = Math.Round(album.Price, 2),
                    ImageSource = album.Cover,
                    Tracks      = album.Tracks.Select(at => new TrackViewModel {
                        Name    = at.Track.Name,
                        AlbumId = album.Id,
                        Id      = at.TrackId,
                        Price   = Math.Round(at.Track.Price, 2)
                    })
                };
                this.ViewModel.Data["AlbumDetailsViewModel"] = albumDetailsViewModel;
                return(this.View());
            }
        }
Exemplo n.º 2
0
        public IHttpResponse GetAlbum(AlbumDetailsViewModel model)
        {
            StringBuilder sb = new StringBuilder();

            Album album =
                this.Context
                .Albums
                .First(a => a.Id == model.Id);

            decimal albumPrice =
                this.Context
                .AlbumTracks
                .Where(at => at.AlbumId == model.Id)
                .Sum(track => track.Track.Price)
                * 0.87m;

            var tracks =
                this.Context
                .AlbumTracks
                .Include(x => x.Track)
                .Include(x => x.Album)
                .Where(at => at.AlbumId == model.Id)
                .ToArray();

            var viewModel = album.To <AlbumDetailsViewModel>();

            viewModel.CreateTrack = $"'/Tracks/Create?albumId={album.Id}'";

            return(this.View("album", HttpResponseStatusCode.Ok, viewModel));
        }
Exemplo n.º 3
0
        public void ConvertsImages()
        {
            var source = CreateDomainAlbum();

            source.Images = new List <Image>
            {
                new Image {
                    Height = 640, Width = 640, Url = "https://i.scdn.co/image/ab67616d0000b273d50eac8c4023cf2b40413656"
                },
                new Image {
                    Height = 300, Width = 300, Url = "https://i.scdn.co/image/ab67616d00001e02d50eac8c4023cf2b40413656"
                },
                new Image {
                    Height = 64, Width = 64, Url = "https://i.scdn.co/image/ab67616d00004851d50eac8c4023cf2b40413656"
                }
            };
            var result   = new AlbumDetailsViewModel(source);
            var expected = new List <ImageViewModel>
            {
                new ImageViewModel {
                    Height = 640, Width = 640, Path = "https://i.scdn.co/image/ab67616d0000b273d50eac8c4023cf2b40413656"
                },
                new ImageViewModel {
                    Height = 64, Width = 64, Path = "https://i.scdn.co/image/ab67616d00004851d50eac8c4023cf2b40413656"
                },
                new ImageViewModel {
                    Height = 300, Width = 300, Path = "https://i.scdn.co/image/ab67616d00001e02d50eac8c4023cf2b40413656"
                }
            };

            result.Images.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 4
0
        public ActionResult AlbumDetails(int id)
        {
            AlbumDetailsViewModel model = null;

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                var entity = cx.Albums
                             .Include(a => a.Photos)
                             .Include(a => a.Comments)
                             .FirstOrDefault(a => a.Id == id);

                model = new AlbumDetailsViewModel()
                {
                    Id          = entity.Id,
                    Name        = entity.Name,
                    Comments    = entity.Comments,
                    DateCreated = entity.DateCreated,
                    Description = entity.Description,
                    Photos      = entity.Photos,
                    User        = entity.User,
                };
            }

            return(View(model));
        }
        public ActionResult AlbumDetails(int id)
        {
            AlbumDetailsViewModel model = EFMapper.EntityToModel(albumRepo.GetAlbum(id));

            #region notused
            //AlbumDetailsViewModel model = null;

            //using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            //{
            //    var entity = cx.Albums
            //        .Include(a => a.Photos)
            //        .Include(a => a.Comments)
            //        .FirstOrDefault(a => a.Id == id);

            //    model = new AlbumDetailsViewModel()
            //    {
            //        Id = entity.Id,
            //        Name = entity.Name,
            //        Comments = entity.Comments,
            //        DateCreated = entity.DateCreated,
            //        Description = entity.Description,
            //        Photos = entity.Photos,
            //        User = entity.User,
            //    };
            //}
            #endregion

            return(View(model));
        }
Exemplo n.º 6
0
            public static void Initialize(TestContext _)
            {
                var source = CreateDomainAlbum();

                source.Tracks = new List <Track>();
                result        = new AlbumDetailsViewModel(source);
            }
Exemplo n.º 7
0
        public IActionResult Details(AlbumDetailsViewModel viewModel)
        {
            this.ShowAppropriateButtonsBasedOnLoggedIn();

            var albumId = viewModel.AlbumId;

            var sb    = new StringBuilder();
            var album = this.albumService.GetAlbum(viewModel);

            if (album == null || !this.IsSignedIn())
            {
                return(this.RedirectToAction("/"));
            }

            var tracksAsString = this.albumService.GetTracksAsString(albumId);

            var result = !string.IsNullOrWhiteSpace(tracksAsString) ? tracksAsString : "There are currently no tracks.";

            sb.Append(result);

            this.Model.Data.Add("Cover", album.Cover.DecodeUrl());
            this.Model.Data.Add("Name", album.Name);
            this.Model.Data.Add("Price", "$" + album.Price.ToString("f2"));
            this.Model.Data.Add("AlbumId", albumId);
            this.Model.Data.Add("Tracks", sb.ToString());
            return(this.View());
        }
Exemplo n.º 8
0
        public IActionResult Comment(AlbumDetailsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var author = userManager.GetUserAsync(User).Result;

                var comment = new Comment()
                {
                    Album = this.db.Album
                            .Where(al => al.Id == model.Id)
                            .FirstOrDefault(),
                    Content   = model.PostComment.Content,
                    User      = author,
                    CreatedOn = DateTime.UtcNow.AddHours(3)
                };

                db.Comments.Add(comment);

                author.CommentsCount++;

                db.SaveChanges();

                return(RedirectToAction("Details", "Albums", new { @albumId = model.Id, @userId = comment.Album.UserId }));
            }

            return(RedirectToAction("Details", "Albums", new { @albumId = model.Id, @userId = model.Creator.Id }));
        }
        public void SetTotalPriceWithAlbum_emptyAlbum_120()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Set TrackPrices
            var priceTrack = new PriceViewModel();

            priceTrack.Currency = userCurrency;
            priceTrack.Amount   = 120;
            //// Create track with price = 120
            var track1 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack",
                Price = priceTrack
            };
            //// Create empty album
            var album1 = new AlbumDetailsViewModel();
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>(),
                Albums = new List <AlbumDetailsViewModel>()
            };

            myCartView.Tracks.Add(track1);
            myCartView.Albums.Add(album1);
            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 120);
        }
        public IActionResult Details(AlbumDetailsViewModel model)
        {
            var albumId = model.Id;

            var album = this.albumService.GetAlbumById(albumId);

            var albumViewModel = new AlbumViewModel
            {
                Name    = album.Name,
                Cover   = album.Cover,
                Price   = album.Price.ToString("F2"),
                AlbumId = album.Id
            };

            var tracksViewModel = new TrackCollectionViewModel
            {
                Tracks = album.Tracks.Select(t => new TracksViewModel
                {
                    Name    = t.Name,
                    AlbumId = album.Id,
                    TrackId = t.Id
                })
            };

            this.Model.Data["AlbumViewModel"]           = albumViewModel;
            this.Model.Data["TrackCollectionViewModel"] = tracksViewModel;

            return(this.View());
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var album = await _context.Albums.FirstOrDefaultAsync(m => m.Id == id);

            if (album == null)
            {
                return(NotFound());
            }

            var albumImagesCount = _context.StoreImages.Where(i => i.Album.Id == album.Id).Count();

            var AlbumViewModel = new AlbumDetailsViewModel()
            {
                Id          = album.Id,
                Title       = album.Title,
                ImagesCount = albumImagesCount,
                Description = album.Description,
                FileName    = Path.Combine(_configuration.GetValue <string>("CustomSettings:ImagesPath"), album.AlbumFolderName, album.CoverPhoto)
            };

            return(View(AlbumViewModel));
        }
Exemplo n.º 12
0
        public HttpResponse Details(string albumId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var albumFromDb = this.albumService.GetAlbumById(albumId);

            if (albumFromDb == null)
            {
                return(this.Redirect("/Albums/All"));
            }

            var albumDetailsViewModel = new AlbumDetailsViewModel
            {
                Id     = albumFromDb.Id,
                Name   = albumFromDb.Name,
                Cover  = albumFromDb.Cover,
                Price  = albumFromDb.Price,
                Tracks = albumFromDb
                         .Tracks
                         .Select(t => new TrackAlbumAllViewModel
                {
                    Id   = t.Id,
                    Name = t.Name
                })
                         .ToList()
            };

            return(this.View(albumDetailsViewModel));
        }
Exemplo n.º 13
0
        public HttpResponse Details(string id)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var album  = this.albumsService.GetAlbumDetails(id);
            var tracks = this.albumsService.GetTracks(id);

            if (album == null)
            {
                return(this.Error("The album does not exist!"));
            }

            var model = new AlbumDetailsViewModel
            {
                Id     = album.Id,
                Name   = album.Name,
                Cover  = album.Cover,
                Price  = album.Price,
                Tracks = tracks.Select(t => new AlbumTracksViewModel
                {
                    Id   = t.Id,
                    Name = t.Name,
                }),
            };

            return(this.View(model));
        }
        public HttpResponse Details(string id)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var album = this.albumsService.GetAlbumById(id);

            var albumTracks = this.tracksService.GetAllTracksInAlbum(id);

            var tracks = albumTracks
                         .Select(x => new TrackListingViewModel
            {
                Id   = x.Id,
                Name = x.Name,
            }).ToList();

            var viewModel = new AlbumDetailsViewModel
            {
                Id     = album.Id,
                Name   = album.Name,
                Cover  = album.Cover,
                Price  = albumTracks.Sum(x => x.Price) * 0.87M,
                Tracks = tracks,
            };

            return(this.View(viewModel));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Index(string id)
        {
            var album = await _albumifyService.GetAsync(id);

            var viewModel = new AlbumDetailsViewModel(album);

            return(View(viewModel));
        }
Exemplo n.º 16
0
 public AlbumDetails(int albumId)
 {
     InitializeComponent();
     BindingContext = model = new AlbumDetailsViewModel()
     {
         _albumId = albumId
     };
 }
Exemplo n.º 17
0
        //------------------- DETAILS -----------------
        // /Albums/Details?id={albumId}
        public HttpResponse Details(string id)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            AlbumDetailsViewModel viewModel = this.albumsService.GetDetails(id);

            return(this.View(viewModel));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Edit(AlbumDetailsViewModel model, List <IFormFile> pictures, string userId)
        {
            var user = this.db.Users
                       .Where(u => u.Id == userId)
                       .FirstOrDefault();

            if (ModelState.IsValid)
            {
                var album = this.db.Album
                            .Where(al => al.Id == model.Id)
                            .FirstOrDefault();

                album.Name        = model.Name;
                album.Description = model.Description;

                db.Update(album);

                if (pictures.Capacity > 0)
                {
                    foreach (var image in pictures)
                    {
                        string filename = image.FileName.Split('\\').Last();

                        var img = new Image()
                        {
                            Name  = filename,
                            Album = album,
                            User  = this.db.Users
                                    .Where(u => u.Id == userId)
                                    .FirstOrDefault()
                        };

                        db.Images.Add(img);

                        string path = Path.Combine(environment.WebRootPath, "uploads", userId, album.Id.ToString());

                        Directory.CreateDirectory(Path.Combine(path));

                        using (FileStream fs = new FileStream(Path.Combine(path, filename), FileMode.Create))
                        {
                            await image.CopyToAsync(fs);
                        }

                        user.ImagesCount++;
                    }
                }

                db.SaveChanges();
            }

            return(RedirectToAction("Details", "Albums", new { @albumId = model.Id, @userId = userId }));
        }
        public ActionResult Details(string id)
        {
            Album albumFromDb = this.albumService.GetAlbumById(id);

            AlbumDetailsViewModel albumViewModel = ModelMapper.ProjectTo <AlbumDetailsViewModel>(albumFromDb);

            if (albumFromDb == null)
            {
                return(this.Redirect("/Albums/All"));
            }

            return(this.View(albumViewModel));
        }
Exemplo n.º 20
0
        public ActionResult Details()
        {
            var albumId = this.Request.QueryData["id"].ToString();

            Album albumFromDb = albumService.GetAlbumById(albumId);

            AlbumDetailsViewModel albumViewModel = ModelMapper.ProjectTo <AlbumDetailsViewModel>(albumFromDb);

            if (albumFromDb == null)
            {
                return(this.Redirect("/Albums/All"));
            }
            return(this.View(albumViewModel));
        }
Exemplo n.º 21
0
        public static AlbumDetailsViewModel EntityToModel(AlbumEntityModel entity)
        {
            AlbumDetailsViewModel model = new AlbumDetailsViewModel()
            {
                Id          = entity.Id,
                Name        = entity.Name,
                Comments    = entity.Comments,
                DateCreated = entity.DateCreated,
                Description = entity.Description,
                Photos      = entity.Photos,
                User        = entity.User,
            };

            return(model);
        }
Exemplo n.º 22
0
        public async Task MatchData_GetAlbumResult()
        {
            //Arrange
            abumDetails = new AlbumDetails(_logger, _mapper, _albumRepo);
            IdViewModel idViewModel = new IdViewModel();

            idViewModel.AlbumId = 3;
            //Act
            ResponseViewModel data = await abumDetails.GetAlbumDetails(idViewModel);

            //Assert
            AlbumDetailsViewModel albumDetails = (AlbumDetailsViewModel)data.Content;

            Assert.Equal("Classic", albumDetails.GenreName.Trim());
            Assert.Equal("Backstreet_Boys", albumDetails.albumName);
        }
Exemplo n.º 23
0
        public void ConvertsArtists()
        {
            var source   = CreateDomainAlbum();
            var result   = new AlbumDetailsViewModel(source);
            var expected = new List <ArtistViewModel>
            {
                new ArtistViewModel {
                    Name = "Jonezetta", ThirdPartyId = "09l3QuYe7ExcyAZYosgVJx"
                },
                new ArtistViewModel {
                    Name = "Made Up", ThirdPartyId = "MadeUp"
                }
            };

            result.Artists.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 24
0
        public IActionResult Details(AlbumDetailsViewModel albumViewModel)
        {
            if (albumViewModel.Id == null)
            {
                var result = this.AlbumService.CreateAlbumDetails(this.Request
                                                                  .QueryData[IRunesConstants.AlbumIdFromTrackCreateFormThroughRequestQeury].ToString());

                SetttingViewDataForAlbumDetails(result);
                return(this.View());
            }
            var albumDetails = this.AlbumService.GetAlbumDetails(albumViewModel.Id);

            SetttingViewDataForAlbumDetails(albumDetails);

            return(this.View());
        }
        public void SetTotalPriceWithAlbum_150and240_390()
        {
            //// Set Currency
            var userCurrency = new CurrencyViewModel();

            userCurrency.Code      = 840;
            userCurrency.ShortName = "USD";
            //// Set TrackPrices
            var priceTrack = new PriceViewModel();

            priceTrack.Currency = userCurrency;
            priceTrack.Amount   = 120;
            //// Create two tracks with total price = 240
            var track1 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack1",
                Price = priceTrack
            };
            var track2 = new TrackDetailsViewModel()
            {
                Name  = "SuperTrack2",
                Price = priceTrack
            };
            //// Set TrackPrices
            var priceAlbum = new PriceViewModel();

            priceAlbum.Currency = userCurrency;
            priceAlbum.Amount   = 150;
            //// Create album with price = 150
            var album1 = new AlbumDetailsViewModel()
            {
                Name  = "MyAlbum",
                Price = priceAlbum
            };
            //// Create and set CartView model
            var myCartView = new CartViewModel()
            {
                Tracks = new List <TrackDetailsViewModel>(),
                Albums = new List <AlbumDetailsViewModel>()
            };

            myCartView.Tracks.Add(track1);
            myCartView.Tracks.Add(track2);
            myCartView.Albums.Add(album1);
            CartViewModelService.SetTotalPrice(myCartView, userCurrency);
            Assert.IsTrue(myCartView.TotalPrice == 390);
        }
Exemplo n.º 26
0
        public async Task Details_FoundItem_ReturnsView()
        {
            Mock <BackendProvider> mockBackend = new Mock <BackendProvider>(autoMapper);

            mockBackend.Setup(m => m.AlbumGetByIDAsync(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(new Album {
                ArtistID = 1, AlbumID = 1
            });

            AlbumController       controller = new AlbumController(mockBackend.Object, autoMapper);
            ViewResult            result     = (await controller.Details(1, 1)) as ViewResult;
            AlbumDetailsViewModel viewModel  = result?.Model as AlbumDetailsViewModel;

            Assert.IsNotNull(result);
            Assert.IsNotNull(viewModel);
            Assert.AreEqual(1, viewModel.ArtistID);
            Assert.AreEqual(1, viewModel.AlbumID);
        }
        //
        // GET: Album/Details
        public ActionResult Details(int id)
        {
            var album  = _albumService.GetAlbum(id);
            var user   = _userService.GetUserById(album.UserId);
            var photos = _photoService.GetAllAlbumPhotos(album.Id);

            var model = new AlbumDetailsViewModel()
            {
                Id          = album.Id,
                AlbumName   = album.AlbumName,
                AlbumImage  = album.AlbumImage,
                UserDetails = user,
                Photos      = photos
            };

            return(View(model));
        }
Exemplo n.º 28
0
            public static void Initialize(TestContext _)
            {
                var source = CreateDomainAlbum();

                source.Tracks = new List <Track>
                {
                    new Track {
                        Name = "Welcome Home", Number = 1
                    },
                    new Track {
                        Name = "Get Ready (Hot Machete)", Number = 2
                    },
                    new Track {
                        Name = "Communicate", Number = 3
                    }
                };
                result = new AlbumDetailsViewModel(source);
            }
Exemplo n.º 29
0
        public AlbumDetailsViewModel GetDetails(string id)
        {
            AlbumDetailsViewModel album = this.db.Albums.Where(x => x.Id == id)
                                          .Select(x => new AlbumDetailsViewModel
            {
                Cover  = x.Cover,
                Name   = x.Name,
                Price  = x.Price,
                Id     = x.Id,
                Tracks = x.Tracks.Select(t => new TrackInfoViewModel
                {
                    Id   = t.Id,
                    Name = t.Name,
                })
            }).FirstOrDefault();

            return(album);
        }
Exemplo n.º 30
0
        public IActionResult Details(AlbumDetailsViewModel model)
        {
            var album = this.AlbumService.GetAlbumById(model.Id);

            if (album == null)
            {
                this.Model.Data["albumDetails"] = $"There are currently no album with {model.Id}.";
            }
            else
            {
                var albumTracksAsViewModel = album.Tracks.Select(at => new AlbumTracksViewModel
                {
                    Album       = at.Album,
                    AlbumId     = at.AlbumId.ToString().ToUpper(),
                    Track       = at.Track,
                    TrackId     = at.TrackId.ToString().ToUpper(),
                    NameOfTrack = at.Track.Name
                }).ToList();

                foreach (var albumTracks in albumTracksAsViewModel)
                {
                    Console.WriteLine($"Album Name {albumTracks.Album.Name} Track Name {albumTracks.Track.Name} TRackName {albumTracks.NameOfTrack}");
                }

                var albumsAsViewModel = new AlbumDetailsViewModel()
                {
                    Cover       = album.Cover,
                    Id          = album.Id.ToString().ToUpper(),
                    Name        = album.Name,
                    AlbumTracks = albumTracksAsViewModel
                };


                if (album.Tracks.Count == 0)
                {
                    albumsAsViewModel.NoTracks = "There are no tracks in album";
                }

                this.Model.Data["albumDetails"] = albumsAsViewModel;
            }

            return(this.View());
        }