private void TransformMetricUnitToUserUnit(TUnitType userUnit, TrainingExerciseSet trainingExerciseSet) { if (trainingExerciseSet != null) { trainingExerciseSet.Weight = Utils.TransformWeightToUnitSytem(TUnitType.Metric, userUnit, trainingExerciseSet.Weight); } }
/// <summary> /// Update data in database /// </summary> /// <param name="trainingDay">data</param> /// <returns>updated data</returns> public TrainingDay Update(TrainingDay trainingDay, TUnitType userUnit) { if (trainingDay == null || string.IsNullOrWhiteSpace(trainingDay.UserId) || trainingDay.Year == 0 || trainingDay.WeekOfYear == 0 || trainingDay.DayOfWeek < 0 || trainingDay.DayOfWeek > 6 || trainingDay.TrainingDayId == 0) { return(null); } var trainingJournalRow = _dbContext.TrainingDay.Where(t => t.UserId == trainingDay.UserId && t.Year == trainingDay.Year && t.WeekOfYear == trainingDay.WeekOfYear && t.DayOfWeek == trainingDay.DayOfWeek && t.TrainingDayId == trainingDay.TrainingDayId).FirstOrDefault(); if (trainingJournalRow == null) { // No data in database return(Create(trainingDay, userUnit)); } else { //Modify Data in database TrainingDayTransformer.ToRow(trainingDay, trainingJournalRow); _dbContext.SaveChanges(); return(TrainingDayTransformer.ToBean(trainingJournalRow, userUnit)); } }
private TUnitType GetExerciseUnit() { TUnitType unit = TUnitType.Metric; if (_trainingExercise != null) { var trainingDayKey = new TrainingDayKey() { UserId = _trainingExercise.UserId, Year = _trainingExercise.Year, WeekOfYear = _trainingExercise.WeekOfYear, DayOfWeek = _trainingExercise.DayOfWeek, TrainingDayId = _trainingExercise.TrainingDayId }; var trainingDayScenario = new TrainingDayScenario() { ManageExercise = false }; var trainingDay = _trainingDayService.GetTrainingDay(trainingDayKey, trainingDayScenario); if (trainingDay != null) { unit = trainingDay.Unit; } } return(unit); }
internal List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario) { var trainingDays = _trainingDayModule.Find(userUnit, trainingDayCriteria); if (trainingDayScenario != null && trainingDayScenario.ManageExercise && trainingDays != null) { foreach (var trainingDay in trainingDays) { CompleteTrainingDayWithExercise(trainingDay); } } return(trainingDays); }
public void ChangeUnitForTrainingExercises(TrainingDay trainingDay, TUnitType oldUnit) { if (trainingDay != null && trainingDay.Unit != oldUnit && trainingDay.TrainingExercises != null) { foreach (var trainingExercise in trainingDay.TrainingExercises) { if (trainingExercise.TrainingExerciseSets != null) { foreach (var set in trainingExercise.TrainingExerciseSets) { set.Weight = Utils.TransformWeightToUnitSytem(oldUnit, trainingDay.Unit, set.Weight); } } } } }
/// <summary> /// Create data in database /// </summary> /// <param name="trainingDay">Data</param> /// <returns>insert data</returns> public TrainingDay Create(TrainingDay trainingDay, TUnitType userUnit) { if (trainingDay == null || string.IsNullOrWhiteSpace(trainingDay.UserId) || trainingDay.Year == 0 || trainingDay.WeekOfYear == 0 || trainingDay.DayOfWeek < 0 || trainingDay.DayOfWeek > 6 || trainingDay.TrainingDayId == 0) { return(null); } var row = new TrainingDayRow(); TrainingDayTransformer.ToRow(trainingDay, row); _dbContext.TrainingDay.Add(row); _dbContext.SaveChanges(); return(TrainingDayTransformer.ToBean(row, userUnit)); }
public static TUnitType GetUserUnit(IUserInfosService userInfosService, string userId) { TUnitType result = TUnitType.Imperial; if (userId != null && userInfosService != null) { var userInfo = userInfosService.GetUserInfo(new UserInfoKey() { UserId = userId }); if (userInfo != null) { result = userInfo.Unit; } } return(result); }
public static double TransformLengthToUnitSytem(TUnitType fromUnitType, TUnitType toUnitType, double length) { if (fromUnitType == toUnitType) { return(length); } double result = length; if (fromUnitType == TUnitType.Imperial && toUnitType == TUnitType.Metric) { //Convert Inch to cm (1 inch = 2.54 cm) result *= 2.54d; } else if (fromUnitType == TUnitType.Metric && toUnitType == TUnitType.Imperial) { //Convert cm to Inch (1 cm = 0.393701 inch) result *= 0.393701d; } return(result); }
internal List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario) { var trainingDays = _trainingDayModule.Find(userUnit, trainingDayCriteria); if (trainingDayScenario != null && trainingDayScenario.ManageExercise && trainingDays != null && trainingDays.Count > 0) { var criteriaList = new CriteriaList <TrainingExerciseCriteria>(); string userId = null; foreach (var trainingDay in trainingDays) { criteriaList.Add(CreateTrainingExerciseCriteria(trainingDay)); if (userId == null) { userId = trainingDay.UserId; } } var trainingExerciseList = _trainingExercisesService.FindTrainingExercise(criteriaList); if (trainingExerciseList != null) { foreach (var trainingDay in trainingDays) { foreach (var trainingExercise in trainingExerciseList) { if (trainingExercise != null && (trainingDay.UserId != null && trainingDay.UserId == trainingExercise.UserId) && (trainingDay.Year == trainingExercise.Year) && (trainingDay.WeekOfYear == trainingExercise.WeekOfYear) && (trainingDay.DayOfWeek == trainingExercise.DayOfWeek) && (trainingDay.TrainingDayId == trainingExercise.TrainingDayId)) { if (trainingDay.TrainingExercises == null) { trainingDay.TrainingExercises = new List <TrainingExercise>(); } trainingDay.TrainingExercises.Add(trainingExercise); } } } } } return(trainingDays); }
public static double TransformWeightToUnitSytem(TUnitType fromUnitType, TUnitType toUnitType, double weight) { if (fromUnitType == toUnitType) { return(weight); } double result = weight; if (fromUnitType == TUnitType.Imperial && toUnitType == TUnitType.Metric) { //Convert Pound to kg (1 Pound = 0.453592 kg) result *= 0.453592d; } else if (fromUnitType == TUnitType.Metric && toUnitType == TUnitType.Imperial) { //Convert Kg to Pound (1 kg = 2.20462 Pound) result *= 2.20462; } return(result); }
internal static TrainingDay ToBean(TrainingDayRow row, TUnitType userUnit) { if (row == null) { return(null); } var bean = new TrainingDay(); bean.UserId = row.UserId; bean.Year = row.Year; bean.WeekOfYear = row.WeekOfYear; bean.DayOfWeek = row.DayOfWeek; bean.TrainingDayId = row.TrainingDayId; bean.BeginHour = row.BeginHour; bean.EndHour = row.EndHour; bean.ModificationDate = DbUtils.DbDateToUtc(row.ModificationDate); bean.Unit = Utils.IntToEnum <TUnitType>(row.Unit ?? (int)userUnit); return(bean); }
/// <summary> /// Get data in database /// </summary> /// <param name="key">Primary Key</param> /// <returns>read data</returns> public TrainingDay Get(TrainingDayKey key, TUnitType userUnit) { if (key == null || string.IsNullOrWhiteSpace(key.UserId) || key.Year == 0 || key.WeekOfYear == 0 || key.DayOfWeek < 0 || key.DayOfWeek > 6 || key.TrainingDayId == 0) { return(null); } var row = _dbContext.TrainingDay.Where(t => t.UserId == key.UserId && t.Year == key.Year && t.WeekOfYear == key.WeekOfYear && t.DayOfWeek == key.DayOfWeek && t.TrainingDayId == key.TrainingDayId).FirstOrDefault(); if (row != null) { return(TrainingDayTransformer.ToBean(row, userUnit)); } return(null); }
public List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario) { List <TrainingDay> result; BeginTransaction(); try { result = GetTrainingDayManager().FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario); CommitTransaction(); } catch { RollbackTransaction(); throw; } finally { EndTransaction(); } return(result); }
/// <summary> /// Find datas /// </summary> /// <returns></returns> public List <TrainingDay> Find(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria = null) { List <TrainingDay> resultList = null; IQueryable <TrainingDayRow> rowList = _dbContext.TrainingDay; CriteriaTransformer.CompleteQuery(ref rowList, trainingDayCriteria); rowList = rowList.OrderBy(t => t.DayOfWeek).OrderBy(t => t.BeginHour); if (rowList != null) { foreach (var trainingJournalDayRow in rowList) { if (resultList == null) { resultList = new List <TrainingDay>(); } resultList.Add(TrainingDayTransformer.ToBean(trainingJournalDayRow, userUnit)); } } return(resultList); }
private async Task <TUnitType> GetExerciseUnit() { TUnitType unit = TUnitType.Metric; try { if (_trainingExercise != null && _trainingExercise.TrainingExerciseSets != null && _trainingExercise.TrainingExerciseSets.Count > 0) { unit = _trainingExercise.TrainingExerciseSets[0].Unit; } else { if (_userInfo == null) { var userInfoKey = new UserInfoKey() { UserId = _trainingExercise.UserId }; if (_trainingExercise.UserId == UserData.Instance.UserInfo.UserId) { var userInfoService = new UserInfoService(_dbContext); _userInfo = userInfoService.GetUserInfo(userInfoKey); } else { _userInfo = await UserInfoWebService.GetUserInfoAsync(userInfoKey); } } if (_userInfo != null) { unit = _userInfo.Unit; } } } catch { } return(unit); }
private void TransformUserUnitToMetricUnit(TUnitType userUnit, TrainingExerciseSet trainingExerciseSet) { if (trainingExerciseSet != null) { trainingExerciseSet.Weight = Utils.TransformWeightToUnitSytem(userUnit, TUnitType.Metric, trainingExerciseSet.Weight); } }
public void ChangeUnitForTrainingExercises(TrainingDay trainingDay, TUnitType oldUnit) { GetTrainingDayManager().ChangeUnitForTrainingExercises(trainingDay, oldUnit); }
private GenericGroupModelCollection <BindingTrainingExercise> PopulateBindingTrainingDay(TrainingDay trainingDay) { if (trainingDay == null) { return(null); } TUnitType viewerUnit = UserData.Instance.UserInfo.Unit; string weightUnit = viewerUnit == TUnitType.Imperial ? Translation.Get(TRS.POUND) : "kg"; StringBuilder setRepSb = new StringBuilder(); StringBuilder setRepWeightSb = new StringBuilder(); string beginHourStr, endHourStr; BindingTrainingExercise bindingTrainingExercise; var collection = new GenericGroupModelCollection <BindingTrainingExercise>();; beginHourStr = trainingDay.BeginHour.ToLocalTime().ToString("HH:mm"); endHourStr = trainingDay.EndHour.ToLocalTime().ToString("HH:mm"); collection.LongName = $"{Translation.Get(TRS.FROM)} {beginHourStr} {Translation.Get(TRS.TO)} {endHourStr}"; collection.ShortName = collection.LongName; collection.ReferenceObject = trainingDay; collection.Clear(); if (trainingDay.TrainingExercises != null) { BodyExercise bodyExercise; TrainingExercise trainingExercise; for (int i = 0; i < trainingDay.TrainingExercises.Count; i++) { trainingExercise = trainingDay.TrainingExercises[i]; bodyExercise = _bodyExerciseList.Where(m => m.Id == trainingExercise.BodyExerciseId).FirstOrDefault(); bindingTrainingExercise = new BindingTrainingExercise() { TrainingExercise = trainingExercise, BodyExerciseId = trainingExercise.BodyExerciseId, RestTime = trainingExercise.RestTime, Tempo = string.Format("{0} : {1}-{2}-{3}-{4}", Translation.Get(TRS.TEMPO), trainingExercise.EccentricContractionTempo, trainingExercise.StretchPositionTempo, trainingExercise.ConcentricContractionTempo, trainingExercise.ContractedPositionTempo), UpOrderVisible = i != 0, DownOrderVisible = i != (trainingDay.TrainingExercises.Count - 1) }; bindingTrainingExercise.BodyExerciseName = bodyExercise != null ? bodyExercise.Name : Translation.Get(TRS.UNKNOWN); if (trainingExercise.TrainingExerciseSets != null) { bindingTrainingExercise.SetRepsTitle = $"{Translation.Get(TRS.SETS)} x {(trainingExercise.ExerciseUnitType == TExerciseUnitType.RepetitionNumber ? Translation.Get(TRS.REPS) : Translation.Get(TRS.EXECUTION_TIME))}"; bindingTrainingExercise.SetRepWeightsTitle = Translation.Get(TRS.WEIGHT) + " (" + weightUnit + ")"; setRepSb.Clear(); setRepWeightSb.Clear(); foreach (var set in trainingExercise.TrainingExerciseSets) { setRepSb.AppendLine($"{set.NumberOfSets} x {(trainingExercise.ExerciseUnitType == TExerciseUnitType.RepetitionNumber ? set.NumberOfReps.ToString() : FormatExecutionTime(set.ExecutionTime))}"); setRepWeightSb.AppendLine(Math.Round(Utils.TransformWeightToUnitSytem(trainingDay.Unit, viewerUnit, set.Weight), 3).ToString()); } bindingTrainingExercise.SetReps = setRepSb.ToString(); bindingTrainingExercise.SetRepWeights = setRepWeightSb.ToString(); } collection.Add(bindingTrainingExercise); } } return(collection); }
public List <TrainingDay> FindTrainingDay(TUnitType userUnit, TrainingDayCriteria trainingDayCriteria, TrainingDayScenario trainingDayScenario) { return(GetTrainingDayManager().FindTrainingDay(userUnit, trainingDayCriteria, trainingDayScenario)); }