Ejemplo n.º 1
0
        public void GetPriceViewModelForAlbumPriceTest()
        {
            var currencyDto   = CreateCurrency();
            var priceLevelDto = CreatePriceLevel();

            var albumDto = new Album
            {
                Id   = 1,
                Name = "Some album"
            };

            var albumPriceDto = new AlbumPrice
            {
                Id           = 1,
                AlbumId      = albumDto.Id,
                Album        = albumDto,
                CurrencyId   = currencyDto.Id,
                Currency     = currencyDto,
                Price        = 4.99m,
                PriceLevelId = priceLevelDto.Id,
                PriceLevel   = priceLevelDto
            };

            var priceViewModel = ModelsMapper.GetPriceViewModel(albumPriceDto);

            Assert.IsNotNull(priceViewModel);

            Assert.IsTrue(priceViewModel.Amount == albumPriceDto.Price);

            Assert.IsNotNull(priceViewModel.Currency);
            Assert.IsTrue(priceViewModel.Currency.Code == albumPriceDto.Currency.Code);
            Assert.IsTrue(priceViewModel.Currency.ShortName.Equals(albumPriceDto.Currency.ShortName, StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(priceViewModel.Currency.FullName.Equals(albumPriceDto.Currency.FullName, StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(priceViewModel.Currency.Symbol.Equals(albumPriceDto.Currency.Symbol, StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 2
0
        public virtual ActionResult Edit(
            [Bind(Include = "Id, ArtistId, ArtistName, Name, ReleaseDate, PostedCover, Price, Cover")]
            AlbumManagementViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Album currentAlbum;
                using (var repo = this.RepositoryFactory.GetAlbumRepository())
                {
                    currentAlbum = repo.GetById(viewModel.Id);
                }

                if (currentAlbum == null)
                {
                    return(this.HttpNotFound($"Альбом с id = {viewModel.Id} не найден"));
                }

                if (viewModel.PostedCover == null)
                {
                    viewModel.Cover = currentAlbum.Cover;
                }

                var album = ManagementMapper.GetAlbumModel(viewModel);
                album.OwnerId = currentAlbum.OwnerId;
                using (var albumRepo = RepositoryFactory.GetAlbumRepository())
                {
                    albumRepo.AddOrUpdate(album);
                    albumRepo.SaveChanges();
                }

                if (viewModel.Price != null)
                {
                    using (var priceRepository = RepositoryFactory.GetAlbumPriceRepository())
                    {
                        var albumPrice = priceRepository.FirstOrDefault(p => p.AlbumId == album.Id &&
                                                                        p.CurrencyId == CurrentUserCurrency.Id &&
                                                                        p.PriceLevelId == CurrentUser.PriceLevelId);
                        if (albumPrice == null)
                        {
                            albumPrice = new AlbumPrice
                            {
                                AlbumId      = album.Id,
                                CurrencyId   = CurrentUserCurrency.Id,
                                PriceLevelId = CurrentUser.PriceLevelId
                            };
                        }

                        albumPrice.Price = viewModel.Price.Value;
                        priceRepository.AddOrUpdate(albumPrice);
                        priceRepository.SaveChanges();
                    }
                }

                return(RedirectToAction("Details", "Albums", new { id = album.Id, area = "Content" }));
            }

            return(View(viewModel));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Executes a mapping from the <see cref="AlbumPrice"/> model to a new <see cref="PriceViewModel"/> model.
 /// </summary>
 /// <param name="albumPrice">
 /// The album price DTO model.
 /// </param>
 /// <returns>
 /// A new <see cref="PriceViewModel"/> model.
 /// </returns>
 public static PriceViewModel GetPriceViewModel(AlbumPrice albumPrice)
 {
     return(_commonMapper.Map <PriceViewModel>(albumPrice));
 }