public void TestEditPost_Given_EditViewModelWithChanges_Should_UpdateRelatedAlbum()
        {
            int         albumId = 1;
            TestContext testContext = new TestContextBuilder().AddDefaultAlbum(albumId, 1, 5).Build();
            var         albumController = new AlbumController(testContext.AlbumRepository, testContext.PhotoRepository, null);
            string      newTitle = "NewTitle1", newDescription = "NewDescription1", newPlace = "NewPlace1", newCity = "NewCity1", newCountry = "newCountry1";
            DateTime    newFrom = new DateTime(2016, 1, 1), newTo = new DateTime(2016, 1, 2);
            var         editAlbumViewModel = new EditAlbumViewModel
            {
                Id          = 1,
                Title       = newTitle,
                Description = newDescription,
                From        = newFrom, To = newTo,
                Place       = newPlace, City = newCity, Country = newCountry,
            };

            var result = albumController.Edit(editAlbumViewModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["controller"], "Admin");

            AlbumEntity album = testContext.Context.Albums.First(a => a.Id == albumId);

            Assert.AreEqual(album.Title, newTitle);
            Assert.AreEqual(album.Description, newDescription);
            Assert.AreEqual(album.Place.Name, newPlace);
            Assert.AreEqual(album.Place.City, newCity);
            Assert.AreEqual(album.Place.Country, newCountry);
            Assert.AreEqual(album.Period.From, newFrom);
            Assert.AreEqual(album.Period.To, newTo);
        }
        public async Task <IActionResult> EditAlbum(int id, EditAlbumViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View(model));
            }

            using (var memoryStream = new MemoryStream())
            {
                try
                {
                    await model.Cover.CopyToAsync(memoryStream);
                }
                catch
                {
                }

                Album albumToUpdate = _applicationDbContext.Albums.SingleOrDefault(x => x.Id == id);

                albumToUpdate.Titel = model.Title;
                if (model.Cover != null)
                {
                    albumToUpdate.Cover = memoryStream.ToArray();
                }

                _applicationDbContext.Albums.Update(albumToUpdate);
                _applicationDbContext.SaveChanges();

                return(RedirectToAction("IndexAlbum"));
            }
        }
        public EditAlbumViewModel Map(AlbumDetail album, ICollection <ArtistNameRef> artistNames, ICollection <GenreDetail> genres)
        {
            GenreViewModelMapper genreMapper = new GenreViewModelMapper();
            EditAlbumViewModel   model       = new EditAlbumViewModel();

            model.Id              = album.Id;
            model.ArtistId        = album.ArtistId;
            model.Title           = album.Title;
            model.DescriptionText = album.DescriptionText;
            model.Label           = album.Label;
            model.Price           = album.Price;
            model.Producer        = album.Producer;
            model.ReleaseDate     = album.ReleaseDate;
            model.CoverImageId    = album.CoverImageId;
            model.Created         = album.CreatedUtc;
            model.Updated         = album.UpdatedUtc;
            model.PublishedStatus = album.PublishedStatus;


            model.Tracks        = album.Tracks.Select(x => this.Map(x)).ToList();
            model.ArtistOptions = artistNames
                                  .Select(x => new SelectListItem
            {
                Text     = x.Name,
                Value    = x.Id.ToString(),
                Selected = x.Id == model.ArtistId
            }).ToList();

            model.Genres = genres.Select(g => genreMapper.Map(g)).ToList();
            model.Genres.Where(g => album.Genres.Contains(g.Name)).ToList().ForEach(x => x.IsSelected = true);

            return(model);
        }
Example #4
0
        public ViewResult Edit(Guid id)
        {
            var album = _databaseContext.Album.Include(a => a.Songs)
                        //.ThenInclude(s => s.SongPersons)
                        //.ThenInclude(sp => sp.Person)
                        //.Include("AlbumGenres.Genre")
                        //.Include(a => a.Label)
                        .FirstOrDefault(m => m.AlbumID == id);

            Console.WriteLine("evo" + album.AlbumName);

            ViewData["Success"] = TempData["Success"];
            ViewData["Labels"]  = _databaseContext.Label.ToList();
            ViewData["Genres"]  = _databaseContext.Genre.ToList();
            ViewData["Songs"]   = _databaseContext.Song.ToList();

            var model = new EditAlbumViewModel
            {
                Album    = album,
                LabelID  = album.Label.LabelID,
                GenreIDs = album.Genres.ToList().Select(gu => gu.GenreID),
                SongIDs  = album.Songs.ToList().Select(mu => mu.SongID)
            };

            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> Edit(int id)
        {
            try
            {
                var album = await unitOfWork.Albums.GetAsync(id);

                // temporary solutions tracking
                // https://github.com/aspnet/AspNetCore.Docs/issues/10393
                var isAuthorized = await authorizationService
                                   .AuthorizeAsync(User, album, AutherazationOperations.OwenResourse);

                if (!isAuthorized.Succeeded)
                {
                    return(RedirectToAction("AccessDenied", "Users"));
                }

                var dto = mapper.Map <AlbumForUpdatingDto>(album);
                var vm  = new EditAlbumViewModel
                {
                    Dto = dto
                };
                return(View(vm));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while getting albums.");
            }
            // ToDo: Implement error page
            return(View("Error"));
        }
Example #6
0
        public async Task <IActionResult> Edit(int id, EditAlbumViewModel vm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(vm));
                }

                if (id != vm.Dto.Id)
                {
                    vm.Message = "Opps update failed please try again";
                    return(View(vm));
                }

                await unitOfWork.Albums.UpdateAsync(vm.Dto);

                await unitOfWork.SaveAsync();

                return(RedirectToAction(nameof(Details), new { id }));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while deleting song.");
            }
            // ToDo: Implement error page
            return(View("ErrorSaving"));
        }
