Ejemplo n.º 1
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.º 2
0
        public ActionResult Delete([Bind(Include = "Id,Name")] AlbumManagementViewModel album)
        {
            if (album != null)
            {
                using (var repository = RepositoryFactory.GetAlbumRepository())
                {
                    repository.Delete(ManagementMapper.GetAlbumModel(album));
                    repository.SaveChanges();
                }
            }

            return(RedirectToAction("List", "Albums", new { area = "Content" }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="artistId">
        ///     The id.
        /// </param>
        /// <returns>
        /// </returns>
        public virtual ActionResult New(int artistId = 0)
        {
            var viewModel = new AlbumManagementViewModel();

            if (artistId > 0)
            {
                using (var artistRepository = RepositoryFactory.GetArtistRepository())
                {
                    var artist = artistRepository.GetById(artistId);
                    if (artist != null)
                    {
                        viewModel.ArtistId   = artistId;
                        viewModel.ArtistName = artist.Name;
                    }
                }
            }

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public virtual ActionResult New(
            [Bind(Include = "ArtistId, ArtistName, Name, ReleaseDate, PostedCover, Price")] AlbumManagementViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var album = ManagementMapper.GetAlbumModel(viewModel);

                if (this.CurrentUser != null && this.CurrentUser.IsInRole(UserRoles.Seller))
                {
                    album.OwnerId = this.CurrentUser.UserProfileId;
                }

                using (var albumRepo = RepositoryFactory.GetAlbumRepository())
                {
                    albumRepo.AddOrUpdate(album);
                    albumRepo.SaveChanges();
                }

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

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

            return(View(viewModel));
        }
Ejemplo n.º 5
0
 /// <summary>
 ///     Executes a mapping from the <see cref="AlbumManagementViewModel" /> model to a new <see cref="Album" /> model.
 /// </summary>
 /// <param name="album">
 ///     The album management view model.
 /// </param>
 /// <returns>
 ///     A new <see cref="Album" /> DTO model.
 /// </returns>
 public static Album GetAlbumModel(AlbumManagementViewModel album)
 {
     return(_managementModelsMapper.Map <Album>(album));
 }