Exemplo n.º 1
0
        public void FillIdentityInfo(int userId, Dictionary <string, object> dictionary)
        {
            string        birth = null, industry = null;
            int?          gender = null, cityId = null;
            Vnet_Identity daIdentity = new Vnet_Identity();

            if (daIdentity.SelectByUser_Id(userId))
            {
                birth  = daIdentity.Birthday.HasValue ? daIdentity.Birthday.Value.ToString() : string.Empty;
                gender = daIdentity.Gender;
                if (daIdentity.Region_Id.HasValue)
                {
                    var region = ChinaArea.GetRegion(daIdentity.Region_Id.Value);
                    cityId = region?.City_ID;
                }
            }
            Tnet_User_Profile daUserProfile = new Tnet_User_Profile();

            if (daUserProfile.SelectByPk(userId))
            {
                if (daUserProfile.City_Id.HasValue)
                {
                    cityId = daUserProfile.City_Id.Value;
                }
                industry = daUserProfile.Industry;
            }
            dictionary.Add("Birthday", birth);
            dictionary.Add("Industry", industry);
            dictionary.Add("Gender", gender);
            dictionary.Add("CityId", cityId);
        }
Exemplo n.º 2
0
        public bool ModifyUserProfile(Entities.ViewModels.UserModifyModel model)
        {
            if (!model.City_Id.HasValue && string.IsNullOrEmpty(model.Avatar) && !model.Org_Id.HasValue &&
                string.IsNullOrEmpty(model.Industry))
            {
                return(true);
            }
            var fac = UserModuleFactory.GetUserModuleInstance();

            if (fac == null)
            {
                Alert((ResultType)500, "系统错误");
                return(false);
            }
            IUser user = fac.GetUserByCode(model.UserCode);

            if (user == null)
            {
                Alert((ResultType)404, "找不到用户信息");
                return(false);
            }
            if (!model.City_Id.HasValue && string.IsNullOrEmpty(model.Avatar) && !model.Org_Id.HasValue &&
                !string.IsNullOrEmpty(user.Avatar) && user.Avatar.Equals(model.Avatar, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            BeginTransaction();
            Tnet_User_Profile daProfile = new Tnet_User_Profile();

            daProfile.ReferenceTransactionFrom(Transaction);
            bool isExist = daProfile.SelectByPk(user.UserId);

            if (model.City_Id.HasValue)
            {
                daProfile.City_Id = model.City_Id.Value;
            }
            if (!string.IsNullOrEmpty(model.Industry))
            {
                daProfile.Industry = model.Industry;
            }
            if (model.Org_Id.HasValue)
            {
                daProfile.Org_Id = model.Org_Id.Value;
            }
            if (!isExist)
            {
                daProfile.User_Id = user.UserId;
                if (!daProfile.Insert())
                {
                    Rollback();
                    Alert((ResultType)541, "用户资料更新失败");
                    return(false);
                }
            }
            else
            {
                if (!daProfile.Update())
                {
                    Rollback();
                    Alert((ResultType)542, "用户资料更新失败");
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(model.Avatar))
            {
                user.Avatar = model.Avatar;
                var manager = fac.GetProfileManager(user);
                if (!manager.Update())
                {
                    Rollback();
                    Alert((ResultType)540, "头像上传失败");
                    return(false);
                }
            }

            Commit();
            return(true);
        }