private async Task <int> CreateTrainigPlanHead(DayOfWeek dayTraining, string trainingName)
        {
            string           userId      = userManager.GetUserId(HttpContext.User);
            byte             trainingDay = trainigDayConverter.DaysToByte(dayTraining);
            TrainingPlanHead planHead    = new TrainingPlanHead
            {
                Date         = DateTime.UtcNow,
                Name         = trainingName,
                TrainingDays = trainingDay,
                UserId       = userId
            };
            await appContext.TrainingPlanHeads.AddAsync(planHead);

            await appContext.SaveChangesAsync();

            return(appContext.TrainingPlanHeads.Where(x => x.UserId.Equals(userId) && x.TrainingDays.Equals(trainingDay)).FirstOrDefault().Id);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Start(int currentHeadPlanId)
        {
            string userId = userManager.GetUserId(HttpContext.User);

            if (currentHeadPlanId != 0)
            {
                TrainingPlanHead trainingPlanHead = appContext.TrainingPlanHeads.Find(currentHeadPlanId);
                if (trainingPlanHead != null)
                {
                    TrainingHead trainingHead = new TrainingHead
                    {
                        UserId             = userId,
                        Date               = DateTime.UtcNow,
                        TrainingPlanHeadId = currentHeadPlanId,
                        Name               = trainingPlanHead.Name,
                        Number             = GetNumberDocument <TrainingHead>(stepTrainingHeadDocument, userId),
                    };
                    await appContext.TrainingHeads.AddAsync(trainingHead);

                    await appContext.SaveChangesAsync();

                    int trainingHeadId = trainingHead.Id;

                    int?currentSpecPlanId = appContext.TrainingPlanSpecs.Where(x => x.HeadId.Equals(currentHeadPlanId)).OrderBy(x => x.Order).FirstOrDefault()?.Id;
                    currentSpecPlanId = currentSpecPlanId ?? 0;
                    return(RedirectToAction("NextStep", new { currentSpecPlanId, trainingPlanHeadId = currentHeadPlanId, trainingHeadId }));
                }
                else
                {
                    ModelState.AddModelError(sharedErrorMessageLocalizer["ProgramPlanNotFoundShort"], sharedErrorMessageLocalizer["ProgramPlanNotFoundLong"]);
                }
            }
            else
            {
                ModelState.AddModelError(nameof(currentHeadPlanId) + "can not be null", nameof(currentHeadPlanId) + "can not be null");
            }
            return(View());
        }