Esempio n. 1
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseUserContactEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldUserId, entity.UserId);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldShowEmail, entity.ShowEmail);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEmail, entity.Email);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEmailValidated, entity.EmailValidated);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldShowMobile, entity.ShowMobile);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldMobile, entity.Mobile);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldMobileValidated, entity.MobileValidated);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldMobileValidatedTime, entity.MobileValidatedTime);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldShortNumber, entity.ShortNumber);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldTelephone, entity.Telephone);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldExtension, entity.Extension);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldQq, entity.Qq);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldWw, entity.Ww);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldIm, entity.Im);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldWeChat, entity.WeChat);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldWeChatValidated, entity.WeChatValidated);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldWeChatOpenId, entity.WeChatOpenId);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldCompanyId, entity.CompanyId);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldCompanyEmail, entity.CompanyEmail);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEmergencyContact, entity.EmergencyContact);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEmergencyMobile, entity.EmergencyMobile);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEmergencyTelephone, entity.EmergencyTelephone);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseUserContactEntity.FieldEnabled, entity.Enabled);
 }
Esempio n. 2
0
        /// <summary>
        /// 保存实体修改记录
        /// </summary>
        /// <param name="newEntity">修改前的实体对象</param>
        /// <param name="oldEntity">修改后的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void UpdateEntityLog(BaseUserContactEntity newEntity, BaseUserContactEntity oldEntity, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                tableName = BaseUserEntity.TableName + "_LOG";
            }
            BaseModifyRecordManager manager = new BaseModifyRecordManager(this.UserInfo, tableName);

            foreach (var property in typeof(BaseUserContactEntity).GetProperties())
            {
                var oldValue         = Convert.ToString(property.GetValue(oldEntity, null));
                var newValue         = Convert.ToString(property.GetValue(newEntity, null));
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                //不记录创建人、修改人、没有修改的记录
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var record = new BaseModifyRecordEntity();
                record.TableCode         = this.CurrentTableName.ToUpper();
                record.TableDescription  = FieldExtensions.ToDescription(typeof(BaseUserContactEntity), "TableName");
                record.RecordKey         = oldEntity.Id.ToString();
                record.ColumnCode        = property.Name.ToUpper();
                record.ColumnDescription = fieldDescription.Text;
                record.NewValue          = newValue;
                record.OldValue          = oldValue;
                record.IPAddress         = Utilities.GetIPAddress(true);
                manager.Add(record, true, false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public static BaseUserContactEntity GetObjectByCache(string id)
        {
            BaseUserContactEntity result = null;

            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            string cacheObject             = "UserContact";

            if (!string.IsNullOrEmpty(id))
            {
                cacheObject = "UserContact" + id;
            }
            if (cache != null && cache[cacheObject] == null)
            {
                BaseUserContactManager manager = new DotNet.Business.BaseUserContactManager(BaseUserContactEntity.TableName);
                result = manager.GetObject(id);
                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    cache.Add(cacheObject, result, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, CacheItemPriority.Normal, null);
                    // System.Console.WriteLine(System.DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " cache UserContact " + id);
                }
            }
            result = cache[cacheObject] as BaseUserContactEntity;

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 更新用户联系方式
        /// </summary>
        /// <param name="entity">用户联系方式实体</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserContactEntity entity)
        {
            int result = 0;

            // 获取原始实体信息
            var entityOld = this.GetObject(entity.Id);

            // 2015-12-26 吉日嘎拉 当新增时,需要判断这个是否为空
            if (entityOld != null)
            {
                // 保存修改记录
                this.UpdateEntityLog(entity, entityOld);
            }
            // 更新数据
            result = this.UpdateObject(entity);
            // 同步数据
            // AfterUpdate(entity);
            // 重新设置缓存
            if (result > 0)
            {
                BaseUserContactManager.SetCache(entity);
            }

            // 返回值
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 设置对象,若不存在就增加,有存在就更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>更新、添加成功?</returns>
        public bool SetObject(BaseUserContactEntity entity)
        {
            bool result = false;

            // 若有主键就是先更新,没主键就是添加
            if (!string.IsNullOrEmpty(entity.Id))
            {
                result = this.Update(entity) > 0;
                // 若不存在,就是添加的意思
                if (!result)
                {
                    // 更新不成功表示没数据,需要添加数据,这时候要注意主键不能出错
                    result = !string.IsNullOrEmpty(this.Add(entity));
                }
            }
            else
            {
                // 若没有主键就是添加数据
                result = !string.IsNullOrEmpty(this.Add(entity));
            }

            // 2016-01-20 吉日嘎拉, 用户的联系方式修改后,要把用户的修改时间也修改,这样才会同步下载用户的信息,用户的联系方式
            SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper);

            sqlBuilder.BeginUpdate(BaseUserEntity.TableName);
            sqlBuilder.SetDBNow(BaseUserEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseUserEntity.FieldId, entity.Id);
            sqlBuilder.EndUpdate();

            return(result);
        }
        /// <summary>
        /// 保存实体修改记录
        /// </summary>
        /// <param name="entityNew">修改后的实体对象</param>
        /// <param name="entityOld">修改前的实体对象</param>
        /// <param name="tableName">表名称</param>
        public void SaveEntityChangeLog(BaseUserContactEntity entityNew, BaseUserContactEntity entityOld, string tableName = null)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                //统一放在一个公共表 Troy.Cui 2016-08-17
                tableName = BaseChangeLogEntity.CurrentTableName;
            }
            var manager = new BaseChangeLogManager(UserInfo, tableName);

            foreach (var property in typeof(BaseUserContactEntity).GetProperties())
            {
                var oldValue         = Convert.ToString(property.GetValue(entityOld, null));
                var newValue         = Convert.ToString(property.GetValue(entityNew, null));
                var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription;
                //不记录创建人、修改人、没有修改的记录
                if (!fieldDescription.NeedLog || oldValue == newValue)
                {
                    continue;
                }
                var entity = new BaseChangeLogEntity
                {
                    TableName         = CurrentTableName,
                    TableDescription  = FieldExtensions.ToDescription(typeof(BaseUserContactEntity), "CurrentTableName"),
                    RecordKey         = entityOld.Id.ToString(),
                    ColumnName        = property.Name,
                    ColumnDescription = fieldDescription.Text,
                    NewValue          = newValue,
                    OldValue          = oldValue
                };
                manager.Add(entity, true, false);
            }
        }