Example #7
0
        public IActionResult OnGet(int?albumId)
        {
            if (albumId == null)
            {
                return(NotFound());
            }

            var album = _context.Albums.Find(albumId);

            if (album == null)
            {
                return(NotFound());
            }

            Album = new EditAlbumViewModel()
            {
                Id              = album.AlbumId,
                Title           = album.Title,
                ArtistId        = album.ArtistId,
                ReferenceNumber = album.ReferenceNumber
            };

            ArtistList = _context.Artists
                         .OrderBy(x => x.Name)
                         .Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.ArtistId.ToString()
            });

            return(Page());
        }
Example #8
0
        public async Task <IActionResult> Edit(int id, EditAlbumViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                model.Categories = await this.GetCategories();

                return(this.View(model));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var album = await this.albums.Find(id);

            if (user.Id != album.UserId)
            {
                return(this.BadRequest());
            }

            var success = await this.albums.Edit(
                model.Title,
                model.Description,
                int.Parse(model.CategoryId),
                id);

            if (!success)
            {
                return(this.BadRequest());
            }

            this.TempData.AddSuccessMessage($"Album {model.Title} details have been successfully changed.");
            return(this.RedirectToAction("Details", "Albums", new { Area = "", id = id }));
        }
        public void AddPhoto(EditAlbumViewModel model)
        {
            var currentUserId = User.Identity.GetUserId();

            MemoryStream target = new MemoryStream();

            model.NewPhoto.InputStream.CopyTo(target);
            byte[] data = target.ToArray();

            var photoToAdd = new Photo()
            {
                Content   = data,
                ProfileId = currentUserId,
                Profile   = db.Profiles.Where(p => p.Id == currentUserId).FirstOrDefault(),
                AlbumId   = model.Id,
                Album     = db.Albums.Where(a => a.Id == model.Id).FirstOrDefault()
            };

            db.Photos.Add(photoToAdd);
            //db.SaveChanges();

            model.Photos.Add(new PhotoViewModel
            {
                Id = GetPictureById(photoToAdd.Id).Id
            });
        }
Example #10
0
        public EditAlbumViewModel GetEditAlbumViewModel(int id)
        {
            EditAlbumViewModel editAlbum = Mapper.Map <Album, EditAlbumViewModel>(albumDomainService.GetAlbumById(id));

            editAlbum.SelectListSingers = new SelectList(singerDomainService.GetListSingers(), "Id", "Name");

            return(editAlbum);
        }
