예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] VehicleType vehicleType)
        {
            if (id != vehicleType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleTypeExists(vehicleType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleType));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RegNum,Color,CheckInTime,MemberId,VehicleTypeId")] ParkedVehicle parkedVehicle)
        {
            if (id != parkedVehicle.Id)
            {
                return(NotFound());
            }

            // Check RegNum
            if (_context.ParkedVehicle.AsNoTracking().Any(p => p.Id == parkedVehicle.Id) &&
                _context.ParkedVehicle.AsNoTracking().First(p => p.Id == parkedVehicle.Id).RegNum != parkedVehicle.RegNum &&
                _context.ParkedVehicle.AsNoTracking().Any(m => m.RegNum == parkedVehicle.RegNum))
            {
                ModelState.AddModelError("RegNum", $"\'{parkedVehicle.RegNum}\' already exists!");
            }

            //if (await _context.ParkedVehicle.AnyAsync(p => p.RegNum == parkedVehicle.RegNum))
            //{
            //    ModelState.AddModelError("RegNum", $"\'{parkedVehicle.RegNum}\' already exists");
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(parkedVehicle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ParkedVehicleExists(parkedVehicle.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                TempData["Message"] = $"Vehicle \'{parkedVehicle.RegNum}\' is updated";

                return(RedirectToAction(nameof(Index)));
            }
            return(View(parkedVehicle));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserName,Email")] Member member)
        {
            if (id != member.Id)
            {
                return(NotFound());
            }

            // Check UserName
            if (_context.Member.AsNoTracking().First(m => m.Id == member.Id).UserName != member.UserName &&
                _context.Member.AsNoTracking().Any(m => m.UserName == member.UserName))
            {
                ModelState.AddModelError("UserName", $"\'{member.UserName}\' already exists!");
            }

            // Check Email
            if (_context.Member.AsNoTracking().First(m => m.Id == member.Id).Email != member.Email &&
                _context.Member.AsNoTracking().Any(m => m.Email == member.Email))
            {
                ModelState.AddModelError("Email", $"\'{member.Email}\' already exists!");
            }

            //// Check UserName
            //if (await UserNameChangedAsync(member) && await UserNameExistsAsync(member))
            //{
            //    ModelState.AddModelError("UserName", $"\'{member.UserName}\' already exists!");
            //}

            //// Check Email
            //if (await EmailChangedAsync(member) && await EmailExistsAsync(member))
            //{
            //    ModelState.AddModelError("Email", $"\'{member.Email}\' already exists!");
            //}

            //if (await UserNameChangedAsync(member) || await EmailChangedAsync(member))
            //{
            //    await CheckUnique(member);
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(member);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemberExists(member.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                TempData["Message"] = $"Member \'{member.UserName}\' is updated";

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }