public async Task <Url> GetAsync(int urlId) { var url = await _context.Urls.FindAsync(urlId); if (url != null) { await _context.Entry(url).Collection(x => x.UrlRequests).LoadAsync(); await _context.Entry(url).Reference(x => x.UrlDetails).LoadAsync(); } return(url); }
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)); }