public async Task <IActionResult> Edit(int id, [Bind("Id,FullName")] Url url) { if (id != url.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var prevUrl = await _context.Urls.FindAsync(id); _context.Entry(prevUrl).State = EntityState.Detached; url.FullName = UrlHelpers.AppendProtocol(url.FullName); if (prevUrl.FullName != url.FullName) { url.ShortName = UrlHelpers.ShortenUrl(url.FullName); _context.Update(url); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!UrlExists(url.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(url)); }
public void Update(Url url) { _context.Update(url); }