Beispiel #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));
        }
Beispiel #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" }));
        }
Beispiel #3
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));
        }