Example #11
0
        public async Task <IActionResult> Edit(int id, EditAlbumViewModel album)
        {
            if (id != album.Id)
            {
                return(NotFound());
            }

            var currAlbum = new Album
            {
                Id              = album.Id,
                Name            = album.Name,
                ImageUrl        = album.ImageUrl,
                Year            = album.Year,
                Format          = album.Format,
                MediaCondition  = album.MediaCondition,
                SleeveCondition = album.SleeveCondition,
                Notes           = album.Notes,
                ArtistId        = album.ArtistId,
            };


            if (ModelState.IsValid)
            {
                try
                {
                    _service.Edit(
                        id,
                        album.Name,
                        album.ImageUrl,
                        album.Year,
                        album.Format,
                        album.MediaCondition,
                        album.SleeveCondition,
                        album.Notes,
                        album.ArtistId);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AlbumExists(album.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            var userId = User.Id();

            var artistList = await _artists.ArtistsList(userId);

            ViewData["ArtistId"] = new SelectList(artistList, "Id", "Name", album.ArtistId);
            return(View(album));
        }
Example #12
0
 public ActionResult Create(EditAlbumViewModel model)
 {
     if (ModelState.IsValid)
     {
         Album album = AlbumMapper.MapEditAlbumViewModel(model, userID);
         albumRepository.AddAlbum(album);
     }
     return(Content(model.Name));
 }
        public IActionResult EditAlbum(int id)
        {
            Album albumFromDb = _applicationDbContext.Albums.SingleOrDefault(x => x.Id == id);
            EditAlbumViewModel albumToEdit = new EditAlbumViewModel
            {
                Title = albumFromDb.Titel,
            };

            return(View(albumToEdit));
        }
Example #14
0
        public ActionResult Edit(EditAlbumViewModel model, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                Album album = AlbumMapper.MapEditAlbumViewModel(model, userID);

                albumRepository.UpdateAlbum(album);
            }
            return(Content(model.Name));
        }
Example #15
0
 internal static Album MapEditAlbumViewModel(EditAlbumViewModel model, Guid id)
 {
     return(new Album
     {
         Name = model.Name,
         Description = model.Description,
         UserID = id,
         Id = model.Id
     });
 }
Example #16
0
        public IActionResult Update(Guid id, EditAlbumViewModel model)
        {
            if (ModelState.IsValid)
            {
                var album = _databaseContext.Album
                            .Include("AlbumGenres.Genre")
                            .Include("SongAlbums.Song.SongGenres.Genre")
                            .FirstOrDefault(m => m.AlbumID == id);


                album.Label       = _databaseContext.Label.ToList().First(c => c.LabelID == model.LabelID);
                album.AlbumName   = model.Album.AlbumName;
                album.AlbumYear   = model.Album.AlbumYear;
                album.Description = model.Album.Description;
                album.AvgGrade    = model.Album.AvgGrade;
                album.Format      = model.Album.Format;
                album.ImagePath   = model.Album.ImagePath;
                album.Price       = model.Album.Price;
                album.Stock       = model.Album.Stock;

                foreach (Guid ID in model.GenreIDs)
                {
                    var genre = _databaseContext.Genre.Find(ID);
                    album.Genres.Add(genre);
                }
                foreach (Guid ID in model.SongIDs)
                {
                    var song = _databaseContext.Song.Find(ID);
                    album.Songs.Add(song);
                }


                TempData["Success"] = true;

                album.Genres.Clear();
                album.Songs.Clear();

                var newGenres = _databaseContext.Genre.Where(u => model.GenreIDs.Contains(u.GenreID)).ToList();
                foreach (var genre in newGenres)
                {
                    album.Genres.Add(genre);
                }

                var newSongs = _databaseContext.Song.Where(u => model.SongIDs.Contains(u.SongID)).ToList();
                foreach (var song in newSongs)
                {
                    album.Songs.Add(song);
                }


                _databaseContext.SaveChanges();
            }
            return(Redirect(nameof(Index)));
        }
        public virtual ActionResult EditAlbum(EditAlbumViewModel albumView)
        {
            if (ModelState.IsValid)
            {
                adminAlbum.EditAlbum(albumView);

                return(Redirect(Url.Action(MVC.Admin.Admin.FormSuccess())));
            }

            return(PartialView("FormEditAlbum", adminAlbum.GetEditAlbumViewModel(albumView)));
        }
Example #18
0
 public ActionResult EditAlbum(EditAlbumViewModel album)
 {
     if (!ModelState.IsValid)
     {
         return(View(album));
     }
     if (GalleryService.EditAlbum(album.ToEntity()))
     {
         return(RedirectToAction("index", "gallery"));
     }
     return(View());
 }
Example #19
0
        public ActionResult EditAlbum()
        {
            if ((string)Session["ValidSession"] == "valid")
            {
                var model = new EditAlbumViewModel();

                return(View(model));
            }
            else
            {
                return(View("~/Views/Home/Index.cshtml", new DashboardViewModel()));
            }
        }
Example #20
0
        public ActionResult Delete(EditAlbumViewModel model)
        {
            Album album = albumRepository.GetAlbumByID(model.Id);

            model = AlbumMapper.MapEditAlbumViewModel(album);

            if (album.UserID == userID)
            {
                return(View(model));
            }

            return(View());
        }
Example #21
0
        public ActionResult Delete(EditAlbumViewModel model, FormCollection collection)
        {
            Album album = AlbumMapper.MapEditAlbumViewModel(model, userID);

            albumRepository.DeleteAlbum(album);

            List <Album> albumsDB            = albumRepository.GettAllAlbumsByUserID(userID);
            List <ListAlbumViewModel> albums = new List <ListAlbumViewModel>();

            albumsDB.ForEach(x => albums.Add(AlbumMapper.MapListAlbumViewModel(x)));

            return(PartialView("_Items", albums));
        }
        public void ViewModelConstruction_test()
        {
            Album album = new Album()
            {
                AlbumId = 1, Title = "White Album"
            };
            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            EditAlbumViewModel viewModel = new EditAlbumViewModel(mockServiceFactory.Object, album);

            Assert.True(viewModel.Album != null && viewModel.Album != album);
            Assert.True(viewModel.Album.AlbumId == album.AlbumId && viewModel.Album.Title == album.Title);
        }
        public ActionResult Edit([Bind] EditAlbumViewModel albumViewModel)
        {
            if (ModelState.IsValid)
            {
                var albumEntity = albumViewModel.ToAlbumEntity();
                _albumRepository.UpdateAlbum(albumEntity);

                TempData["message"] = $"Album '{albumEntity.Title}' has been edited successfully";
                return(RedirectToAction("Albums", "Admin"));
            }

            return(View(albumViewModel));
        }
        public ActionResult Edit(EditAlbumViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.GenreLookupList  = _genreService.GetAllGenres().Genres.OrderBy(g => g.Name);
                model.ArtistLookupList = _artistService.GetAllArtists().Artists.OrderBy(a => a.Name);

                return(View(model));
            }

            _albumService.EditAlbum(model.ConvertToEditAlbumRequest());

            return(RedirectToAction("Index"));
        }
        public void TestDeletePost_Given_AlbumWithPhotos_Should_DeleteAlbum()
        {
            var testContext        = new TestContextBuilder().AddDefaultAlbum(1).AddDefaultAlbum(2).Build();
            var albumController    = new AlbumController(testContext.AlbumRepository, testContext.PhotoRepository, null);
            var albumEditViewModel = new EditAlbumViewModel {
                Id = 1
            };

            var result = albumController.Delete(albumEditViewModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["controller"], "Admin");
            Assert.IsTrue(testContext.Context.Albums.Count() == 1);
        }
        public void AlbumIsValid_isValid_test()
        {
            Album album = new Album()
            {
                AlbumId = 1, Title = "White Album", Artist = "Beatles",
                Genre   = 5, AlbumNumber = "RCRL-Btls-034", Price = -1m
            };
            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            EditAlbumViewModel viewModel = new EditAlbumViewModel(mockServiceFactory.Object, album);

            Assert.True(!viewModel.Album.IsValid);
            viewModel.Album.Price = 17.5m;
            Assert.True(viewModel.Album.IsValid);
        }
        public void CanSaveCommand_test()
        {
            Album album = new Album()
            {
                AlbumId = 1, Title = "White Album", Artist = "Beatles",
                Genre   = 5, AlbumNumber = "RCRL-Btls-034", Price = 14.90M
            };
            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            EditAlbumViewModel viewModel = new EditAlbumViewModel(mockServiceFactory.Object, album);

            Assert.False(viewModel.SaveCommand.CanExecute(null));
            viewModel.Album.Title = "Revolver";
            Assert.True(viewModel.SaveCommand.CanExecute(null));
        }
Example #28
0
        public void EditAlbum(EditAlbumViewModel albumView)
        {
            Album album = albumDomainService.GetAlbumWithImage(albumView.Id);

            Mapper.Map(albumView, album);

            if (albumView.AlbumImage != null)
            {
                album.AlbumImage.ImageData = GetArray(albumView.AlbumImage);
            }

            album.Singer = singerDomainService.GetSingerById(albumView.SingerId);

            albumDomainService.Entry(album).State = EntityState.Modified;
            albumDomainService.SaveChanges();
        }
        public ActionResult Delete([Bind(Include = "Id, Title, Description, Place, City, Country, From, To")]
                                   EditAlbumViewModel albumViewModel)
        {
            try
            {
                _albumRepository.RemoveAlbumById(albumViewModel.Id);
                TempData["message"] = $"Album '{albumViewModel.Title}' has been deleted successfully";
                return(RedirectToAction("Albums", "Admin"));
            }
            catch
            {
                ModelState.AddModelError("", "Failed to delete album");
            }

            return(View(albumViewModel));
        }
 public AlbumDetail MapOnTo(EditAlbumViewModel model, AlbumDetail existingObject, int?coverImageId)
 {
     existingObject.Title           = model.Title;
     existingObject.DescriptionText = model.DescriptionText;
     existingObject.Genres          = model.Genres.Where(g => g.IsSelected).Select(g => g.Name).ToList();
     if (coverImageId.HasValue)
     {
         existingObject.CoverImageId = coverImageId.Value;
     }
     existingObject.Label       = model.Label;
     existingObject.Price       = model.Price;
     existingObject.Producer    = model.Producer;
     existingObject.ReleaseDate = model.ReleaseDate;
     existingObject.Tracks      = model.Tracks.Select(x => this.Map(x)).ToList();
     return(existingObject);
 }