// Get All basic tables // DEFAULT CRUD public IEnumerable <ManagementMapper> GetManagements() { var content = db.Managements.ToList(); if (content.Count() == 0) { return(null); } else { List <ManagementMapper> managements = new List <ManagementMapper>(); ContactsHelper contact = new ContactsHelper(); foreach (var item in content) { ManagementMapper management = new ManagementMapper { ManagerId = item.managerId, ContactId = item.contactId ?? 0, DepartmentName = item.departmentName }; managements.Add(management); } return(managements); } }
public virtual ActionResult Edit( [Bind(Include = "Id, Name, Birthday, Biography, Photo, PostedPhoto")] ArtistManagementViewModel viewModel) { if (ModelState.IsValid) { Artist currentArtist; using (var repo = this.RepositoryFactory.GetArtistRepository()) { currentArtist = repo.GetById(viewModel.Id); } if (currentArtist == null) { return(this.HttpNotFound($"Исполнитель с id = {viewModel.Id} не найден")); } using (var repository = RepositoryFactory.GetArtistRepository()) { var artist = ManagementMapper.GetArtistModel(viewModel); repository.AddOrUpdate(artist); repository.SaveChanges(); return(RedirectToAction("Details", "Artists", new { id = viewModel.Id, area = "Content" })); } } return(View(viewModel)); }
/// <summary> /// </summary> /// <param name="id"> /// The id. /// </param> /// <returns> /// </returns> public ActionResult Edit(int id) { var genreService = ServiceFactory.GetGenreService(); var genreManagementViewModel = ManagementMapper.GetGenreManagementViewModel(genreService.GetGenreDetailsViewModel(id)); return(View(genreManagementViewModel)); }
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)); }
public virtual ActionResult New(GenreManagementViewModel viewModel) { var genre = ManagementMapper.GetGenreModel(viewModel); using (var repository = RepositoryFactory.GetGenreRepository()) { repository.AddOrUpdate(genre); repository.SaveChanges(); } CacheHelper.ClearCachedGenres(); return(RedirectToAction("Details", "Genres", new { area = "Content", id = genre.Id })); }
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" })); }
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" })); }
/// <summary> /// </summary> /// <param name="id"> /// The artist id. /// </param> /// <returns> /// </returns> public virtual ActionResult Edit(int id = 0) { if (id <= 0) { return(RedirectToAction("List", "Artists", new { area = "Content" })); } var artistService = ServiceFactory.GetArtistService(); var artist = ManagementMapper.GetArtistManagementViewModel(artistService.GetArtistDetails(id)); if (artist == null) { return(HttpNotFound($"Исполнитель с id = {id} не найден")); } return(View(artist)); }
/// <summary> /// Deletes the track with the specified <paramref name="id"/> from the system. /// </summary> /// <param name="id"> /// The track id. /// </param> /// <returns> /// The view which generates page for deleting tracks in case if <paramref name="id"/> was specified; /// otherwise redirects to the list of tracks. /// </returns> public ActionResult Delete(int?id) { if (id == null || id <= 0) { return(RedirectToAction("List", "Tracks", new { area = "Content" })); } var trackService = ServiceFactory.GetTrackService(); var track = ManagementMapper.GetTrackManagementViewModel(trackService.GetTrackDetails(id.Value, CurrentUserCurrency.Code, CurrentUser.PriceLevelId)); if (track == null) { return(HttpNotFound($"Трек с id = {id} не найден")); } return(View(track)); }
public ActionResult New( [Bind(Include = "Name, Birthday, Biography, Photo, PostedPhoto")] ArtistManagementViewModel viewModel) { if (ModelState.IsValid) { var artist = ManagementMapper.GetArtistModel(viewModel); using (var repository = RepositoryFactory.GetArtistRepository()) { repository.AddOrUpdate(artist); repository.SaveChanges(); return(RedirectToAction("Details", "Artists", new { area = "Content", id = artist.Id })); } } return(View(viewModel)); }
/// <summary> /// Deletes the album with the specified <paramref name="id"/> from the system. /// </summary> /// <param name="id"> /// The album id. /// </param> /// <returns> /// The view which generates page for deleting albums in case if <paramref name="id"/> was specified; /// otherwise redirects to the list of albums. /// </returns> public ActionResult Delete(int?id) { if (id == null || id <= 0) { return(RedirectToAction("List", "Albums", new { area = "Content" })); } var albumService = ServiceFactory.GetAlbumService(); var album = ManagementMapper.GetAlbumManagementViewModel(albumService.GetAlbumDetails(id.Value, CurrentUserCurrency.Code, CurrentUser.PriceLevelId)); if (album == null) { return(HttpNotFound($"Альбом с id = {id} не найден")); } return(View(album)); }
public ActionResult Edit(GenreManagementViewModel viewModel) { if (!ModelState.IsValid) { return(RedirectToAction("List", "Genres", new { Area = "Content" })); } var genreModel = ManagementMapper.GetGenreModel(viewModel); using (var repo = RepositoryFactory.GetGenreRepository()) { repo.AddOrUpdate(genreModel); repo.SaveChanges(); } CacheHelper.ClearCachedGenres(); return(RedirectToAction("Details", "Genres", new { Area = "Content", id = viewModel.Id })); }
/// <summary> /// </summary> /// <returns> /// </returns> public virtual ActionResult Edit(int id = 0) { if (id <= 0) { return(RedirectToAction("List", "Tracks", new { area = "Content" })); } var trackService = ServiceFactory.GetTrackService(); var trackManagementViewModel = ManagementMapper.GetTrackManagementViewModel(trackService.GetTrackDetails(id, CurrentUserCurrency.Code, CurrentUser.PriceLevelId)); if (trackManagementViewModel == null) { return(HttpNotFound($"Трек с id = {id} не найден")); } trackManagementViewModel.Genres = GetGenres(); return(this.View(trackManagementViewModel)); }
// Get One basic table // DEFAULT CRUD public ManagementMapper GetManagement(int managerId) { var content = db.Managements.FirstOrDefault(j => j.managerId == managerId); if (content == null) { return(null); } else { ContactsHelper contact = new ContactsHelper(); ManagementMapper management = new ManagementMapper { ManagerId = content.managerId, ContactId = content.contactId ?? 0, DepartmentName = content.departmentName }; return(management); } }
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)); }
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)); }
/// <summary> /// </summary> /// <param name="id"> /// The artist id. /// </param> /// <returns> /// </returns> public virtual ActionResult Edit(int id = 0) { if (id <= 0) { return(RedirectToAction("List", "Albums", new { area = "Content" })); } var albumService = ServiceFactory.GetAlbumService(); var viewModel = ManagementMapper.GetAlbumManagementViewModel(albumService.GetAlbumDetails(id, CurrentUserCurrency.Code, CurrentUser.PriceLevelId)); if (viewModel == null) { return(HttpNotFound($"Альбом с id = {id} не найден")); } using (var realtionsRepo = RepositoryFactory.GetAlbumTrackRelationRepository()) { var tracks = realtionsRepo.GetAll(t => t.AlbumId == id, t => t.Track).Select(t => t.Track).ToList(); ViewBag.Tracks = tracks; } return(View(viewModel)); }
public ManagementService(string connectionString) { this._connectionString = connectionString; this._mapper = ManagementMapper.GetMapper(typeof(TModel)); }
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)); }