예제 #1
0
 public void AddUser(DUOJU_USERS user)
 {
     DBEntities.DUOJU_USERS.Add(user);
 }
예제 #2
0
        public int AddWeChatUser(WeChatUserInfo info)
        {
            var user  = UserRepository.GetUserByOpenId(info.openid);
            var isAdd = user == null;

            var subscribed = info.subscribe.HasValue ?
                             (YesNo)Enum.Parse(typeof(YesNo), info.subscribe.Value.ToString()) :
                             (user != null && user.SUBSCRIBED == YesNo.Y.ToString() ? YesNo.Y : YesNo.N);

            if (isAdd)
            {
                var rolePrivilege = UserRepository.GetRolePrivilege(UserRoles.USER.ToString());
                user = new DUOJU_USERS
                {
                    ACCOUNT = string.Format(CommonSettings.USERACCOUNT_WECHAT_FORMAT, info.openid),
                    SOURCE  = (int)UserSources.WECHAT,
                    DUOJU_ROLE_PRIVILEGES = rolePrivilege,
                    PRIVILEGES            = rolePrivilege.PRIVILEGES,
                    OPEN_ID     = info.openid,
                    CREATE_BY   = CommonSettings.OPERATOR_SYSTEM_ID,
                    CREATE_TIME = DateTime.Now
                };
            }

            user.SUBSCRIBED = subscribed.ToString();
            if (subscribed == YesNo.Y)
            {
                if (info.subscribe_time.HasValue)
                {
                    user.SUBSCRIBE_TIME = WeChat.ConvertDateTime(info.subscribe_time.Value);
                }
                user.NICK_NAME = info.nickname;
                if (info.sex.HasValue)
                {
                    user.SEX = ((UserSexes)Enum.Parse(typeof(UserSexes), info.sex.Value.ToString())).ToString();
                }
                user.HEAD_IMG_URL = info.headimgurl;
                if (!string.IsNullOrEmpty(info.country))
                {
                    var country = AreaRepository.GetCountryInfoByName(info.country);
                    if (country != null)
                    {
                        user.DUOJU_COUNTRIES = country;
                    }
                }
                if (!string.IsNullOrEmpty(info.province))
                {
                    var province = AreaRepository.GetProvinceInfoByName(info.province);
                    if (province != null)
                    {
                        user.DUOJU_PROVINCES = province;
                    }
                }
                if (!string.IsNullOrEmpty(info.city))
                {
                    var city = AreaRepository.GetCityInfoByName(info.city);
                    if (city != null)
                    {
                        user.DUOJU_CITIES = city;
                    }
                }
            }
            user.ENABLED          = YesNo.Y.ToString();
            user.LAST_UPDATE_BY   = CommonSettings.OPERATOR_SYSTEM_ID;
            user.LAST_UPDATE_TIME = DateTime.Now;

            if (isAdd)
            {
                user.DUOJU_USER_FINANCES.Add(new DUOJU_USER_FINANCES
                {
                    COIN_COUNT       = CommonSettings.USERREGISTER_DEFAULT_COIN_COUNT,
                    CREATE_BY        = CommonSettings.OPERATOR_SYSTEM_ID,
                    CREATE_TIME      = DateTime.Now,
                    LAST_UPDATE_BY   = CommonSettings.OPERATOR_SYSTEM_ID,
                    LAST_UPDATE_TIME = DateTime.Now
                });

                UserRepository.AddUser(user);
            }
            UserRepository.SaveChanges();

            return(user.USER_ID);
        }