Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, EditGenreViewModel 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.Genres.UpdateAsync(vm.Dto);

                await unitOfWork.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while deleting song.");
            }
            // ToDo: Implement error page
            return(View("ErrorSaving"));
        }
Exemplo n.º 2
0
        public IActionResult Edit(EditGenreViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _genreService.Edit(new GenreDTO()
                    {
                        Id = model.Id, Name = model.Name
                    });

                    _loggerService.LogInformation(CONTROLLER_NAME + LoggerConstants.ACTION_EDIT, LoggerConstants.TYPE_POST, $"edit genre id: {model.Id} successful", GetCurrentUserId());

                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    _loggerService.LogWarning(CONTROLLER_NAME + LoggerConstants.ACTION_EDIT, LoggerConstants.TYPE_POST, $"edit genre id: {model.Id} error: {ex.Message}", GetCurrentUserId());

                    ModelState.AddModelError(ex.Property, ex.Message);
                }
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(EditGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var genre = await _context.Genres
                            .SingleOrDefaultAsync(m => m.GenreId == model.GenreId);

                genre.Name = model.Name;
                _context.Update(genre);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GenreExists(model.GenreId))
                {
                    return(View("NotFound"));
                }

                throw;
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 4
0
        public IActionResult Edit(EditGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            this._genreService.Edit(model.Id, model.Name);

            return(this.RedirectToAction(nameof(All)));
        }
Exemplo n.º 5
0
        public IActionResult Edit(int id)
        {
            Genre supplier = this._genreService.GetGenreById(id);

            var editViewModel = new EditGenreViewModel()
            {
                Id   = supplier.Id,
                Name = supplier.Name,
            };

            return(this.View(editViewModel));
        }
Exemplo n.º 6
0
        public IActionResult Edit(EditGenreViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Genre editGenre = _context.Genres.SingleOrDefault(g => g.ID == vm.ID);
                editGenre.Name = vm.Name;
                _context.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public ActionResult Edit(EditGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Edit(model.Id));
            }

            var genre = mapper.Map <EditGenreViewModel, Genre>(model);

            genreService.UpdateGenre(genre);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 8
0
        public ViewResult Edit(Guid id)
        {
            var genre = _databaseContext.Genre
                        .FirstOrDefault(p => p.GenreID == id);

            ViewData["Success"] = TempData["Success"];

            var model = new EditGenreViewModel
            {
                Genre = genre
            };

            return(View(model));
        }
Exemplo n.º 9
0
        public IActionResult Edit(int id)
        {
            Genre editGenre = _context.Genres.SingleOrDefault(g => g.ID == id);

            if (editGenre != null)
            {
                EditGenreViewModel vm = new EditGenreViewModel()
                {
                    ID = id, Name = editGenre.Name
                };
                return(View(vm));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public ActionResult Edit(Guid id)
        {
            var response = _genreService.GetGenre(new GetGenreRequest {
                Id = id
            });

            var model = new EditGenreViewModel
            {
                Id          = response.Genre.Id,
                Name        = response.Genre.Name,
                Description = response.Genre.Description
            };

            return(View(model));
        }
Exemplo n.º 11
0
        public IActionResult Update(Guid id, EditGenreViewModel model)
        {
            if (ModelState.IsValid)
            {
                var genre = _databaseContext.Genre

                            .FirstOrDefault(m => m.GenreID == id);

                genre.GenreName = model.Genre.GenreName;

                TempData["Success"] = true;


                _databaseContext.SaveChanges();
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 12
0
        public ActionResult Edit(EditGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var request = new EditGenreRequest
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description
            };

            _genreService.EditGenre(request);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Edit(int id)
        {
            try
            {
                var genre = await unitOfWork.Genres.GetAsync(id);

                var dto = mapper.Map <GenreForUpdatingDto>(genre);
                var vm  = new EditGenreViewModel
                {
                    Dto = dto
                };
                return(View(vm));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred while getting albums.");
            }
            // ToDo: Implement error page
            return(View("Error"));
        }
Exemplo n.º 14
0
        public void Update(Guid genreId, EditGenreViewModel genre)
        {
            try
            {
                var result = FilmHausDbContext.Genres.Find(genreId);

                if (result == null)
                {
                    throw new ArgumentNullException();
                }

                result.Name = genre.Name;

                FilmHausDbContext.Entry(result).State = EntityState.Modified;
                FilmHausDbContext.SaveChanges();
            }
            catch (InvalidOperationException ex)
            {
                throw ex;
            }
        }