コード例 #1
0
        public ActionResult Register(BlogUsers user)
        {
            JSData       json       = new JSData();
            BlogTypesBLL typeBLL    = new BlogTypesBLL();
            BlogUsersBLL userBLL    = new BlogUsersBLL();
            BlogUsers    checkName  = userBLL.GetList(t => t.UserName == user.UserName).FirstOrDefault();
            BlogUsers    checkEmail = userBLL.GetList(t => t.Email == user.Email).FirstOrDefault();

            if (checkName != null)
            {
                json.State   = EnumState.失败;
                json.Message = "用户名已存在!";
            }
            else if (checkEmail != null)
            {
                json.State   = EnumState.失败;
                json.Message = "该邮箱已被注册!";
            }
            else
            {
                user.UserNickname = user.UserName;
                userBLL.Add(user);
                typeBLL.Add(new BlogTypes {
                    TypeName = "未分类", UserId = user.UserId, BlogUsers = user
                });
                try
                {
                    userBLL.save();
                    typeBLL.save();
                }catch (Exception ex)
                {
                    throw ex;
                }
                BLL.DataCache.GetUsersInfo(true);//更新缓存
                BLLSession.UserInfoSessioin = user;
                json.State   = EnumState.正常重定向;
                json.JSurl   = "/";
                json.Message = "恭喜你," + user.UserName + "注册成功!";
            }
            return(Json(json));
        }
コード例 #2
0
        /// <summary>
        /// 若在数据库找到该用户名,则返回该用户id,否则创建该用户名用户
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        private int GetUserId(string userName)
        {
            BlogTypesBLL type        = new BlogTypesBLL();
            BlogUsersBLL user        = new BlogUsersBLL();
            var          blogtagmode = user.GetList(t => t.UserName == userName);

            if (blogtagmode.Count() >= 1)
            {
                return(blogtagmode.FirstOrDefault().UserId);
            }
            else if (userName == "admin")
            {
                user.Add(new BlogUsers()
                {
                    UserName     = userName,
                    IsDel        = false,
                    UserPass     = "******",
                    UserNickname = "小mu虫",
                    Email        = "*****@*****.**"
                });
                user.save();
                if (type.GetList(t => t.TypeName == "未分类").Count() < 1)
                {
                    type.Add(new BlogTypes()
                    {
                        TypeName = "未分类",
                        UserId   = user.GetList(t => t.UserName == userName).FirstOrDefault().UserId
                    });
                    type.save();
                }
                return(GetUserId(userName));
            }
            else
            {
                Exception ex = new Exception("在博客家园中没有该用户,请先新建该用户!"); throw ex;
            }
        }