Esempio n. 1
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="userInfo">UserInfo</param>
        /// <returns>insert data</returns>
        public UserInfo Create(UserInfo userInfo)
        {
            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId))
            {
                return(null);
            }

            var row = new UserInfoRow();

            UserInfoTransformer.ToRow(userInfo, row);
            _dbContext.Insert(row);
            return(UserInfoTransformer.ToBean(row));
        }
Esempio n. 2
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public UserInfo Get(UserInfoKey key)
        {
            if (key == null || string.IsNullOrWhiteSpace(key.UserId))
            {
                return(null);
            }

            var row = _dbContext.UserInfo.Where(m => m.UserId == key.UserId).FirstOrDefault();

            if (row != null)
            {
                return(UserInfoTransformer.ToBean(row));
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Find data in database
        /// </summary>
        /// <returns></returns>
        public List <UserInfo> Find(UserInfoCriteria userInfoCriteria = null)
        {
            List <UserInfo>          resultList = null;
            TableQuery <UserInfoRow> rowList    = _dbContext.Table <UserInfoRow>();

            CriteriaTransformer.CompleteQuery(ref rowList, userInfoCriteria);

            if (rowList != null && rowList.Count() > 0)
            {
                resultList = new List <UserInfo>();
                foreach (var userInfoRow in rowList)
                {
                    resultList.Add(UserInfoTransformer.ToBean(userInfoRow));
                }
            }
            return(resultList);
        }
Esempio n. 4
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="userInfo">data</param>
        /// <returns>updated data</returns>
        public UserInfo Update(UserInfo userInfo)
        {
            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId))
            {
                return(null);
            }

            var row = _dbContext.UserInfo.Where(m => m.UserId == userInfo.UserId).FirstOrDefault();

            if (row == null)
            { // No data in database
                return(Create(userInfo));
            }
            else
            { //Modify Data in database
                UserInfoTransformer.ToRow(userInfo, row);
                _dbContext.SaveChanges();
                return(UserInfoTransformer.ToBean(row));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="userInfo">data</param>
        /// <returns>updated data</returns>
        public UserInfo Update(UserInfo userInfo)
        {
            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId))
            {
                return(null);
            }

            var row = _dbContext.Table <UserInfoRow>().Where(m => m.UserId == userInfo.UserId).FirstOrDefault();

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