Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BugExists(Bug.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.User
                       .AsNoTracking()
                       .FirstOrDefaultAsync(m => m.ID == id);

            if (user == null)
            {
                return(NotFound());
            }

            try
            {
                _context.User.Remove(user);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Bug.Add(Bug);
            await _context.SaveChangesAsync();

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

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

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

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var studentToUpdate = await _context.User.FindAsync(id);

            if (await TryUpdateModelAsync <User>(
                    studentToUpdate,
                    "user",
                    u => u.FirstName, u => u.LastName, u => u.Email))
            {
                await _context.SaveChangesAsync();

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

            return(Page());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyUser = new User();

            if (await TryUpdateModelAsync <User>(
                    emptyUser,
                    "user", // Prefix for form value.
                    u => u.FirstName, u => u.LastName, u => u.Email))
            {
                _context.User.Add(emptyUser);
                await _context.SaveChangesAsync();

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