Esempio n. 7
0
        public static BaseUserContactEntity GetUserContactObject(BaseUserInfo userInfo, string id)
        {
            BaseUserContactEntity result = null;

            string url = BaseSystemInfo.UserCenterHost + "/UserCenterV42/UserService.ashx";

            WebClient           webClient  = new WebClient();
            NameValueCollection postValues = new NameValueCollection();

            postValues.Add("system", BaseSystemInfo.SoftFullName);
            postValues.Add("systemCode", BaseSystemInfo.SystemCode);
            postValues.Add("securityKey", BaseSystemInfo.SecurityKey);
            // 2015-11-25 吉日嘎拉,这里还是从缓存里获取就可以了,提高登录的效率。
            postValues.Add("function", "GetUserContactObject");
            postValues.Add("userInfo", userInfo.Serialize());
            postValues.Add("encrypted", true.ToString());
            postValues.Add("id", SecretUtil.Encrypt(id));
            // 向服务器发送POST数据
            byte[] responseArray = webClient.UploadValues(url, postValues);
            string response      = Encoding.UTF8.GetString(responseArray);

            if (!string.IsNullOrEmpty(response))
            {
                result = JsonConvert.DeserializeObject <BaseUserContactEntity>(response);
            }

            return(result);
        }
        /// <summary>
        /// 设置对象,若不存在就增加,有存在就更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>更新、添加成功?</returns>
        public bool SetEntity(BaseUserContactEntity entity)
        {
            var result = false;

            // 若有主键就是先更新,没主键就是添加
            if (!string.IsNullOrEmpty(entity.Id.ToString()))
            {
                result = Update(entity) > 0;
                // 若不存在,就是添加的意思
                if (!result)
                {
                    // 更新不成功表示没数据,需要添加数据,这时候要注意主键不能出错
                    result = !string.IsNullOrEmpty(Add(entity));
                }
            }
            else
            {
                // 若没有主键就是添加数据
                result = !string.IsNullOrEmpty(Add(entity));
            }

            // 2016-01-20 吉日嘎拉, 用户的联系方式修改后,要把用户的修改时间也修改,这样才会同步下载用户的信息,用户的联系方式
            var sqlBuilder = new SqlBuilder(DbHelper);

            sqlBuilder.BeginUpdate(BaseUserEntity.CurrentTableName);
            sqlBuilder.SetDbNow(BaseUserEntity.FieldUpdateTime);
            sqlBuilder.SetWhere(BaseUserEntity.FieldId, entity.UserId);
            sqlBuilder.EndUpdate();

            return(result);
        }
