Ejemplo n.º 1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="trainingJournal">Data</param>
        /// <returns>insert data</returns>
        public TrainingWeek Create(TrainingWeek trainingJournal)
        {
            if (trainingJournal == null || string.IsNullOrWhiteSpace(trainingJournal.UserId) ||
                trainingJournal.Year == 0 || trainingJournal.WeekOfYear == 0)
                return null;

            var row = new TrainingWeekRow();
            TrainingWeekTransformer.ToRow(trainingJournal, row);
            _dbContext.TrainingWeek.Add(row);
            _dbContext.SaveChanges();
            return TrainingWeekTransformer.ToBean(row);
        }
Ejemplo n.º 2
0
        public static void ToRow(TrainingWeek bean, TrainingWeekRow row)
        {
            if (bean == null)
                return;

            row.UserId = bean.UserId;
            row.Year = bean.Year;
            row.WeekOfYear = bean.WeekOfYear;
            row.UserHeight = bean.UserHeight;
            row.UserWeight = bean.UserWeight;
            row.Unit = (int)bean.Unit;
            row.ModificationDate = DbUtils.DateToUtc(Utils.DateTimeWithoutMs); // Set modificationDate
        }
Ejemplo n.º 3
0
        internal static TrainingWeek ToBean(TrainingWeekRow row)
        {
            if (row == null)
                return null;

            var bean = new TrainingWeek();
            bean.UserId = row.UserId;
            bean.Year = row.Year;
            bean.WeekOfYear = row.WeekOfYear;
            bean.UserHeight = row.UserHeight;
            bean.UserWeight = row.UserWeight;
            bean.Unit = Utils.IntToEnum<TUnitType>(row.Unit);
            bean.ModificationDate = DbUtils.DbDateToUtc(row.ModificationDate);
            return bean;
        }