Пример #1
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="trainingJournalDayExercise">data</param>
        /// <returns>updated data</returns>
        public TrainingExercise Update(TrainingExercise trainingJournalDayExercise)
        {
            if (trainingJournalDayExercise == null || string.IsNullOrWhiteSpace(trainingJournalDayExercise.UserId) ||
                trainingJournalDayExercise.Year == 0 || trainingJournalDayExercise.WeekOfYear == 0 ||
                trainingJournalDayExercise.DayOfWeek < 0 || trainingJournalDayExercise.DayOfWeek > 6 || trainingJournalDayExercise.TrainingDayId == 0 || trainingJournalDayExercise.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.TrainingExercise.Where(t => t.UserId == trainingJournalDayExercise.UserId &&
                                                        t.Year == trainingJournalDayExercise.Year &&
                                                        t.WeekOfYear == trainingJournalDayExercise.WeekOfYear &&
                                                        t.DayOfWeek == trainingJournalDayExercise.DayOfWeek &&
                                                        t.TrainingDayId == trainingJournalDayExercise.TrainingDayId &&
                                                        t.Id == trainingJournalDayExercise.Id).FirstOrDefault();

            if (row == null)
            {             // No data in database
                return(Create(trainingJournalDayExercise));
            }
            else
            {             //Modify Data in database
                TrainingExerciseTransformer.ToRow(trainingJournalDayExercise, row);
                _dbContext.SaveChanges();
                return(GetBean(row));
            }
        }
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="trainingJournalDayExercise">Data</param>
        /// <returns>insert data</returns>
        public TrainingExercise Create(TrainingExercise trainingJournalDayExercise)
        {
            if (trainingJournalDayExercise == null || string.IsNullOrWhiteSpace(trainingJournalDayExercise.UserId) ||
                trainingJournalDayExercise.Year == 0 || trainingJournalDayExercise.WeekOfYear == 0 ||
                trainingJournalDayExercise.DayOfWeek < 0 || trainingJournalDayExercise.DayOfWeek > 6 || trainingJournalDayExercise.TrainingDayId == 0 || trainingJournalDayExercise.Id == 0)
            {
                return(null);
            }

            var row = new TrainingExerciseRow();

            TrainingExerciseTransformer.ToRow(trainingJournalDayExercise, row);
            _dbContext.Insert(row);
            return(GetBean(row));
        }