Esempio n. 9
0
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseUserContactEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
        /// <summary>
        /// 更新用户联系方式
        /// </summary>
        /// <param name="entity">用户联系方式实体</param>
        /// <param name="enableLlog">启用日志</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserContactEntity entity, bool enableLlog)
        {
            var result = 0;

            if (enableLlog)
            {
                // 获取原始实体信息
                var entityOld = GetEntity(entity.Id);
                // 2015-12-26 吉日嘎拉 当新增时,需要判断这个是否为空
                if (entityOld != null)
                {
                    // 保存修改记录
                    SaveEntityChangeLog(entity, entityOld);
                }
            }
            // 更新数据
            result = UpdateEntity(entity);
            // 同步数据
            // AfterUpdate(entity);
            // 重新设置缓存
            if (result > 0)
            {
                SetCache(entity);
            }

            // 返回值
            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// 离职处理
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>影响行数</returns>
        public int Leave(BaseUserEntity userEntity, BaseUserLogOnEntity userLogOnEntity, string comment)
        {
            int result = 0;

            if (userEntity != null)
            {
                // 更新用户实体
                this.UpdateObject(userEntity);
            }

            // 更新登录信息
            if (userLogOnEntity != null)
            {
                BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(this.UserInfo);
                userLogOnManager.UpdateObject(userLogOnEntity);
            }

            // 填写评论
            if (!string.IsNullOrWhiteSpace(comment))
            {
                SQLBuilder sqlBuilder = new SQLBuilder(BaseSystemInfo.ServerDbType);
                sqlBuilder.BeginInsert(BaseCommentEntity.TableName);
                sqlBuilder.SetValue(BaseCommentEntity.FieldId, System.Guid.NewGuid().ToString("N"));
                sqlBuilder.SetValue(BaseCommentEntity.FieldCategoryCode, BaseUserEntity.TableName);
                sqlBuilder.SetValue(BaseCommentEntity.FieldObjectId, userEntity.Id);
                sqlBuilder.SetValue(BaseCommentEntity.FieldContents, comment);
                sqlBuilder.SetValue(BaseCommentEntity.FieldWorked, 1);
                sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentId, userEntity.DepartmentId);
                sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentName, userEntity.DepartmentName);
                sqlBuilder.SetValue(BaseCommentEntity.FieldCreateUserId, this.UserInfo.Id);
                sqlBuilder.SetValue(BaseCommentEntity.FieldCreateBy, this.UserInfo.RealName);
                sqlBuilder.SetDBNow(BaseCommentEntity.FieldCreateOn);
                sqlBuilder.SetValue(BaseCommentEntity.FieldIPAddress, this.UserInfo.IPAddress);
                sqlBuilder.SetValue(BaseCommentEntity.FieldEnabled, 1);
                sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 0);
                sqlBuilder.EndInsert();
            }

            // 2016-03-17 吉日嘎拉 停止吉信的号码
            if (userEntity != null && !string.IsNullOrEmpty(userEntity.NickName))
            {
                AfterLeaveStopIM(userEntity);
            }

            // 2016-03-17 吉日嘎拉 停止吉信的号码
            if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
            {
                BaseUserContactEntity userContactEntity = BaseUserContactManager.GetObjectByCache(userEntity.Id);
                {
                    if (userContactEntity != null && !string.IsNullOrEmpty(userContactEntity.CompanyMail))
                    {
                        ChangeUserMailStatus(userContactEntity.CompanyMail, true);
                    }
                }
            }

            return(result);
        }
