Ejemplo n.º 1
0
        public ActionResult Delete([Bind(Include = "Id,Name")] TrackManagementViewModel track)
        {
            if (track != null)
            {
                using (var repository = RepositoryFactory.GetTrackRepository())
                {
                    repository.Delete(ManagementMapper.GetTrackModel(track));
                    repository.SaveChanges();
                }
            }

            return(RedirectToAction("List", "Tracks", new { area = "Content" }));
        }
Ejemplo n.º 2
0
        public virtual ActionResult New(
            [Bind(Include = "PostedTrackFile,PostedImage,PostedTrackSample,ArtistId,ArtistName,Duration,Genres,GenreId,Name,ReleaseDate,FileName,Price")]
            TrackManagementViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var track = ManagementMapper.GetTrackModel(viewModel);

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

                using (var repository = this.RepositoryFactory.GetTrackRepository())
                {
                    repository.AddOrUpdate(track);
                    repository.SaveChanges();
                }

                if (viewModel.Price != null && CurrentUser != null)
                {
                    using (var priceRepository = RepositoryFactory.GetTrackPriceRepository())
                    {
                        priceRepository.AddOrUpdate(new TrackPrice
                        {
                            TrackId      = track.Id,
                            CurrencyId   = CurrentUserCurrency.Id,
                            PriceLevelId = CurrentUser.PriceLevelId,
                            Price        = viewModel.Price.Value
                        });
                        priceRepository.SaveChanges();
                    }
                }

                return(this.RedirectToAction("Details", "Tracks", new { id = track.Id, area = "Content" }));
            }

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public virtual ActionResult Edit(
            [Bind(Include = "Id,PostedTrackFile,PostedImage,PostedTrackSample,ArtistId,ArtistName,Duration,Genres,GenreId,Name,ReleaseDate,FileName,Price,Image,TrackFile,TrackSample")]
            TrackManagementViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Track currentTrack;
                using (var repo = this.RepositoryFactory.GetTrackRepository())
                {
                    currentTrack = repo.GetById(viewModel.Id);
                }

                if (currentTrack == null)
                {
                    return(this.HttpNotFound($"Трек с id = {viewModel.Id} не найден"));
                }

                if (viewModel.PostedTrackFile == null)
                {
                    viewModel.TrackFile = currentTrack.TrackFile;
                }

                if (viewModel.PostedImage == null)
                {
                    viewModel.Image = currentTrack.Image;
                }

                var track = ManagementMapper.GetTrackModel(viewModel);
                track.OwnerId = currentTrack.OwnerId;
                using (var repository = this.RepositoryFactory.GetTrackRepository())
                {
                    repository.AddOrUpdate(track);
                    repository.SaveChanges();
                }

                if (viewModel.Price != null)
                {
                    using (var priceRepository = RepositoryFactory.GetTrackPriceRepository())
                    {
                        var trackPrice = priceRepository.FirstOrDefault(p => p.TrackId == track.Id &&
                                                                        p.CurrencyId == CurrentUserCurrency.Id &&
                                                                        p.PriceLevelId == CurrentUser.PriceLevelId);
                        if (trackPrice == null)
                        {
                            trackPrice = new TrackPrice
                            {
                                TrackId      = track.Id,
                                CurrencyId   = CurrentUserCurrency.Id,
                                PriceLevelId = CurrentUser.PriceLevelId
                            };
                        }

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

                return(this.RedirectToAction("Details", "Tracks", new { id = track.Id, area = "Content" }));
            }

            if (viewModel.Genres == null)
            {
                viewModel.Genres = GetGenres();
            }

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