コード例 #1
0
        public JsonResult delComment(comment comment)
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                if (user.type == 1)
                {
                    DbNewsDataContext db = new DbNewsDataContext();
                    var query            = from t in db.comment
                                           where t.id == comment.id
                                           select t;
                    foreach (comment item in query)
                    {
                        db.comment.DeleteOnSubmit(item);
                    }
                    db.SubmitChanges();
                    return(Json(Result.success()));
                }
                else
                {
                    return(Json(Result.fail()));
                }
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #2
0
        public JsonResult login(User user)
        {
            DbNewsDataContext db    = new DbNewsDataContext();
            IQueryable <User> query = from t in db.user
                                      where t.username == user.username && t.password == user.password
                                      select new User
            {
                id       = t.id,
                username = t.username,
                nickname = t.nickname,
                type     = t.type
            };
            List <User> userList = query.ToList();

            if (userList.Count() == 1)
            {
                userList[0].password = null;
                Session.Add("user", userList[0]);
                Session.Add("type", userList[0].type);
                return(Json(Result.success()));
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #3
0
        public JsonResult getNews(News news)
        {
            DbNewsDataContext db = new DbNewsDataContext();

            if (news.id > 0)
            {
                var query = from t in db.news
                            where t.id == news.id
                            select new News
                {
                    id           = t.id,
                    title        = t.title,
                    summary      = t.summary,
                    content      = t.content,
                    date         = (DateTime)t.date,
                    categoryName = t.category.name,
                    userNickname = t.user.nickname
                };
                News newsList = query.First();
                return(Json(Result.success(newsList)));
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #4
0
        public JsonResult addNews(news news)
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                if (user.type == 1)
                {
                    news.userId = user.id;
                    news.date   = DateTime.Now;
                    DbNewsDataContext db = new DbNewsDataContext();
                    db.news.InsertOnSubmit(news);
                    db.SubmitChanges();
                    return(Json(Result.success()));
                }
                else
                {
                    return(Json(Result.fail()));
                }
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #5
0
        public JsonResult addUser(user requestData)
        {
            requestData.nickname = requestData.username;
            requestData.type     = 0;
            DbNewsDataContext db = new DbNewsDataContext();

            db.user.InsertOnSubmit(requestData);
            db.SubmitChanges();
            return(Json(Result.success()));
        }
コード例 #6
0
        public JsonResult getCategoryList()
        {
            DbNewsDataContext db = new DbNewsDataContext();
            var query            = from t in db.category
                                   select new Category
            {
                id   = t.id,
                name = t.name,
            };
            List <Category> categoryList = query.ToList();

            return(Json(Result.success(categoryList)));
        }
コード例 #7
0
        public JsonResult addComment(comment comment)
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                comment.userId = user.id;
                comment.status = 0;
                comment.date   = DateTime.Now;
                DbNewsDataContext db = new DbNewsDataContext();
                db.comment.InsertOnSubmit(comment);
                db.SubmitChanges();
                return(Json(Result.success()));
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #8
0
        public JsonResult setUserPassword(User requestData)
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                DbNewsDataContext db = new DbNewsDataContext();
                var query            = from t in db.user
                                       where t.id == user.id
                                       select t;
                foreach (user item in query)
                {
                    item.password = requestData.password;
                    db.SubmitChanges();
                }
                return(Json(Result.success()));
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #9
0
        public JsonResult addCategory(category category)
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                if (user.type == 1)
                {
                    DbNewsDataContext db = new DbNewsDataContext();
                    db.category.InsertOnSubmit(category);
                    db.SubmitChanges();
                    return(Json(Result.success()));
                }
                else
                {
                    return(Json(Result.fail()));
                }
            }
            else
            {
                return(Json(Result.fail()));
            }
        }
コード例 #10
0
        public JsonResult getCommentList(Comment comment)
        {
            DbNewsDataContext db = new DbNewsDataContext();

            if (comment.newsId > 0)
            {
                var query = from t in db.comment
                            where t.newsId == comment.newsId && t.status == comment.status
                            select new Comment
                {
                    id           = t.id,
                    status       = (int)t.status,
                    content      = t.content,
                    date         = (DateTime)t.date,
                    newsTitle    = t.news.title,
                    userNickname = t.user.nickname
                };
                List <Comment> commentList = query.ToList();
                return(Json(Result.success(commentList)));
            }
            else
            {
                var query = from t in db.comment
                            select new Comment
                {
                    id           = t.id,
                    status       = (int)t.status,
                    content      = t.content,
                    date         = (DateTime)t.date,
                    newsTitle    = t.news.title,
                    userNickname = t.user.nickname
                };
                List <Comment> commentList = query.ToList();
                return(Json(Result.success(commentList)));
            }
        }
コード例 #11
0
        public JsonResult getUserInfo()
        {
            User user = (User)Session["user"];

            if (user != null)
            {
                DbNewsDataContext db = new DbNewsDataContext();
                var query            = from t in db.user
                                       where t.id == user.id
                                       select new User
                {
                    id       = t.id,
                    username = t.username,
                    nickname = t.nickname,
                    type     = t.type
                };
                User userQuery = (User)query.First();
                return(Json(Result.success(userQuery)));
            }
            else
            {
                return(Json(Result.fail()));
            }
        }