Esempio n. 12
0
 private static void SetCache(BaseUserContactEntity entity)
 {
     if (entity != null && !string.IsNullOrWhiteSpace(entity.Id))
     {
         System.Web.Caching.Cache cache = HttpRuntime.Cache;
         string key = "UserContact" + entity.Id;
         cache.Add(key, entity, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, CacheItemPriority.Normal, null);
     }
 }
        private static void SetCache(BaseUserContactEntity entity)
        {
            var key = string.Empty;

            if (entity != null && entity.UserId > 0)
            {
                key = "UserContact:" + entity.UserId;
                CacheUtil.Set(key, entity);
            }
        }
        /// <summary>
        /// 从缓存中获取实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static BaseUserContactEntity GetCacheByKey(string key)
        {
            BaseUserContactEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                result = CacheUtil.Get <BaseUserContactEntity>(key);
            }
            return(result);
        }
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseUserContactEntity GetEntityByCache(int id)
        {
            BaseUserContactEntity result = null;

            if (id > 0)
            {
                var key = "UserContact:" + id;
                result = CacheUtil.Cache(key, () => new BaseUserContactManager().GetEntity(id), true);
            }

            return(result);
        }
Esempio n. 16
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseUserContactEntity GetUserContactObjectByCache(BaseUserInfo userInfo, string id)
        {
            BaseUserContactEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                entity = BaseUserContactManager.GetObjectByCache(id);
            });

            return(entity);
        }
        public static string GetTelephoneByCache(string id)
        {
            string result = string.Empty;

            BaseUserContactEntity entity = GetObjectByCache(id);

            if (entity != null)
            {
                result = entity.Telephone;
            }

            return(result);
        }
Esempio n. 18
0
        private static void SetCache(BaseUserContactEntity entity)
        {
            string key = string.Empty;

            if (entity != null && !string.IsNullOrWhiteSpace(entity.Id))
            {
                using (var redisClient = PooledRedisHelper.GetClient())
                {
                    key = "UserContact:" + entity.Id;
                    redisClient.Set <BaseUserContactEntity>(key, entity, DateTime.Now.AddMinutes(10));
                }
            }
        }
Esempio n. 19
0
        public static BaseUserContactEntity GetCacheByKey(string key)
        {
            BaseUserContactEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                using (var redisClient = PooledRedisHelper.GetClient())
                {
                    result = redisClient.Get <BaseUserContactEntity>(key);
                }
            }
            return(result);
        }
