Esempio n. 1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="translation">Data</param>
        /// <returns>insert data</returns>
        public TranslationVal Create(TranslationVal translation)
        {
            if (translation == null || translation.CultureId < 0 || string.IsNullOrWhiteSpace(translation.Key))
            {
                return(null);
            }

            var row = new TranslationRow();

            TranslationTransformer.ToRow(translation, row);
            _dbContext.Insert(row);

            return(TranslationTransformer.ToBean(row));
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="translation">data</param>
        /// <returns>updated data</returns>
        public TranslationVal Update(TranslationVal translation)
        {
            if (translation == null || translation.CultureId < 0 || string.IsNullOrWhiteSpace(translation.Key))
            {
                return(null);
            }

            var row = _dbContext.Translation.Where(m => m.CultureId == translation.CultureId && m.Key == translation.Key).FirstOrDefault();

            if (row == null)
            { // No data in database
                return(Create(translation));
            }
            else
            { //Modify Data in database
                TranslationTransformer.ToRow(translation, row);
                _dbContext.SaveChanges();
                return(TranslationTransformer.ToBean(row));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="translation">data</param>
        /// <returns>updated data</returns>
        public TranslationVal Update(TranslationVal translation)
        {
            if (translation == null || translation.CultureId < 0 || string.IsNullOrWhiteSpace(translation.Key))
            {
                return(null);
            }

            var row = _dbContext.Table <TranslationRow>().Where(m => m.CultureId == translation.CultureId && m.Key == translation.Key).FirstOrDefault();

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