示例#1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="country">Data</param>
        /// <returns>insert data</returns>
        public Country Create(Country country)
        {
            if (country == null || country.Id == 0)
            {
                return(null);
            }

            var row = new CountryRow();

            CountryTransformer.ToRow(country, row);
            _dbContext.Insert(row);

            return(CountryTransformer.ToBean(row));
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscle">data</param>
        /// <returns>updated data</returns>
        public Country Update(Country muscle)
        {
            if (muscle == null || muscle.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.Country.Where(m => m.Id == muscle.Id).FirstOrDefault();

            if (row == null)
            { // No data in database
                return(Create(muscle));
            }
            else
            { //Modify Data in database
                CountryTransformer.ToRow(muscle, row);
                _dbContext.SaveChanges();
                return(CountryTransformer.ToBean(row));
            }
        }
示例#3
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscle">data</param>
        /// <returns>updated data</returns>
        public Country Update(Country muscle)
        {
            if (muscle == null || muscle.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.Table <CountryRow>().Where(m => m.Id == muscle.Id).FirstOrDefault();

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