public IActionResult AddExFromTrainProgram(DayOfWeek dayTraining, int headId)
        {
            var userId = userManager.GetUserId(HttpContext.User);
            var model  = new AddExercisesFromTrainingProgramViewModel
            {
                DayTraining      = dayTraining,
                HeadId           = headId,
                TrainingPrograms = appContext.TrainingProgramHeads.Where(x => x.UserId.Equals(userId)).Include(x => x.Category).ToList()
            };

            return(View(model));
        }
        public async Task <IActionResult> AddExFromTrainProgram(AddExercisesFromTrainingProgramViewModel viewModel)
        {
            if (viewModel != null)
            {
                var trainingProgramSpecs = appContext.TrainingProgramSpecs.Where(x => x.HeadId.Equals(viewModel.ProgramHeadId)).ToList();
                if (trainingProgramSpecs.Count != 0)
                {
                    var  userId = userManager.GetUserId(HttpContext.User);
                    int  headId = viewModel.HeadId;
                    byte SetNum = 1;
                    List <TrainingPlanSpec> lines;

                    #region Find last order number in current training plan
                    if (headId == 0)
                    {
                        headId = await CreateTrainigPlanHead(viewModel.DayTraining, CreateTrainingPlanName(viewModel.DayTraining));

                        lines = new List <TrainingPlanSpec>();
                    }
                    else
                    {
                        lines = appContext.TrainingPlanSpecs.Where(x => x.HeadId.Equals(viewModel.HeadId)).ToList();
                        if (lines.Count != 0)
                        {
                            SetNum = Convert.ToByte(lines.Max(x => x.Set) + 1);
                        }
                    }
                    documentSpecHandler.FillDocument(lines);
                    int lastOrderNum = documentSpecHandler.GetLastOrder();
                    int step         = documentSpecHandler.GetOrderStep();
                    #endregion
                    lines = new List <TrainingPlanSpec>();
                    foreach (var trainingProgramLine in trainingProgramSpecs)
                    {
                        lines.Add(new TrainingPlanSpec
                        {
                            HeadId = headId,
                            Set    = SetNum,
                            ExId   = trainingProgramLine.ExId,
                            Weight = trainingProgramLine.Weight,
                            Amount = trainingProgramLine.Amount,
                            Order  = lastOrderNum += step
                        });
                    }
                    await appContext.TrainingPlanSpecs.AddRangeAsync(lines);

                    await appContext.SaveChangesAsync();
                }
            }
            TempData["dayTraining"] = viewModel.DayTraining;
            return(RedirectToAction("Show"));
        }