public IActionResult Get(TrainingWeekKey trainingWeekKey, Boolean manageDay = false) { try { if (trainingWeekKey == null) { return(BadRequest()); } var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = manageDay }; if (manageDay) { trainingWeekScenario.TrainingDayScenario = new TrainingDayScenario() { ManageExercise = true }; } var trainingWeek = _trainingWeeksService.GetTrainingWeek(trainingWeekKey, trainingWeekScenario); return(new OkObjectResult(trainingWeek)); } catch (Exception exception) { return(BadRequest(new WebApiException("Error", exception))); } }
public IActionResult Create([FromBody] TrainingDayViewModel viewModel) { try { if (ModelState.IsValid) { if (string.IsNullOrWhiteSpace(viewModel.UserId) || viewModel.Year == 0 || viewModel.WeekOfYear == 0 || viewModel.DayOfWeek < 0 || viewModel.DayOfWeek > 6 || SessionUserId != viewModel.UserId) { return(BadRequest()); } //Verify trainingWeek exist var trainingWeekKey = new TrainingWeekKey() { UserId = viewModel.UserId, Year = viewModel.Year, WeekOfYear = viewModel.WeekOfYear }; var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = false }; var trainingWeek = _trainingWeeksService.GetTrainingWeek(trainingWeekKey, trainingWeekScenario); if (trainingWeek == null) { return(BadRequest(new WebApiException(string.Format(Translation.P0_NOT_EXIST, Translation.TRAINING_WEEK)))); } //Verify valid week of year if (viewModel.WeekOfYear > 0 && viewModel.WeekOfYear <= 52) { var trainingDay = ControllerUtils.TransformViewModelToTrainingDay(viewModel); trainingDay = _trainingDaysService.CreateTrainingDay(trainingDay); if (trainingDay == null) { return(BadRequest(new WebApiException(string.Format(Translation.IMPOSSIBLE_TO_CREATE_P0, Translation.TRAINING_DAY)))); } else { return(new OkObjectResult(trainingDay)); } } else { return(BadRequest()); } } else { return(BadRequest(new WebApiException(ControllerUtils.GetModelStateError(ModelState)))); } } catch (Exception exception) { return(BadRequest(new WebApiException("Error", exception))); } }
// // GET: /Report/TrainingDayReport/Index public IActionResult Index(string userId, int year, int weekOfYear, int dayOfWeek, int?trainingDayId, bool displayImages, string userIdViewer) { var userInfo = _userInfosService.GetUserInfo(new UserInfoKey() { UserId = userId }); if (userInfo == null) { userInfo = new UserInfo(); } var trainingWeekKey = new TrainingWeekKey() { UserId = userId, Year = year, WeekOfYear = weekOfYear }; var trainingWeekScenario = new TrainingWeekScenario() { ManageTrainingDay = true, TrainingDayScenario = new TrainingDayScenario() { ManageExercise = true } }; var trainingWeek = _trainingWeeksService.GetTrainingWeek(trainingWeekKey, trainingWeekScenario); if (trainingWeek == null) { trainingWeek = new TrainingWeek(); } //Unit viewer convertion if (string.IsNullOrEmpty(userIdViewer)) { userIdViewer = SessionUserId; } var viewerUnit = AppUtils.GetUserUnit(_userInfosService, userIdViewer); var userUnit = AppUtils.GetUserUnit(_userInfosService, userId); trainingWeek.UserHeight = Utils.TransformLengthToUnitSytem(userUnit, viewerUnit, trainingWeek.UserHeight); trainingWeek.UserWeight = Utils.TransformWeightToUnitSytem(userUnit, viewerUnit, trainingWeek.UserWeight); var trainingWeekViewModel = TrainingViewModelTransformer.TrainingWeekToViewModel(trainingWeek, _usersService); List <TrainingDayViewModel> trainingDayViewModels = null; List <TrainingExerciseViewModel> trainingExerciseViewModels = null; if (trainingWeek != null && trainingWeek.TrainingDays != null && trainingWeek.TrainingDays.Count > 0) { trainingDayViewModels = new List <TrainingDayViewModel>(); foreach (var trainingDay in trainingWeek.TrainingDays) { if (!trainingDayId.HasValue || trainingDay.TrainingDayId == trainingDayId) { if (trainingDay.DayOfWeek == dayOfWeek) { // Get only current trainingDayViewModels.Add(TrainingViewModelTransformer.TrainingDayToViewModel(trainingDay, userInfo)); var trainingExercises = FindTrainingExercise(trainingDay); if (trainingExercises != null) { foreach (var trainingExercise in trainingExercises) { //Convert user Unit to viewer unit if (trainingExercise.TrainingExerciseSets != null) { foreach (var set in trainingExercise.TrainingExerciseSets) { set.Weight = Utils.TransformWeightToUnitSytem(userUnit, viewerUnit, set.Weight); } } if (trainingExerciseViewModels == null) { trainingExerciseViewModels = new List <TrainingExerciseViewModel>(); } trainingExerciseViewModels.Add(TrainingViewModelTransformer.TrainingExerciseToViewModel(trainingExercise, _bodyExercisesService)); } } } } } } ViewBag.DayOfWeek = dayOfWeek; ViewBag.displayImages = displayImages; ViewBag.ViewerUnit = viewerUnit; return(View(new Tuple <TrainingWeekViewModel, List <TrainingDayViewModel>, List <TrainingExerciseViewModel> >(trainingWeekViewModel, trainingDayViewModels, trainingExerciseViewModels))); }