public async Task <IActionResult> Edit(Genre genre) { bool duplicate = await _context.Genres.AnyAsync(d => d.Name.Equals(genre.Name)); if (duplicate) { ModelState.AddModelError("FirstName", Resourses.ERROR_GenreExists); } if (ModelState.IsValid) { _context.Update(genre); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Edit(Developer developer) { bool duplicate = await _context.Developers.AnyAsync(d => d.Name.Equals(developer.Name) && d.CountryId == developer.CountryId && d.Id != developer.Id); if (duplicate) { ModelState.AddModelError("Name", Resourses.ERROR_DeveloperExists); } if (ModelState.IsValid) { _context.Update(developer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.CountryList = new SelectList(_context.Countries.ToList(), "Id", "Name"); return(View(developer)); }
public async Task <IActionResult> Edit(Game game, int devId) { ViewBag.DevId = devId; bool duplicate = _context.Games.Any(s => s.Id != game.Id && s.DeveloperId == game.DeveloperId && s.Name.Equals(game.Name)); if (duplicate) { ModelState.AddModelError("Name", Resourses.ERROR_GameExists); } if (ModelState.IsValid) { _context.Update(game); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = devId })); } ViewBag.DeveloperList = new SelectList(_context.Developers, "Id", "Name", game.DeveloperId); ViewBag.GenreList = new SelectList(_context.Genres, "Id", "Name", game.GenreId); ViewBag.StatusList = new SelectList(_context.Statuses, "Id", "Name", game.StatusId); return(View(game)); }