예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(Address.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToPage("./Index"));
        }
예제 #2
0
        public async Task <ActionResult> OnPostClickedAsync(int id)
        {
            Address = _context.Address.ToList();
            string url = "";

            foreach (var address in Address)
            {
                if (address.Id == id)
                {
                    url = address.LongAddress;
                    address.Clicked++;
                    _context.Attach(address).State = EntityState.Modified;
                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
            }
            if (!string.IsNullOrEmpty(url))
            {
                return(Redirect(url));
            }
            else
            {
                return(NotFound());
            }
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var shortURL = CreateShortURL();

            Address.ShortAddress = shortURL;
            _context.Address.Add(Address);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Address = await _context.Address.FindAsync(id);

            if (Address != null)
            {
                _context.Address.Remove(Address);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }