コード例 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GenreExists(Genre.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!_context.Books.Any(x => x.Id == BookCopy.BookId))
            {
                return(Page());
            }

            var copy = _context.BookCopies.FirstOrDefault(x => x.Id == BookCopy.Id);

            if (copy is null)
            {
                return(NotFound());
            }

            if (!BookStates.StateExist(BookCopy.State))
            {
                return(Page());
            }

            copy.State    = BookCopy.State;
            copy.Quantity = BookCopy.Quantity;

            try
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("Edit", new { id = BookCopy.BookId }));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }
        }