Exemplo n.º 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));
        }
Exemplo n.º 3
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));
            }
        }