예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LongUrl,ShortUrl,CreationDate,Counter")] Url url)
        {
            if (id != url.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(url);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UrlExists(url.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(url));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,longUrl,key")] ShortUrl shortUrl)
        {
            if (!loggedIn())
            {
                return(View("Login"));
            }

            if (id != shortUrl.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shortUrl);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShortUrlExists(shortUrl.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shortUrl));
        }