public JsonResult ArticleInfo(string ArticleType_Name, int limit, int offset)
        {
            var article = from a in db.Article
                          join b in db.ArticleType on a.ArticleType_ID equals b.ArticleType_ID
                          into JionedEmpDept
                          from ab in JionedEmpDept.DefaultIfEmpty()
                          join c in db.User_Card on a.UserCard_ID equals c.UserCard_ID
                          into JionedEmpDeptac
                          from ac in JionedEmpDeptac.DefaultIfEmpty()
                          orderby a.Article_CreateDT descending
                          //where ab.ArticleType_Name.Contains(ArticleType_Name)
                          select new
            {
                ID   = a.Article_ID,
                文章标题 = a.Article_Title,
                文章描述 = a.Article_Abstract,
                文章内容 = a.Article_Content,
                文章封面 = a.Article_Img,
                创建时间 = a.Article_CreateDT.ToString("yyyy/MM/dd"),
                文章标签 = a.Lable_ID,
                文章类型 = ab.ArticleType_Name,
                文章作者 = ac.UserCard_Nickname
            };
            var total = article.Count();
            var rows  = article.Where(x => x.文章类型.Contains(ArticleType_Name)).Skip(offset).Take(limit).ToList();

            return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet));
        }
 public ActionResult Article_Edit(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         if (id == 0)
         {
             ViewBag.state = "";
         }
         else
         {
             var article = from a in db.Article
                           join b in db.ArticleType on a.ArticleType_ID equals b.ArticleType_ID
                           into JionedEmpDept
                           from ab in JionedEmpDept.DefaultIfEmpty()
                           join c in db.User_Card on a.UserCard_ID equals c.UserCard_ID
                           into JionedEmpDeptac
                           from ac in JionedEmpDeptac.DefaultIfEmpty()
                           where a.Article_ID == id
                           select new
             {
                 ID   = a.Article_ID,
                 文章标题 = a.Article_Title,
                 文章描述 = a.Article_Abstract,
                 文章内容 = a.Article_Content,
                 文章封面 = a.Article_Img,
                 创建时间 = a.Article_CreateDT,
                 文章标签 = a.Lable_ID,
                 文章类型 = ab.ArticleType_Name,
                 文章作者 = ac.UserCard_Nickname
             };
             foreach (var i in article)
             {
                 ViewData["文章标题"] = i.文章标题;
                 ViewData["文章描述"] = i.文章描述;
                 ViewData["文章内容"] = i.文章内容.ToString();
                 ViewData["创建时间"] = i.创建时间;
                 var    lables       = i.文章标签.Split(',');
                 string LablesID_str = "";
                 foreach (var lable in lables)
                 {
                     LablesID_str = LablesID_str + db.Lable.Where(x => x.Lable_ID.ToString() == lable).Select(x => x.Lable_Text).FirstOrDefault() + ",";
                 }
                 ViewData["文章标签"] = LablesID_str;
                 ViewData["文章类型"] = i.文章类型;
                 ViewData["文章作者"] = i.文章作者;
                 ViewData["文章封面"] = i.文章封面;
                 ViewBag.Labe     = LablesID_str;
             }
             ViewBag.state = id;
         }
     }
     //ViewBag.state = "";
     return(View());
     //return Content(id.ToString());
 }
        public void CheckLoginStart()
        {
            User_Login user_Login = new User_Login();

            try
            {
                if (Session["UsernameOrdinary"] != null || Session["UsernameOrdinary"].ToString() != "")
                {
                    user_Login = (User_Login)Session["UsernameOrdinary"];
                    //string[] vs = Session["Username"].ToString().Split(',');
                    var list = (from n in db.User_Login
                                join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                                into JionedEmpDept
                                from a in JionedEmpDept.DefaultIfEmpty()
                                where n.UserLogin_Name == user_Login.UserLogin_Name && n.UserLogin_PassWord == user_Login.UserLogin_PassWord
                                select new
                    {
                        权限 = a.UserCard_GmLevel,
                        状态 = n.UserLogin_State
                    });            //内连接
                    if (list.Count() > 0)
                    {
                        foreach (var s in list)
                        {
                            if (s.状态 == true)
                            {
                                start = true;
                                //if (s.权限 == 0)
                                //{
                                //    start = true;
                                //}
                                //else
                                //{
                                //    start = false;
                                //}
                            }
                            else
                            {
                                start = false;
                            }
                        }
                    }
                }
                else
                {
                    start = false;
                }
            }
            catch (Exception e)
            {
                start = false;
            }
        }
        public JsonResult tset()
        {
            var ArticleType = from a in db.ArticleType
                              join b in db.Forum
                              on a.Forum_ID equals b.Forum_ID
                              into JionedEmpDept
                              from b in JionedEmpDept.DefaultIfEmpty()
                              select new
            {
                a.Forum_ID,
                a.ArticleType_ID,
                a.ArticleType_Name,
                b.Forum_Name
            };

            return(Json(new { total = ArticleType.ToList().Count, rows = ArticleType.ToList() }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult ArticleTypeInfo(int limit, int offset, string Search)
        {
            var total = 0;

            if (Search.Trim() == "")
            {
                var ArticleType = from a in db.ArticleType
                                  join b in db.Forum
                                  on a.Forum_ID equals b.Forum_ID
                                  into JionedEmpDept
                                  from b in JionedEmpDept.DefaultIfEmpty()
                                  select new
                {
                    a.Forum_ID,
                    a.ArticleType_ID,
                    a.ArticleType_Name,
                    b.Forum_Name
                };
                total = ArticleType.ToList().Count;
                var rows = ArticleType.Skip(offset).Take(limit).ToList();
                return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var ArticleType = from a in db.ArticleType
                                  join b in db.Forum
                                  on a.Forum_ID equals b.Forum_ID
                                  into JionedEmpDept
                                  from b in JionedEmpDept.DefaultIfEmpty()
                                  where a.ArticleType_Name.Contains(Search.Trim())
                                  select new
                {
                    a.Forum_ID,
                    a.ArticleType_ID,
                    a.ArticleType_Name,
                    b.Forum_Name
                };
                total = ArticleType.ToList().Count;
                var rows = ArticleType.Skip(offset).Take(limit).ToList();
                return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult UserLoginImg()
        {
            User_Login user_Login = new User_Login();

            user_Login = (User_Login)Session["UsernameOrdinary"];
            var list = (from n in db.User_Login
                        join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                        into JionedEmpDept
                        from a in JionedEmpDept.DefaultIfEmpty()
                        where n.UserLogin_Name == user_Login.UserLogin_Name && n.UserLogin_PassWord == user_Login.UserLogin_PassWord
                        select new
            {
                权限 = a.UserCard_GmLevel,
                状态 = n.UserLogin_State,
                头像 = a.UserCard_ChatHeadImg,
                用户名 = n.UserLogin_Name,
                昵称 = a.UserCard_Nickname
            });

            return(Json(list.ToList(), JsonRequestBehavior.AllowGet));
        }
        public JsonResult ArticleInfo_ALL(int limit, int offset, string SearchArticleName, string SearchArticleTypeName, int id)
        {
            var ArticleInfoALL = from a in db.Article
                                 join b in db.ArticleType on a.ArticleType_ID equals b.ArticleType_ID
                                 into JionedEmpDept
                                 from ab in JionedEmpDept.DefaultIfEmpty()
                                 join c in db.User_Card on a.UserCard_ID equals c.UserCard_ID
                                 into JionedEmpDeptac
                                 from ac in JionedEmpDeptac.DefaultIfEmpty()
                                 where a.Article_Title.Contains(SearchArticleName) && ab.ArticleType_Name.Contains(SearchArticleTypeName)
                                 select new
            {
                ID   = a.Article_ID,
                文章标题 = a.Article_Title,
                文章描述 = a.Article_Abstract,
                文章内容 = a.Article_Content,
                文章封面 = a.Article_Img,
                创建时间 = a.Article_CreateDT.ToString("yyyy/MM/dd"),
                文章标签 = a.Lable_ID,
                文章类型 = ab.ArticleType_Name,
                文章作者 = ac.UserCard_Nickname,
                UCID = ac.UserLogin_ID
            };

            if (id == 0)
            {
            }
            else
            {
                ArticleInfoALL = from a in ArticleInfoALL
                                 where a.UCID == id
                                 select a;
            }
            var total = ArticleInfoALL.ToList().Count;
            var rows  = ArticleInfoALL.Skip(offset).Take(limit).ToList();

            return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet));
        }
        public int LoginAdmin(string username, string password)
        {
            var state = 0;

            if (db.User_Login.Where(x => x.UserLogin_Name == username).ToList().Count > 0)
            {
                List <User_Login> user = db.User_Login.Where(x => x.UserLogin_Name == username).ToList();
                if (user.Select(x => x.UserLogin_PassWord == password).Count() > 0)
                {
                    var list = (from n in user
                                join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                                into JionedEmpDept
                                from a in JionedEmpDept.DefaultIfEmpty()
                                select new
                    {
                        权限 = a.UserCard_GmLevel,
                        状态 = n.UserLogin_State
                    });            //内连接
                    foreach (var s in list)
                    {
                        if (s.状态 == true)
                        {
                            if (s.权限 == 0)
                            {
                                state = 1;
                            }
                            else
                            {
                                state = 3;
                            }
                        }
                        else
                        {
                            state = 4;
                        }
                    }
                    //state = 1;//登录成功
                    if (state == 1)
                    {
                        /*
                         * if (Request.Cookies.Get("username") != null)//Request.Cookies["username"]!=null
                         * {
                         *  //Cookie已经存在
                         * }*/
                        //return RedirectToAction( "_operator", "operatorInfo" );
                        //User_Login user_Login = db.User_Login.Where(x => x.UserLogin_Name == username);
                        User_Login user_Login  = new User_Login();
                        var        user_Logins = from a in db.User_Login
                                                 where a.UserLogin_Name == username && a.UserLogin_PassWord == password
                                                 select a;
                        foreach (var a in user_Logins)
                        {
                            user_Login = a;
                        }
                        Session["Username"] = user_Login;
                        /*使用Cookie*/

                        //cookie.Value = "用户名";//单值
                        cookie.Values["username"] = HttpUtility.UrlEncode(username);
                        //cookie.Values["password"] = HttpUtility.UrlEncode(password);//多值
                        //cookie.Expires = DateTime.MaxValue;//过期时间
                        cookie.Expires = DateTime.Now.AddHours(1);
                        Response.Cookies.Add(cookie);
                        roles.SetRole(username, "Admin");
                    }
                    else
                    {
                        Response.Cookies["User"].Values["username"] = null;
                        Session["Username"] = null;
                        Session.RemoveAll();
                        Session.Clear();
                    }
                }
                else
                {
                    state = 2;//密码错误
                    Session.RemoveAll();
                    Session.Clear();
                }
            }
            else
            {
                state = 0;//无此用户
                Session.RemoveAll();
                Session.Clear();
            }
            return(state);
        }
        public int LoginManagementOrdinary(string UNM, string PWD)
        {
            var state            = 0;
            int i                = -1;
            List <User_Login> ad = db.User_Login.ToList();

            foreach (var ax in ad)
            {
                if (ax.UserLogin_Name == UNM && ax.UserLogin_PassWord == PWD)
                {
                    i = ax.UserLogin_ID;
                }
                else
                {
                    state = 0;
                }
            }
            if (i != -1)
            {
                List <User_Login> user = db.User_Login.Where(x => x.UserLogin_ID == i).ToList();
                var list = (from n in user
                            join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                            into JionedEmpDept
                            from a in JionedEmpDept.DefaultIfEmpty()
                            select new
                {
                    权限 = a.UserCard_GmLevel,
                    状态 = n.UserLogin_State
                });            //内连接
                foreach (var s in list)
                {
                    if (s.状态 == true)
                    {
                        state = 1;
                    }
                    else
                    {
                        state = 4;
                    }
                }
                if (state == 1)
                {
                    User_Login user_Login  = new User_Login();
                    var        user_Logins = from a in db.User_Login
                                             where a.UserLogin_ID == i
                                             select a;
                    foreach (var a in user_Logins)
                    {
                        user_Login = a;
                    }
                    Session["UsernameOrdinary"] = user_Login;
                    roles.SetRole(UNM, "PUTONG");
                }
                else
                {
                    Session["UsernameOrdinary"] = null;
                    Session.RemoveAll();
                    Session.Clear();
                }
            }
            else
            {
                state = 0;//无此用户
                Session.RemoveAll();
                Session.Clear();
            }
            return(state);
        }
 public ActionResult ArticleADD(FormCollection collection)
 {
     try
     {
         User_Login user_Login1 = new User_Login();
         var        user_Logins = from a in db.User_Login
                                  where a.UserLogin_ID == 1
                                  select a;
         foreach (var a in user_Logins)
         {
             user_Login1 = a;
         }
         Session["UsernameOrdinary"] = user_Login1;
         var        content     = collection["editor"];
         string     PathImgFile = "";
         User_Login user_Login  = new User_Login();
         user_Login = (User_Login)Session["UsernameOrdinary"];
         var list = (from n in db.User_Login
                     join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                     into JionedEmpDept
                     from a in JionedEmpDept.DefaultIfEmpty()
                     where n.UserLogin_Name == user_Login.UserLogin_Name && n.UserLogin_PassWord == user_Login.UserLogin_PassWord
                     select new
         {
             用户卡片ID = a.UserCard_ID,
             // 用户名=n.UserLogin_Name
         });
         int Uid = 0;
         foreach (var x in list)
         {
             Uid = x.用户卡片ID;
         }
         if (Request.Files.Count > 0)
         {
             DirectoryInfo directory = new DirectoryInfo(Directory.GetCurrentDirectory());
             string        ext       = Path.GetExtension(Request.Files[0].FileName);//directory.FullName;
             if (Request.Files[0].ContentType == "image/jpg" || Request.Files[0].ContentType == "image/png" || Request.Files[0].ContentType == "image/gif" || Request.Files[0].ContentType == "image/jpeg")
             {
                 Random ran      = new Random();
                 string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ran.Next(100, 1000) + Guid.NewGuid().ToString() + ext;//给文件取名
                 string fileDir  = HttpContext.Server.MapPath("/Resource/Img");
                 fileDir = fileDir + "/" + fileName;
                 Request.Files[0].SaveAs(fileDir);
                 //PathImgFile = fileDir + "." + ext + "" + Request.Files[0].ContentType;
                 PathImgFile = "/Resource/Img/" + fileName;
             }
             else
             {
                 PathImgFile = "/Resource/Img/20180518030030100c8fc06cd-770e-49f1-b77b-cdc54d8a0d45.jpg";
             }
         }
         else
         {
             PathImgFile = "/Resource/Img/20180518030030100c8fc06cd-770e-49f1-b77b-cdc54d8a0d45.jpg";
         }
         string type      = collection["ArticleType_ID"].Trim() + "-" + collection["inputForum_Name"].Trim();
         int    ATypeID   = db.ArticleType.Where(x => x.ArticleType_Name == type).Select(x => x.ArticleType_ID).FirstOrDefault();
         var    array     = collection["biaoqian"].Split(',');
         string LableText = ",";
         int    lableid;
         foreach (var xa in array)
         {
             if (db.Lable.Where(x => x.Lable_Text == xa).Count() > 0)
             {
             }
             else
             {
                 Lable lable = new Lable {
                     Lable_Text = xa, Lable_Remark = user_Login.UserLogin_Name + "新增", Lable_CreatDT = DateTime.Now
                 };
                 db.Lable.Add(lable);
                 db.SaveChanges();
             }
             lableid    = db.Lable.Where(x => x.Lable_Text == xa).Select(x => x.Lable_ID).FirstOrDefault();
             LableText += lableid + ",";
         }
         db.Article.Add(new Article
         {
             UserCard_ID      = Uid,
             Article_Title    = collection["Article_Title"].ToString(),
             Article_Abstract = collection["Article_Abstract"].ToString(),
             Article_CreateDT = DateTime.Now,
             Article_Img      = PathImgFile,
             Article_Content  = content,
             ArticleType_ID   = ATypeID,
             Lable_ID         = LableText,
         });
         db.SaveChanges();
         return(Content(type));
     }
     catch (Exception ex)
     {
         return(Content(ex.ToString()));
     }
 }
 /// <summary>
 /// 文章详细表
 /// </summary>
 /// <param name="id">文章ID</param>
 /// <returns></returns>
 public ActionResult ArticleInfo_ID(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         if (id == 0)
         {
             var article = from a in db.Article
                           join b in db.ArticleType on a.ArticleType_ID equals b.ArticleType_ID
                           into JionedEmpDept
                           from ab in JionedEmpDept.DefaultIfEmpty()
                           join c in db.User_Card on a.UserCard_ID equals c.UserCard_ID
                           into JionedEmpDeptac
                           from ac in JionedEmpDeptac.DefaultIfEmpty()
                           //where ab.ArticleType_Name.Contains(ArticleType_Name)
                           select new
             {
                 ID   = a.Article_ID,
                 文章标题 = a.Article_Title,
                 文章描述 = a.Article_Abstract,
                 文章内容 = a.Article_Content,
                 文章封面 = a.Article_Img,
                 创建时间 = a.Article_CreateDT,
                 文章标签 = a.Lable_ID,
                 文章类型 = ab.ArticleType_Name,
                 文章作者 = ac.UserCard_Nickname
             };
             foreach (var i in article)
             {
                 ViewBag.Article_ID = i.ID;
                 ViewData["文章标题"]   = i.文章标题;
                 ViewData["文章描述"]   = i.文章描述;
                 ViewData["文章内容"]   = i.文章内容.ToString();
                 ViewData["创建时间"]   = i.创建时间;
                 string[] lables   = i.文章标签.ToString().Split(',');
                 string[] lablestr = new string[lables.Length];
                 for (int a = 0; a < lables.Length; a++)
                 {
                     int lableID = int.Parse(lables[a]);
                     lablestr[a] = db.Lable.Where(x => x.Lable_ID == lableID).Select(x => x.Lable_Text).FirstOrDefault();
                 }
                 ViewData["文章标签"] = lablestr;
                 ViewData["文章类型"] = i.文章类型;
                 ViewData["文章作者"] = i.文章作者;
             }
         }
         else
         {
             var article = from a in db.Article
                           join b in db.ArticleType on a.ArticleType_ID equals b.ArticleType_ID
                           into JionedEmpDept
                           from ab in JionedEmpDept.DefaultIfEmpty()
                           join c in db.User_Card on a.UserCard_ID equals c.UserCard_ID
                           into JionedEmpDeptac
                           from ac in JionedEmpDeptac.DefaultIfEmpty()
                           where a.Article_ID == id
                           select new
             {
                 ID   = a.Article_ID,
                 文章标题 = a.Article_Title,
                 文章描述 = a.Article_Abstract,
                 文章内容 = a.Article_Content,
                 文章封面 = a.Article_Img,
                 创建时间 = a.Article_CreateDT,
                 文章标签 = a.Lable_ID,
                 文章类型 = ab.ArticleType_Name,
                 文章作者 = ac.UserCard_Nickname
             };
             foreach (var i in article)
             {
                 ViewBag.Article_ID = i.ID;
                 ViewData["文章标题"]   = i.文章标题;
                 ViewData["文章描述"]   = i.文章描述;
                 ViewData["文章内容"]   = i.文章内容.ToString();
                 ViewData["创建时间"]   = i.创建时间;
                 string[] lables   = i.文章标签.ToString().Split(',');
                 string[] lablestr = new string[lables.Length];
                 for (int a = 0; a < lables.Length; a++)
                 {
                     //int lableID = int.Parse(lables[a+1]);
                     lablestr[a] = db.Lable.Where(x => x.Lable_ID.ToString() == lables[a]).Select(x => x.Lable_Text).FirstOrDefault();
                 }
                 ViewData["文章标签"] = lablestr;
                 ViewData["文章类型"] = i.文章类型;
                 ViewData["文章作者"] = i.文章作者;
                 ViewBag.Labe     = lablestr;
             }
         }
     }
     return(View());
 }