コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,TourName,Date")] Tours tours)
        {
            if (id != tours.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tours);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ToursExists(tours.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tours));
        }
コード例 #2
0
ファイル: UsersController.cs プロジェクト: katebass/itcraft
        public async Task <IActionResult> Edit(int id, [Bind("ID,Email,Password")] Users users)
        {
            user = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
            var  userq        = _context.Users.Where(u => u.Email == user.Value).AsNoTracking().FirstOrDefault();
            bool AlreadyExist = _context.Users.Any(u => u.Email == users.Email);

            if (AlreadyExist)
            {
                ViewBag.AlreadyExist = true;

                return(View("~/Views/Users/Edit.cshtml", users));
            }
            if (users.ID != id || (user != null && userq.ID != users.ID))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    users.Password = getHash(users.Password);
                    _context.Update(users);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsersExists(users.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Logout", "Login"));
            }
            return(View(users));
        }