Ejemplo n.º 1
0
        public IActionResult EditArtWork(int id, EditArtWorkViewModel editArtWorkViewModel)
        {
            if (this.ArtisticWorkService.GetArtisticWorkById(id) == null)
            {
                return(RedirectToAction("Categories", "ArtisticWork", new { area = "" }));
            }
            ;

            this.ArtisticWorkService.EditArtWork(id, editArtWorkViewModel);

            return(RedirectToAction("Categories", "ArtisticWork", new { area = "" }));
        }
Ejemplo n.º 2
0
        public void EditArtWorkShouldEditsArtworkCorrect()
        {
            var options = new DbContextOptionsBuilder <WAGDbContext>()
                          .UseInMemoryDatabase(databaseName: "Edit_ArtWork_Db")
                          .Options;

            var dbContext = new WAGDbContext(options);

            var service = new ArtisticWorkService(dbContext, null);

            var artisticWork = new ArtisticWork()
            {
                Year         = 2015,
                Height       = 120.5,
                Width        = 80.2,
                Price        = 350.99m,
                Availability = true,
                HasFrame     = true,
                Technique    = "Test Technique",
            };

            dbContext.ArtisticWorks.Add(artisticWork);
            dbContext.SaveChanges();

            var editArtWorkViewModel = new EditArtWorkViewModel()
            {
                Year         = 2016,
                Height       = 130.6,
                Width        = 70.3,
                Price        = 420.50m,
                Availability = false,
                HasFrame     = false,
                Technique    = "Test Technique - Edited",
            };

            var id = dbContext.ArtisticWorks.LastOrDefault().Id;

            service.EditArtWork(id, editArtWorkViewModel);

            var artWork = dbContext
                          .ArtisticWorks
                          .FirstOrDefault(artwork => artwork.Id == id);

            Assert.Equal(editArtWorkViewModel.Year, artWork.Year);
            Assert.Equal(editArtWorkViewModel.Height, artWork.Height);
            Assert.Equal(editArtWorkViewModel.Width, artWork.Width);
            Assert.Equal(editArtWorkViewModel.Price, artWork.Price);
            Assert.Equal(editArtWorkViewModel.Availability, artWork.Availability);
            Assert.Equal(editArtWorkViewModel.HasFrame, artWork.HasFrame);
            Assert.Equal(editArtWorkViewModel.Technique, artWork.Technique);
        }
        public IActionResult EditArtWork(EditArtWorkViewModel viewModel)
        {
            var existingArtWork = this.ArtisticWorkService.GetArtisticWorkById(viewModel.Id);

            if (existingArtWork == null)
            {
                return(RedirectToAction("Categories", "ArtisticWork", new { area = "" }));
            }
            ;

            ArtisticWork ArtWorkUpdate = mapper.Map(viewModel, existingArtWork);

            this.ArtisticWorkService.EditArtWork(ArtWorkUpdate);

            return(RedirectToAction("Categories", "ArtisticWork", new { area = "" }));
        }
        public void EditArtWork(int id, EditArtWorkViewModel editArtWorkViewModel)
        {
            var categoryNew = DbContext.ArtisticWorkCategories.FirstOrDefault(c => c.Id == editArtWorkViewModel.CategoryId);

            var artworkToUpdate = this.DbContext.ArtisticWorks.FirstOrDefault(artwork => artwork.Id == id);

            if (artworkToUpdate != null)
            {
                artworkToUpdate.Year                 = editArtWorkViewModel.Year;
                artworkToUpdate.Height               = editArtWorkViewModel.Height;
                artworkToUpdate.Width                = editArtWorkViewModel.Width;
                artworkToUpdate.Price                = editArtWorkViewModel.Price;
                artworkToUpdate.Availability         = editArtWorkViewModel.Availability;
                artworkToUpdate.HasFrame             = editArtWorkViewModel.HasFrame;
                artworkToUpdate.ArtisticWorkCategory = categoryNew;
                artworkToUpdate.Technique            = editArtWorkViewModel.Technique;
                artworkToUpdate.EditedOn             = DateTime.UtcNow;

                DbContext.SaveChanges();
            }
        }
        public EditArtWorkViewModel GetEditArtWorkViewModel(int id)
        {
            var artWork = GetArtisticWorkById(id);

            if (artWork == null)
            {
                return(null);
            }

            var viewModel = new EditArtWorkViewModel()
            {
                Year               = artWork.Year,
                Height             = artWork.Height,
                Width              = artWork.Width,
                Price              = artWork.Price,
                Availability       = artWork.Availability,
                HasFrame           = artWork.HasFrame,
                Technique          = artWork.Technique,
                ExistingCategories = this.GetArtisticWorkCategories()
            };

            return(viewModel);
        }