Esempio 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);
        }
        public static void ToRow(MuscularGroup bean, MuscularGroupRow row)
        {
            if (bean == null)
                return;

            row.Id = bean.Id;
        }
        internal static MuscularGroup ToBean(MuscularGroupRow row)
        {
            if (row == null)
                return null;

            var bean = new MuscularGroup();
            bean.Id = row.Id;
            return bean;
        }