示例#1
0
        public ResultModel <U_User> Login([FromBody] JObject model, [FromUri] Encrypt encrypt)
        {
            ResultModel <U_User> msg = new ResultModel <U_User>();
            var user = JsonConvert.DeserializeObject <U_User>(JsonConvert.SerializeObject(model));

            if (user == null)
            {
                msg.Code    = 2001;
                msg.Message = "参数错误";
                return(msg);
            }
            if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.PassWord))
            {
                msg.Code    = 2001;
                msg.Message = "参数错误";
                return(msg);
            }
            UserInfoForCookie userInfoForCookie = null;

            msg = new U_UserBLL().UserLogin(user, ref userInfoForCookie);
            if (msg.Code == 2000)
            {
                HttpContext.Current.Response.Cookies.Set(G_Comm.EncryptCookie <UserInfoForCookie>(userInfoForCookie));
            }
            return(msg);
        }
示例#2
0
        public int UpdateArticle(Article article, UserInfoForCookie user)
        {
            StringBuilder sbsql      = new StringBuilder(@"UPDATE  dbo.Article
        SET ");
            var           dyParamter = new DynamicParameters();

            dyParamter.Add("UserCode", user.UserCode);
            dyParamter.Add("ArticleNo", article.ArticleNo);
            if (article.Title != null)
            {
                sbsql.Append("Title=@Title");
                dyParamter.Add("Title", article.Title);
            }
            if (article.Content != null)
            {
                sbsql.Append("Content=@Content");
                dyParamter.Add("Content", article.Content);
            }
            if (article.ImageUrl != null)
            {
                sbsql.Append("ImageUrl=@ImageUrl");
                dyParamter.Add("ImageUrl", article.ImageUrl);
            }
            sbsql.Append(@"
                Modifier = @UserCode ,
                ModDate = GETDATE()
        WHERE   ArticleNo = @ArticleNo");
            using (var conn = AdoConfig.GetDBConnection())
            {
                return(conn.Execute(sbsql.ToString(), dyParamter));
            }
        }
示例#3
0
        public ResultModel <object> DeleteArticle(Article article, UserInfoForCookie user)
        {
            ResultModel <object> msg = new ResultModel <object>();

            if (article == null)
            {
                msg.Code    = 2001;
                msg.Message = "参数错误";
                return(msg);
            }
            if (string.IsNullOrEmpty(article.ArticleNo))
            {
                msg.Code    = 2001;
                msg.Message = "参数错误";
                return(msg);
            }
            int result = 0;

            result = new ArticleDAL().DeleteArticle(article, user);
            if (result > 0)
            {
                msg.Message = "操作成功";
            }
            else
            {
                msg.Code    = 2001;
                msg.Message = "操作失败";
            }
            return(msg);
        }
示例#4
0
        public int DeleteArticle(Article article, UserInfoForCookie user)
        {
            string sql = @"UPDATE  dbo.Article
        SET     IsDel = 1 ,
                Modifier = @UserCode ,
                ModDate = GETDATE()
        WHERE   ArticleNo = @ArticleNo;";

            using (var conn = AdoConfig.GetDBConnection())
            {
                return(conn.Execute(sql, new { article.ArticleNo, user.UserCode }));
            }
        }
示例#5
0
        /// <summary>
        /// 操作
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public ResultModel <object> OperateArticle(Article article, UserInfoForCookie user)
        {
            ResultModel <object> msg = new ResultModel <object>();

            if (article == null)
            {
                msg.Code    = 2001;
                msg.Message = "参数错误";
                return(msg);
            }
            if (article.Title == null && article.Content == null && article.ImageUrl == null)
            {
                msg.Code    = 2000;
                msg.Message = "未作修改";
                return(msg);
            }
            int result = 0;

            if (!string.IsNullOrEmpty(article.ArticleNo))//update
            {
                result = new ArticleDAL().UpdateArticle(article, user);
            }
            else//insert
            {
                article.ArticleNo = new CreateEmpCode().GetRandomEmpCode(2, 4);
                result            = new ArticleDAL().InsertArticle(article, user);
            }
            if (result > 0)
            {
                msg.Message = "操作成功";
            }
            else
            {
                msg.Code    = 2001;
                msg.Message = "操作失败";
            }
            return(msg);
        }
示例#6
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public ResultModel <U_User> UserLogin(U_User user, ref UserInfoForCookie userInfoForCookie)
        {
            ResultModel <U_User> msg = new ResultModel <U_User>();

            user.PassWord = EncryptOperation.MD5HashHex(user.PassWord);
            msg.Data      = new U_UserDAL().UserLogin(user);
            if (msg.Data == null)
            {
                msg.Code    = 2001;
                msg.Message = "帐号或密码错误";
            }
            else
            {
                userInfoForCookie = new UserInfoForCookie()
                {
                    UserName = msg.Data.UserName,
                    UserCode = msg.Data.UserCode,
                    IsAdmin  = msg.Data.IsAdmin,
                    E_Mail   = msg.Data.E_Mail,
                };
            }
            return(msg);
        }
示例#7
0
        public int InsertArticle(Article article, UserInfoForCookie user)
        {
            string sql = @" INSERT dbo.Article
                ( Title ,
                  ArticleNo,
                  Creator ,
                  CreateDate ,
                  Content ,
                  ImageUrl
                )
        VALUES  ( @Title , 
                  @ArticleNo,
                  @UserCode , 
                  GETDATE() , 
                  @Content ,
                  @ImageUrl
                )";

            using (var conn = AdoConfig.GetDBConnection())
            {
                return(conn.Execute(sql, new { article.Title, article.ArticleNo, article.Content, article.ImageUrl, user.UserCode }));
            }
        }