Esempio n. 1
0
        public IList <UserSimp> GetLikedPersons(IList <int> ids)
        {
            //参数id数量不固定,目前方案只能采用拼接sql的方式来进行
            List <UserSimp> list = new List <UserSimp>();

            if (null == ids || ids.Count == 0)
            {
                return(list); //如果没有id的话,直接返回一个空的集合
            }
            string sql = ids.Aggregate("select usersimp.userid,usersimp.username from user_usersimp usersimp,user_likeperson likeperson where likeperson.userid=usersimp.userid and likeperson.id in(", (current, id) => current + (id + ","));

            //去掉逗号,加上括号
            sql = sql.Substring(0, sql.Length - 1) + ")";
            DataSet dataSet = new DataSet();

            SqlHelper.GetDataTable(sql, CommandType.Text, dataSet);
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                UserSimp model = new UserSimp();
                model.UserId   = Convert.ToInt32(row[0]);
                model.UserName = row[1].ToString();
                list.Add(model);
            }
            return(list);
        }
Esempio n. 2
0
        public UserSimp GetUserSimp(string account)
        {
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentNullException("account", "用户账户为空");
            }
            UserSimp     model = null;
            string       sql   = "select * from user_usersimp where account=@account";
            SqlParameter spm   = new SqlParameter("@account", SqlDbType.VarChar, 20)
            {
                Value = account
            };

            using (var reader = SqlHelper.ExecuteReader(sql, CommandType.Text, spm))
            {
                if (reader.HasRows)
                {
                    model = new UserSimp();
                    while (reader.Read())
                    {
                        model.UserId   = reader.GetInt32(0);
                        model.UserName = reader.GetString(1);
                        model.Account  = account;
                        model.Password = reader.GetString(3);
                        model.MemberId = reader.GetInt32(4);
                        model.Head     = reader.GetString(5);
                        model.DelFlag  = (DelFlag)reader.GetInt32(6);
                    }
                }
            }
            return(model);
        }
Esempio n. 3
0
        public void AddUser(UserSimp usersimp, UserInfo userinfo)
        {
            if (null == usersimp || null == userinfo)
            {
                throw new ArgumentNullException("userinfo");
            }
            string sqluser     = "******";
            string sqluserinfo =
                "insert into user_userinfo values(@desc,@email,@emailvalidatecode,@isvalide,@number,@like,@follower,@follow,@delflag)";

            SqlParameter[] spm1 =
                SqlHelper.GetSqpParameters(
                    new string[] { "@username", "@account", "@password", "@memberid", "@head", "delflag" },
                    new object[]
            {
                usersimp.UserName, usersimp.Account, usersimp.Password, usersimp.MemberId, usersimp.Head,
                usersimp.DelFlag
            },
                    new SqlDbType[]
            {
                SqlDbType.NVarChar, SqlDbType.VarChar, SqlDbType.VarChar, SqlDbType.Int, SqlDbType.VarChar,
                SqlDbType.Int
            });
            SqlParameter[] spm2 =
                SqlHelper.GetSqpParameters(
                    new string[]
            {
                "@desc", "@email", "@emailvalidatecode", "@isvalide", "@number", "@like", "@follow", "@follow",
                "@delflag"
            },
                    new object[]
            {
                userinfo.Description, userinfo.Email, userinfo.EmailValidateCode, userinfo.IsValide,
                userinfo.Number, userinfo.Liked, userinfo.Follower, userinfo.Follow, userinfo.DelFlag
            },
                    new SqlDbType[]
            {
                SqlDbType.NVarChar, SqlDbType.VarChar, SqlDbType.VarChar, SqlDbType.Int, SqlDbType.VarChar,
                SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, SqlDbType.Int
            });

            try
            {
                SqlHelper.Sqltransaction(new string[] { sqluser, sqluserinfo },
                                         new SqlParameter[][] { spm1, spm2 });
            }
            catch (Exception e)
            {
                throw new UserException("注册用户失败,请重新注册");
            }
        }
Esempio n. 4
0
        public ViewUser GetViewUser(UserSimp usersimp)
        {
            if (null == usersimp)
            {
                throw new ArgumentNullException("usersimp", "usersimp对象为null");
            }
            ViewUser viewUser = new ViewUser();

            viewUser.UserId   = usersimp.UserId;
            viewUser.UserName = usersimp.UserName;
            //这里要进行一次路径的转换
            viewUser.Head = ConvertPath.RelativeToAppLocation(usersimp.Head);
            return(viewUser);
        }
Esempio n. 5
0
        public void RegsiterUser(string account, string username, string description, string password1, string password2)
        {
            if (password1 != password2)
            {
                throw new UserException("2次密码输入不一致");
            }
            if (password1.Length < 6)
            {
                throw new UserException("密码最小长度为6位");
            }
            if (AccountExist(account))
            {
                throw new UserException("用户名已经存在");
            }
            UserSimp userSimp = new UserSimp()
            {
                Account  = account,
                UserName = username,
                DelFlag  = DelFlag.Normal,
                //头像,我们给一个默认值
                Head = @"E:\ShareYou\ShareYou\Content\Image\Head\2c8d94e6-3d6b-4b61-8150-c3d3790b9ab8.png",
                //第一级的会员
                MemberId = 0,
                //进行md5加密操作
                Password = Md5String.GetMd5String(password1),
            };
            UserInfo userinfo = new UserInfo()
            {
                Description       = description,
                Email             = "",
                EmailValidateCode = "",
                DelFlag           = DelFlag.Normal,
                IsValide          = EmailValide.NotValide,
                Follower          = 0,
                Follow            = 0,
                Liked             = 0,
                Number            = "",
            };

            //异常继续往上抛出
            DbSession.UserDal.AddUser(userSimp, userinfo);
        }
Esempio n. 6
0
        //如果需要另外的Service来解决,必须new 对象出来,不然存在一个循环引用的问题,但是还是有好处的,就是避免了创建过多的对象出来

        public UserSimp Login(string account, string password)
        {
            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                throw new UserException("密码或者账号为空,请重新输入");
            }
            if (!AccountExist(account))
            {
                throw new UserException("账户不存在,大兄弟!");
            }
            DelFlag status = (DelFlag)Convert.ToInt32(DbSession.UserDal.GetUserStatus(account)); //可能存在异常,我们继续往上抛出

            if (status == DelFlag.Deleted)                                                       //账户被删除
            {
                throw new UserException("此用户已被删除,请申诉或者重新申请账户");
            }
            if (status == DelFlag.Freeze)
            {
                throw new UserException("当前账户被冻结");
            }
            //可以获取用户信息
            UserSimp model = null;

            if (Md5String.GetMd5String(password) == DbSession.UserDal.GetPassword(account).ToString())
            {
                //表示信息校验成功
                //出现的异常继续往上抛出
                model = DbSession.UserDal.GetUserSimp(account);
            }
            else
            {
                //密码错误,出现异常了
                throw new UserException("用户密码错误");
            }
            return(model);
        }
Esempio n. 7
0
 public ViewComment()
 {
     User    = new UserSimp();
     Comment = new ForumComment();
 }
Esempio n. 8
0
 public ViewUserInfo()
 {
     UserInfo = new UserInfo.UserInfo();
     User     = new UserSimp();
 }
Esempio n. 9
0
 public ViewPost()
 {
     Post = new ForumPost();
     User = new UserSimp();
 }