public IActionResult ExerciseStat() { var userId = userManager.GetUserId(HttpContext.User); var dayFrom = DateTime.Now.Date; var dayTo = dayFrom.AddHours(23).AddMinutes(59); var userExercises = appContext.TrainingHeads.Where(x => x.UserId.Equals(userManager.GetUserId(HttpContext.User))) .Join(appContext.TrainingSpecs, x => x.Id, y => y.HeadId, (x, y) => new { y.ExId }) .Join(appContext.Exercises, x => x.ExId, y => y.Id, (x, y) => new { ExerciseName = y.Name, ExerciseId = y.Id }) .OrderBy(x => x.ExerciseName).Distinct().ToList(); var model = new ExerciseStatisticsChartViewModel { UserId = userId, DayFrom = dayFrom, DayTo = dayTo }; if (userExercises != null) { int exerciseId = userExercises.FirstOrDefault().ExerciseId; model.UserId = userId; model.DayFrom = dayFrom; model.DayTo = dayTo; model.Exercises = new List <SelectListItem>(); foreach (var item in userExercises) { model.Exercises.Add(new SelectListItem { Text = item.ExerciseName, Value = item.ExerciseId.ToString(), Selected = false }); } return(View(model)); } else { ModelState.AddModelError(localizerErrorMessages["UserHasNotFinishedExercisesShort"], localizerErrorMessages["UserHasNotFinishedExercisesLong"]); } return(View("ExerciseStat", model)); }
public IActionResult ExerciseStat(ExerciseStatisticsChartViewModel model) { if (ModelState.IsValid) { List <TrainingHead> userHeads = GetUserHead(model); List <TrainingSpec> userSpec = GetUserSpec(userHeads); var userExercises = appContext.Exercises.OrderBy(x => x.Name); var statisticsModel = new StatisticsModel(); var userRows = statisticsModel.GetExerciseData(new UserGeneralData { UserId = model.UserId, DateFrom = model.DayFrom, DateTo = model.DayTo, UserHead = userHeads, UserSpecs = userSpec, UserExercises = userExercises, ExerciseId = model.Exercise }); var userRowsInGradualNumberDateLabel = RowsXAxisConverter.ToSerialNumbersWithDateLabel(userRows); ColumnChart <int, float> columnChart = new ColumnChart <int, float>(localizerStatisticController["TittleColumnChart"], userRowsInGradualNumberDateLabel, localizerShared); var jsonData = chartProvider.GetColumnChart(columnChart); var exercises = userExercises.Select((x) => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); var viewModel = new ExerciseStatisticsChartViewModel() { UserId = model.UserId, DayFrom = model.DayFrom, DayTo = model.DayTo, Exercise = model.Exercise, Exercises = exercises, ChartDataJSON = jsonData }; return(View(viewModel)); } return(RedirectToAction("ExerciseStat")); }