Beispiel #1
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);
        }
Beispiel #2
0
        private bool UpgradeUserRole(SubOrder subOrder, UserLevel level)
        {
            DateTime start = DateTime.Now;

            BeginTransaction();
            Tnet_User_Role daVip = new Tnet_User_Role();

            daVip.ReferenceTransactionFrom(Transaction);
            if (!daVip.SelectByUserId_UserLevel(subOrder.User_Id, (int)level))
            {
                daVip.User_Id          = subOrder.User_Id;
                daVip.Expire_Time      = start.AddYears(1);
                daVip.Last_Modify_Time = DateTime.Now;
                daVip.User_Level       = (int)level;
                daVip.Role_Name        = UserLevel.VIP会员.ToString();
                if (!daVip.Insert())
                {
                    Rollback();
                    return(false);
                }
            }
            else
            {
                if (daVip.Expire_Time > start)
                {
                    start = daVip.Expire_Time;
                }
                daVip.Expire_Time      = start.AddYears(1);
                daVip.Last_Modify_Time = DateTime.Now;
                if (!daVip.Update())
                {
                    Rollback();
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(this.Order.Biz_Args))
            {
                JsonObject arg      = JsonObject.Parse(this.Order.Biz_Args);
                string     org_code = arg.GetString("Org_Code");
                if (!string.IsNullOrEmpty(org_code))
                {
                    Tnet_Organization daOrg = new Tnet_Organization();
                    if (!daOrg.SelectByOrgCode(org_code))
                    {
                        Rollback();
                        Alert("归属俱乐部未找到");
                        return(false);
                    }
                    Tnet_User_Profile daProfile = new Tnet_User_Profile();
                    daProfile.ReferenceTransactionFrom(Transaction);
                    daProfile.User_Id          = daVip.User_Id;
                    daProfile.Org_Id           = daOrg.Org_Id;
                    daProfile.Last_Modify_Time = DateTime.Now;
                    if (!daProfile.Update())
                    {
                        Rollback();
                        Alert("修改归属信息失败");
                        return(false);
                    }
                }
            }
            Tnet_User daUser = new Tnet_User();

            daUser.ReferenceTransactionFrom(Transaction);
            if (!daUser.UpdateUserLevel(subOrder.User_Id, level))
            {
                Rollback();
                Alert("更新会员角色失败");
                return(false);
            }
            Commit();
            return(true);
        }