Exemple #1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="muscularGroup">Data</param>
        /// <returns>insert data</returns>
        public MuscularGroup Create(MuscularGroup muscularGroup)
        {
            if (muscularGroup == null)
            {
                return(null);
            }

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

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

            var muscularGroupRow = new MuscularGroupRow();

            MuscularGroupTransformer.ToRow(muscularGroup, muscularGroupRow);
            _dbContext.MuscularGroup.Add(muscularGroupRow);
            _dbContext.SaveChanges();
            return(MuscularGroupTransformer.ToBean(muscularGroupRow));
        }
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="muscularGroup">Data</param>
        /// <returns>insert data</returns>
        public MuscularGroup Create(MuscularGroup muscularGroup)
        {
            if (muscularGroup == null || muscularGroup.Id == 0)
            {
                return(null);
            }

            var muscularGroupRow = new MuscularGroupRow();

            MuscularGroupTransformer.ToRow(muscularGroup, muscularGroupRow);
            _dbContext.Insert(muscularGroupRow);
            return(MuscularGroupTransformer.ToBean(muscularGroupRow));
        }
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public MuscularGroup Get(MuscularGroupKey key)
        {
            if (key == null || key.Id == 0)
            {
                return(null);
            }

            var muscularGroupRow = _dbContext.Table <MuscularGroupRow>().Where(m => m.Id == key.Id).FirstOrDefault();

            if (muscularGroupRow != null)
            {
                return(MuscularGroupTransformer.ToBean(muscularGroupRow));
            }
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <MuscularGroup> Find(MuscularGroupCriteria muscularGroupCriteria = null)
        {
            List <MuscularGroup>          resultList           = null;
            TableQuery <MuscularGroupRow> muscularGroupRowList = _dbContext.Table <MuscularGroupRow>();

            CriteriaTransformer.CompleteQuery(ref muscularGroupRowList, muscularGroupCriteria);

            if (muscularGroupRowList != null && muscularGroupRowList.Count() > 0)
            {
                resultList = new List <MuscularGroup>();
                foreach (var muscularGroupRow in muscularGroupRowList)
                {
                    resultList.Add(MuscularGroupTransformer.ToBean(muscularGroupRow));
                }
            }
            return(resultList);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <MuscularGroup> Find(MuscularGroupCriteria muscularGroupCriteria = null)
        {
            List <MuscularGroup>          resultList = null;
            IQueryable <MuscularGroupRow> rowList    = _dbContext.MuscularGroup;

            CriteriaTransformer.CompleteQuery(ref rowList, muscularGroupCriteria);

            if (rowList != null)
            {
                foreach (var muscularGroupRow in rowList)
                {
                    if (resultList == null)
                    {
                        resultList = new List <MuscularGroup>();
                    }
                    resultList.Add(MuscularGroupTransformer.ToBean(muscularGroupRow));
                }
            }
            return(resultList);
        }
Exemple #6
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscularGroup">data</param>
        /// <returns>updated data</returns>
        public MuscularGroup Update(MuscularGroup muscularGroup)
        {
            if (muscularGroup == null || muscularGroup.Id == 0)
            {
                return(null);
            }

            var muscularGroupRow = _dbContext.MuscularGroup.Where(m => m.Id == muscularGroup.Id).FirstOrDefault();

            if (muscularGroupRow == null)
            { // No data in database
                return(Create(muscularGroup));
            }
            else
            { //Modify Data in database
                MuscularGroupTransformer.ToRow(muscularGroup, muscularGroupRow);
                _dbContext.SaveChanges();
                return(MuscularGroupTransformer.ToBean(muscularGroupRow));
            }
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscularGroup">data</param>
        /// <returns>updated data</returns>
        public MuscularGroup Update(MuscularGroup muscularGroup)
        {
            if (muscularGroup == null || muscularGroup.Id == 0)
            {
                return(null);
            }

            var muscularGroupRow = _dbContext.Table <MuscularGroupRow>().Where(m => m.Id == muscularGroup.Id).FirstOrDefault();

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