Esempio n. 20
0
        /// <summary>
        /// 验证手机验证码
        /// 2015-11-10 吉日嘎拉 手机验证码确认的代码进行优化
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="mobile">手机号码</param>
        /// <param name="code">验证码</param>
        /// <returns>成功验证</returns>
        public bool ValidateVerificationCode(BaseUserInfo userInfo, string mobile, string code)
        {
            bool result = false;

            if (string.IsNullOrEmpty(mobile))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(false);
            }

            string connectionString = string.Empty;

            connectionString = ConfigurationHelper.AppSettings("OpenMasDbConnection", BaseSystemInfo.EncryptDbConnection);
            if (!string.IsNullOrEmpty(connectionString))
            {
                using (IDbHelper dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SqlServer, connectionString))
                {
                    string commandText = @"SELECT COUNT(1)
                                             FROM SMSSentLog
                                            WHERE DATEDIFF(Hour, CreateTime, GETDATE()) < 8
                                                  AND MessageCode = " + dbHelper.GetParameter("MessageCode")
                                         + " AND DestinationAddress = " + dbHelper.GetParameter("DestinationAddress");
                    object remainingNumber = dbHelper.ExecuteScalar(commandText
                                                                    , new IDbDataParameter[] { dbHelper.MakeParameter("MessageCode", code)
                                                                                               , dbHelper.MakeParameter("DestinationAddress", mobile) });
                    if (remainingNumber != null)
                    {
                        result = int.Parse(remainingNumber.ToString()) > 0;
                    }
                }

                // 手机验证码通过审核了
                if (result && userInfo != null)
                {
                    BaseUserContactEntity userContactEntity = BaseUserContactManager.GetObjectByCache(userInfo.Id);
                    if (userContactEntity != null)
                    {
                        // 2016-02-13 吉日嘎拉 这里还需要进行缓存更新操作
                        userContactEntity.MobileValiated         = 1;
                        userContactEntity.MobileVerificationDate = DateTime.Now;
                        new BaseUserContactManager().Update(userContactEntity);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的
        /// </summary>
        /// <param name="userId">主键</param>
        /// <returns>用户信息</returns>
        public static BaseUserContactEntity SetCache(int userId)
        {
            BaseUserContactEntity result = null;

            var manager = new BaseUserContactManager();

            result = manager.GetEntityByUserId(userId);
            if (result != null)
            {
                SetCache(result);
            }

            return(result);
        }
        /// <summary>
        /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>用户信息</returns>
        public static BaseUserContactEntity SetCache(string id)
        {
            BaseUserContactEntity result = null;

            BaseUserContactManager manager = new BaseUserContactManager();

            result = manager.GetObject(id);
            if (result != null)
            {
                SetCache(result);
            }

            return(result);
        }
Esempio n. 23
0
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseUserContactEntity entity, bool identity = true, bool returnId = true)
 {
     Identity = identity;
     ReturnId = returnId;
     if (entity.Id == 0)
     {
         entity.Id = AddEntity(entity).ToInt();
         return(entity.Id.ToString());
     }
     else
     {
         return(UpdateEntity(entity) > 0 ? entity.Id.ToString() : string.Empty);
     }
 }
Esempio n. 24
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseUserContactEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseUserEntity.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
Esempio n. 25
0
        public static BaseUserContactEntity GetUserContactObjectByCache(BaseUserInfo userInfo, string id)
        {
            BaseUserContactEntity result = null;

            string key = "UserContact:" + id;

            result = BaseUserContactManager.GetCacheByKey(key);

            // 远程通过接口获取数据
            if (result == null)
            {
                result = GetUserContactObject(userInfo, id);
            }

            return(result);
        }
Esempio n. 26
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string CreateUser(BaseUserInfo userInfo, BaseUserEntity userEntity, BaseUserContactEntity userContactEntity, out string statusCode, out string statusMessage)
        {
            string result = string.Empty;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                result = CreateUser(dbHelper, userInfo, userEntity, userContactEntity, out returnCode, out returnMessage);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
Esempio n. 27
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseUserContactEntity GetObjectByCache(string id)
        {
            BaseUserContactEntity result = null;

            string key = "UserContact:";

            if (!string.IsNullOrEmpty(id))
            {
                key = key + id;
            }
            result = GetCacheByKey(key);
            if (result == null)
            {
                result = SetCache(id);
            }

            return(result);
        }
Esempio n. 28
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseUserContactEntity GetUserContactObject(BaseUserInfo userInfo, string id)
        {
            BaseUserContactEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 判断是否已经登录的用户?
                if (userManager.UserIsLogOn(userInfo))
                {
                    var userContactManager = new BaseUserContactManager(dbHelper, userInfo);
                    entity = userContactManager.GetObject(id);
                }
            });

            return(entity);
        }
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <returns>影响行数</returns>
        public static int CachePreheating()
        {
            int result = 0;

            // 把所有的数据都缓存起来的代码
            BaseUserContactManager manager = new BaseUserContactManager();

            using (IDataReader dataReader = manager.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    BaseUserContactEntity entity = BaseEntity.Create <BaseUserContactEntity>(dataReader, false);
                    BaseUserContactManager.SetCache(entity);
                    result++;
                    System.Console.WriteLine(result.ToString() + " : " + entity.Telephone);
                }
                dataReader.Close();
            }

            return(result);
        }
Esempio n. 30
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseUserContactEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseUserContactEntity.FieldId);
            sqlBuilder.SetValue(BaseUserContactEntity.FieldId, entity.Id);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseUserEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseUserEntity.FieldModifiedOn);
            sqlBuilder.EndInsert();
            return(entity.Id);
        }