public async Task <IActionResult> EditUser(int id, /*[Bind("ID,Title,ReleaseDate,Genre,Price")] */ User user)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                User userCh = await _context.Users.FirstOrDefaultAsync(u => u.Login == user.Login& u.UserId != user.UserId);

                if (userCh == null)
                {
                    try
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        User userCheck = await _context.Users.FirstOrDefaultAsync(u => u.UserId == user.UserId);

                        if (userCheck == null)

                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                    return(await EditUser(id));
                }
            }
            return(RedirectToAction(nameof(EditDB)));
        }
Example #2
0
        public async Task <IActionResult> EditTraining(int id, /*[Bind("ID,Title,ReleaseDate,Genre,Price")] */ ControleTraining edtraining)
        {
            if (id != edtraining.TrainingId)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                Training trainingCh = await _context.Trainings.FirstOrDefaultAsync(u => u.Name == edtraining.Name& u.TrainingId != edtraining.TrainingId);

                if (trainingCh == null)
                {
                    try
                    {
                        Training training = new Training();
                        DateTime datetime = new DateTime(edtraining.TimeOfStarting.Year, edtraining.TimeOfStarting.Month, edtraining.TimeOfStarting.Day,
                                                         edtraining.Time.Hour, edtraining.Time.Minute, edtraining.Time.Second);
                        training.TimeOfStarting   = datetime;
                        training.Name             = edtraining.Name;
                        training.TrainingDuration = edtraining.TrainingDuration;
                        training.TrainingId       = edtraining.TrainingId;
                        training.GymId            = edtraining.GymId;
                        _context.Update(training);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        Training trainingCheck = await _context.Trainings.FirstOrDefaultAsync(u => u.TrainingId == edtraining.TrainingId);

                        if (trainingCheck == null)

                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                    return(await EditTraining(id));
                }
            }
            return(RedirectToAction(nameof(ControleTraining)));
        }