public async Task <IActionResult> Skip(TrainingStepViewModel model) { var currentSpecPlanLine = appContext.TrainingPlanSpecs.Find(model.CurrentSpecPlanId); var currentSpecLine = GetCurrentSpecLine(currentSpecPlanLine, model.HeadTrainingId); var nextSpecPlanLine = GetNextSpecLine <TrainingPlanSpec>(currentSpecPlanLine.Id); if (currentSpecLine == null) { currentSpecLine = new TrainingSpec { HeadId = model.HeadTrainingId, ExId = model.ExerciseId, Set = model.Set, Weight = model.Weight, Amount = 0, Order = model.Order }; appContext.TrainingSpecs.Add(currentSpecLine); UpdateTrainingDuration(model.HeadTrainingId, DateTime.UtcNow); await appContext.SaveChangesAsync(); } if (nextSpecPlanLine == null) { return(RedirectToAction("NextStep", new { currentSpecPlanId = currentSpecPlanLine.Id, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId, isFinishedTraining = true })); } return(RedirectToAction("NextStep", new { currentSpecPlanId = nextSpecPlanLine.Id, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId })); }
public IActionResult NextStep(int currentSpecPlanId = 0, int trainingPlanHeadId = 0, int trainingHeadId = 0, bool isFinishedTraining = false) { if (currentSpecPlanId == 0) { return(RedirectToAction("Finish", new { trainingHeadId })); } var currentSpecPlanLine = appContext.TrainingPlanSpecs.Include(x => x.Exercise).Where(x => x.Id.Equals(currentSpecPlanId)).FirstOrDefault(); if (currentSpecPlanLine != null) { string userId = userManager.GetUserId(HttpContext.User); TrainingSpec currentSpecLine = GetCurrentSpecLine(currentSpecPlanLine, trainingHeadId); TrainingStepViewModel model; if (currentSpecLine == null) { model = new TrainingStepViewModel { HeadTrainingPlanId = trainingPlanHeadId, HeadTrainingId = trainingHeadId, CurrentSpecPlanId = currentSpecPlanId, CurrentSpecId = 0, Set = currentSpecPlanLine.Set, Weight = currentSpecPlanLine.Weight, ExerciseId = currentSpecPlanLine.ExId, Exercise = currentSpecPlanLine.Exercise.Name, ExerciseDescription = currentSpecPlanLine.Exercise.Description, Amount = currentSpecPlanLine.Amount, Order = currentSpecPlanLine.Order, IsFinishedTraining = isFinishedTraining }; } else { model = new TrainingStepViewModel { HeadTrainingPlanId = trainingPlanHeadId, HeadTrainingId = trainingHeadId, CurrentSpecPlanId = currentSpecPlanId, CurrentSpecId = currentSpecLine.Id, Set = currentSpecLine.Set, Weight = currentSpecLine.Weight, ExerciseId = currentSpecLine.ExId, Exercise = currentSpecLine.Exercise.Name, ExerciseDescription = currentSpecLine.Exercise.Description, Amount = currentSpecLine.Amount, Order = currentSpecLine.Order, IsFinishedTraining = isFinishedTraining }; } return(View(model)); } ModelState.AddModelError("Trainig specification line not found", "Trainig specification line not found"); return(View("Error")); }
public async Task <IActionResult> NextStep(TrainingStepViewModel model) { string userId = userManager.GetUserId(HttpContext.User); var currentSpecPlanId = model.CurrentSpecPlanId; var currentSpecPlanLine = appContext.TrainingPlanSpecs.Find(currentSpecPlanId); var currentSpecId = GetCurrentSpecLine(currentSpecPlanLine, model.HeadTrainingId) != null?GetCurrentSpecLine(currentSpecPlanLine, model.HeadTrainingId).Id : 0; if (currentSpecPlanId != 0) { if (model.CurrentSpecId != 0) // такая запись в TrainingSpec есть - модифицируем { var currentSpecLine = appContext.TrainingSpecs.Find(model.CurrentSpecId); if (currentSpecLine == null) { ModelState.AddModelError("IncorrectSpecId", $"Record {nameof(model.CurrentSpecId)} with not found in DataBase"); RedirectToAction("NextStep", new { currentSpecPlanId = model.CurrentSpecPlanId, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId }); } else { currentSpecLine.Weight = model.Weight; currentSpecLine.Amount = model.Amount; appContext.TrainingSpecs.Update(currentSpecLine); await appContext.SaveChangesAsync(); } } else // новая запись в TrainingSpec - добавляем { var currentSpecLine = new TrainingSpec { HeadId = model.HeadTrainingId, ExId = model.ExerciseId, Set = model.Set, Weight = model.Weight, Amount = model.Amount, Order = appContext.TrainingPlanSpecs.Find(currentSpecPlanId).Order }; appContext.TrainingSpecs.Add(currentSpecLine); await appContext.SaveChangesAsync(); } //Найти следующую запись в тренировочной программе. var nextSpecPlanLine = GetNextSpecLine <TrainingPlanSpec>(model.CurrentSpecPlanId); if (nextSpecPlanLine == null) { return(RedirectToAction("NextStep", new { currentSpecPlanId = model.CurrentSpecPlanId, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId, isFinishedTraining = true })); } else { return(RedirectToAction("NextStep", new { currentSpecPlanId = nextSpecPlanLine.Id, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId })); } } else { return(View("Error")); } }
public IActionResult PreviousStep(TrainingStepViewModel model) { var previousSpecPlanLine = GetPreviousSpecLine <TrainingPlanSpec>(model.CurrentSpecPlanId); if (previousSpecPlanLine != null) { return(RedirectToAction("NextStep", new { currentSpecPlanId = previousSpecPlanLine.Id, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId })); } else { return(RedirectToAction("NextStep", new { currentSpecPlanId = model.CurrentSpecPlanId, trainingPlanHeadId = model.HeadTrainingPlanId, trainingHeadId = model.HeadTrainingId })); } }