コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,ProductName,ProductPrice,ProductDescription")] Product product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,Username,Password,DisplayName")] User user)
        {
            string status = HttpContext.Session.GetString("sessionStatus");

            if (status == "Admin")
            {
                if (id != user.UserId)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!UserExists(user.UserId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(user));
            }
            return(RedirectToAction("Index", "Home"));
        }