Esempio n. 1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="bodyExercise">Data</param>
        /// <returns>insert data</returns>
        public BodyExercise Create(BodyExercise bodyExercise)
        {
            if (bodyExercise == null)
            {
                return(null);
            }

            if (bodyExercise.Id == 0)
            {
                var key = new BodyExerciseKey();
                var sequencerManager = new SequencerManager();
                do
                {
                    key.Id = sequencerManager.GetNextValue(_dbContext, 2, "bodyExercise");
                }while (Get(key) != null); // Test Record exist
                bodyExercise.Id = key.Id;
            }

            if (bodyExercise.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = new BodyExerciseRow();

            BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
            _dbContext.BodyExercise.Add(bodyExerciseRow);
            _dbContext.SaveChanges();
            return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
        }
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public BodyExercise Get(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == key.Id).FirstOrDefault();

            if (bodyExerciseRow != null)
            {
                return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Find body exercises
        /// </summary>
        /// <returns></returns>
        public List <BodyExercise> Find(BodyExerciseCriteria bodyExerciseCriteria = null)
        {
            List <BodyExercise>          resultList           = null;
            TableQuery <BodyExerciseRow> muscularGroupRowList = _dbContext.Table <BodyExerciseRow>();

            CriteriaTransformer.CompleteQuery(ref muscularGroupRowList, bodyExerciseCriteria);

            if (muscularGroupRowList != null && muscularGroupRowList.Count() > 0)
            {
                resultList = new List <BodyExercise>();
                foreach (var muscularGroupRow in muscularGroupRowList)
                {
                    resultList.Add(BodyExerciseTransformer.ToBean(muscularGroupRow));
                }
            }
            return(resultList);
        }
Esempio n. 4
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="bodyExercise">Data</param>
        /// <returns>insert data</returns>
        public BodyExercise Create(BodyExercise bodyExercise)
        {
            if (bodyExercise == null)
            {
                return(null);
            }

            if (bodyExercise.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = new BodyExerciseRow();

            BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
            _dbContext.Insert(bodyExerciseRow);
            return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="bodyExercise">data</param>
        /// <returns>updated data</returns>
        public BodyExercise Update(BodyExercise bodyExercise)
        {
            if (bodyExercise == null || bodyExercise.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == bodyExercise.Id).FirstOrDefault();

            if (bodyExerciseRow == null)
            { // No data in database
                return(Create(bodyExercise));
            }
            else
            { //Modify Data in database
                BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
                _dbContext.SaveChanges();
                return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="bodyExercise">data</param>
        /// <returns>updated data</returns>
        public BodyExercise Update(BodyExercise bodyExercise)
        {
            if (bodyExercise == null || bodyExercise.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = _dbContext.Table <BodyExerciseRow>().Where(m => m.Id == bodyExercise.Id).FirstOrDefault();

            if (bodyExerciseRow == null)
            { // No data in database
                return(Create(bodyExercise));
            }
            else
            {                                       //Modify Data in database
                BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
                _dbContext.Delete(bodyExerciseRow); //Update don't work... need delete and insert
                _dbContext.Insert(bodyExerciseRow);
                return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
            }
        }