Exemplo n.º 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));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public Country Get(CountryKey key)
        {
            if (key == null || key.Id == 0)
            {
                return(null);
            }

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

            if (row != null)
            {
                return(CountryTransformer.ToBean(row));
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Find data in database
        /// </summary>
        /// <returns></returns>
        public List <Country> Find(CountryCriteria countryCriteria = null)
        {
            List <Country>          resultList = null;
            TableQuery <CountryRow> rowList    = _dbContext.Table <CountryRow>();

            CriteriaTransformer.CompleteQuery(ref rowList, countryCriteria);

            if (rowList != null && rowList.Count() > 0)
            {
                resultList = new List <Country>();
                foreach (var row in rowList)
                {
                    resultList.Add(CountryTransformer.ToBean(row));
                }
            }
            return(resultList);
        }
        /// <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));
            }
        }
Exemplo n.º 5
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));
            }
        }