//TRAINING
        //EDIT Training
        public async Task <IActionResult> EditTraining(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var training = await _context.Trainings.FindAsync(id);

            var gyms    = _context.Gyms.ToList();
            var coaches = _context.Users.Where(u => u.RoleId == 2).ToList();

            if (training == null)
            {
                return(NotFound());
            }
            var editTraining = new EditTraining();

            editTraining.Name           = training.Name;
            editTraining.TimeOfStarting = training.TimeOfStarting;
            editTraining.Time           = training.TimeOfStarting;


            editTraining.TrainingDuration = training.TrainingDuration;
            editTraining.TrainingId       = training.TrainingId;

            editTraining.GymId   = training.GymId;
            editTraining.Gyms    = new SelectList(gyms, "GymId", "Name");
            editTraining.CoachId = training.CoachId;
            editTraining.Coaches = new SelectList(coaches, "UserId", "LastName");
            return(View(editTraining));
        }
        public async Task <IActionResult> AddTraining()
        {
            var gyms    = _context.Gyms.ToList();
            var coaches = _context.Users.Where(u => u.RoleId == 2).ToList();

            var editTraining = new EditTraining();

            editTraining.Gyms    = new SelectList(gyms, "GymId", "Name");
            editTraining.Coaches = new SelectList(coaches, "UserId", "LastName");
            return(View(editTraining));
        }
        public async Task <IActionResult> AddTraining(EditTraining edtraining)
        {
            if (ModelState.IsValid)
            {
                Training trainingCh = await _context.Trainings.FirstOrDefaultAsync(u => u.Name == edtraining.Name);

                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;
                        training.CoachId = edtraining.CoachId;
                        _context.Trainings.Add(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(View());
                }
            }
            return(RedirectToAction(nameof(EditDB)));
        }