Example #1
0
        /// <summary>
        /// 根据ID获取文章实体对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetArticleByID(int id)
        {
            Article res = ArticleMgr.GetArticleByID(id);

            //return Json(JsonConvert.SerializeObject(res, Config.FULL_DATE_FORMAT));
            return(Json(res));
        }
Example #2
0
        public void GetArticles(HttpContext context)
        {
            List <Article> list = ArticleMgr.GetArticles();

            //拼接json字符串
            StringBuilder builder = new StringBuilder();

            builder.Append("[");//[

            foreach (Article item in list)
            {
                builder.Append("{");// { 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },
                builder.AppendFormat("\"ID\":\"{0}\",\"Cate_Name\":\"{1}\",\"Title\":\"{2}\",\"Content\":\"{3}\",\"Update_Time\":\"{4}\",\"User_Name\":\"{5}\"",
                                     item.ID, item.Cate_Name, item.Title, item.Content, item.Update_Time.ToString(), item.User_Name);
                builder.Append("},");
            }

            // [{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },
            // [{ 'name':'jack','age':12 },{ 'name':'jack','age':12 },{ 'name':'jack','age':12 }]
            context.Response.Write(builder.ToString().Substring(0, builder.ToString().Length - 1) + "]");

            // "123,"->"1234"

            /*string str = "123,";
             * str.Substring(0, 3);//123
             * str.Substring(0, str.Length - 1) + "4";
             */
        }
Example #3
0
        /// <summary>
        /// 查看文章页面
        /// </summary>
        /// <returns></returns>
        public ActionResult ArticlesView()
        {
            List <Article> list = ArticleMgr.GetArticles();

            ViewBag.ArticleList = list;
            return(View());
        }
Example #4
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pp"></param>
        /// <param name="title"></param>
        /// <param name="cateid"></param>
        /// <returns></returns>
        public JsonResult GetArticleByPager(PageParam pp, string title, int cateid = -1)
        {
            var             res   = ArticleMgr.GetArticlesByPager(cateid, title, pp);
            LayUITableModel model = new LayUITableModel(res.Total, res.Rows);

            return(Json(model));
        }
Example #5
0
        public void AddArticle(HttpContext context)
        {
            string cateid  = context.Request["cateid"];
            string title   = context.Request["title"];
            string content = context.Request["content"];

            Article entity = new Article();

            entity.Cate_id = int.Parse(cateid);
            entity.Title   = title;
            entity.Content = content;

            entity.Update_Time = DateTime.Now;
            //从session中获取当前用户
            User curUser = context.Session["CurUser"] as User;

            entity.Create_User = curUser.ID;

            bool res = ArticleMgr.Add(entity);

            if (res)
            {
                context.Response.Write("{\"status\":true}");
            }
            else
            {
                context.Response.Write("{\"status\":false}");
            }
        }
Example #6
0
 public void LoadDBData(List <DBBaseAlert> data)
 {
     if (data == null)
     {
         return;
     }
     foreach (var item in data)
     {
         if (item.Type == AlertType.Continue)
         {
             continue;
         }
         var alert = Add(item.TDID, GetEntity(item.Cast));
         alert.TipStr               = item.TipStr;
         alert.DetailStr            = item.DetailStr;
         alert.TitleStr             = item.TitleStr;
         alert.Illustration         = item.Illustration;
         alert.CurTurn              = item.CurTurn;
         alert.ID                   = item.ID;
         alert.IsCommingTimeOutFalg = item.IsCommingTimeOutFalg;
         alert.StartSFX             = item.StartSFX;
         alert.IsAutoTrigger        = item.IsAutoTrigger;
         alert.Bg                   = item.Bg;
         alert.Icon                 = item.Icon;
         alert.WarfareData          = RelationMgr.GetWarfareData <IBaseWarfareData>(item.War);
         item.SelfArticle.ForEach(x => alert.SelfArticle.Add(ArticleMgr.Get <TDBaseArticleData>(x)));
         item.TargetArticle.ForEach(x => alert.TargetArticle.Add(ArticleMgr.Get <TDBaseArticleData>(x)));
     }
 }
Example #7
0
        public ActionResult SubmitArticleComments(int id, string content)
        {
            if (string.IsNullOrEmpty(content) == true)
            {
                return(Content("评论内容不可为空。"));
            }

            var obj = new article_comments()
            {
                article_id = id,
                comments   = content,
                user_id    = CurrentUser.id,
                user_name  = CurrentUser.name,
                created_dt = DateTime.Now
            };

            ArticleMgr.InsertArticleComments(obj);

            #region 发送消息通知给相关用户(apply user和comments user)
            var temp_user_list = new List <int>();

            var article = ArticleMgr.GetArticle(id);
            if (CurrentUser.id != article.article_apply.apply_user_id) // 不应该通知本人
            {
                var msg = new message()
                {
                    title                 = "文章讨论",
                    message_content       = string.Format("我回复了您发布的文章《{0}》:{1}", article.title, content),
                    message_sender_id     = CurrentUser.id,
                    message_sender_name   = CurrentUser.name,
                    message_receiver_id   = article.article_apply.apply_user_id,
                    message_receiver_name = article.article_apply.apply_user_name,
                };
                SystemMgr.InsertMessage(msg);
                temp_user_list.Add(msg.message_receiver_id);
            }
            foreach (var comments in article.article_comments.Where(t => t.user_id != CurrentUser.id)) // 通知其他用户
            {
                if (temp_user_list.Contains(comments.user_id) == true)                                 // 不重复通知同一个用户(回复多次的)
                {
                    continue;
                }

                var msg2 = new message()
                {
                    title                 = "文章讨论",
                    message_content       = string.Format("我回复您参与讨论的文章《{0}》:{1}", article.title, content),
                    message_sender_id     = CurrentUser.id,
                    message_sender_name   = CurrentUser.name,
                    message_receiver_id   = comments.user_id,
                    message_receiver_name = comments.user_name,
                };
                SystemMgr.InsertMessage(msg2);
                temp_user_list.Add(msg2.message_receiver_id);
            }
            #endregion

            return(Content("OK"));
        }
Example #8
0
        /// <summary>
        /// 操作
        /// </summary>
        static void SwitchOperate()
        {
            while (true)
            {
                Console.WriteLine("====================================");
                Console.WriteLine("请选择对应的操作:");
                Console.WriteLine("1、新增类别");
                Console.WriteLine("2、删除类别");
                Console.WriteLine("3、查看类别");

                Console.WriteLine("4、发布文章");
                Console.WriteLine("5、更新文章");
                Console.WriteLine("6、查看文章");
                Console.WriteLine("7、删除文章");

                Console.WriteLine("0、退出");

                string keyCode = Console.ReadLine();
                switch (keyCode)
                {
                case "1":
                    CategoryMgr.AddCategoryConsole();
                    break;

                case "2":
                    CategoryMgr.DeleteCategoryConsole();
                    break;

                case "3":
                    CategoryMgr.ShowCategoryConsole();
                    break;

                case "4":
                    ArticleMgr.AddConsole();
                    break;

                case "5":
                    ArticleMgr.UpdateConsole();
                    break;

                case "6":
                    ArticleMgr.ShowConsole();
                    break;

                case "7":
                    ArticleMgr.RemoveConsole();
                    break;

                case "0":
                    return;

                default:
                    Console.WriteLine("输入有误");
                    break;
                }
            }
        }
Example #9
0
        public void TestGetArticleByPager()
        {
            PageParam pp = new PageParam()
            {
                PageIndex = 2, PageSize = 10
            };
            var res = ArticleMgr.GetArticlesByPager(-1, "linux", pp);

            Assert.IsTrue(res.Total > 0);
        }
Example #10
0
        /// <summary>
        /// 显示学术文章详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(int id)
        {
            ViewBag.CurrentUser = CurrentUser;
            if (CurrentUser != null)
            {
                ViewBag.Collection = AccountMgr.GetUserCollection(CurrentUser.id, ContentType.文章, id);
            }
            var obj = ArticleMgr.GetArticle(id);

            return(View("Detail", obj));
        }
Example #11
0
        public ResponseListModel <article> GetArticleList(ReqArticleEn en)
        {
            var reVal = new ResponseListModel <article>();

            try
            {
                reVal = new ArticleMgr().GetArticleList(en);
            }
            catch (Exception ex)
            {
                reVal.Success = false;
                reVal.Message = ex.Message;
            }
            return(reVal);
        }
Example #12
0
        /// <summary>
        /// 获取文章列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetArticles()
        {
            List <Article> list = ArticleMgr.GetArticles();

            //默认的序列化,时间格式会有问题
            //return Json(list);

            //string jsonStr = JsonConvert.SerializeObject(list, Config.FULL_DATE_FORMAT);
            //return Json(jsonStr);

            //使用layui table的方式
            LayUITableModel res = new LayUITableModel(list.Count, list);

            return(Json(res));
        }
Example #13
0
        public ActionResult Detail(int id)
        {
            article reVal = null;
            var     art   = new ArticleMgr().GetArticle(id);

            if (art.Success && art.Item != null)
            {
                reVal         = art.Item;
                ViewBag.Title = art.Item.title;
            }
            var next = new Business.Article.ArticleMgr().GetNextArticle(id);

            ViewBag.nextid = next.Item.aid;
            ViewBag.title  = next.Item.title;
            return(View(reVal));
        }
Example #14
0
        /// <summary>
        /// 保存文章 新增/修改
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public JsonResult SaveArticle(Article article)
        {
            bool res = false;

            article.Update_Time = DateTime.Now;
            article.Create_User = ContextObjects.CurrentUser.ID;

            //id为-1时,即新增
            if (article.ID == -1)
            {
                res = ArticleMgr.Add(article);
            }
            else
            {
                res = ArticleMgr.Update(article);
            }
            return(Json(res));
        }
Example #15
0
 public void Remove(TData alert)
 {
     if (alert == null)
     {
         return;
     }
     alert.OnBeRemoved();
     Data.Remove(alert);
     if (alert.Type == AlertType.Interaction)
     {
         InteractionData.Remove(alert);
         Callback_OnInteractionChange?.Invoke(alert);
     }
     else if (alert.Type == AlertType.Disposable)
     {
         DisposableData.Remove(alert);
         Callback_DisposableChange?.Invoke(alert);
     }
     else if (alert.Type == AlertType.Continue)
     {
         ContinueData.Remove(alert);
         Callback_ContinueChange?.Invoke(alert);
     }
     //移除Article
     foreach (var item in alert.SelfArticle)
     {
         ArticleMgr.RemoveArticle(item);
     }
     foreach (var item in alert.TargetArticle)
     {
         ArticleMgr.RemoveArticle(item);
     }
     if (BaseGlobal.IsUnReadData)
     {
         Callback_OnRemoved?.Invoke(alert);
     }
 }
Example #16
0
        public ActionResult SubmitArticle([Bind] article article, HttpPostedFileBase file)
        {
            // 判断 文章标题是否为空
            if (string.IsNullOrEmpty(article.title) == true)
            {
                return(Content("文章标题不可为空"));
            }

            // 判断 是否选择了文章附件
            else if (file == null)
            {
                return(Content("未选择文章附件"));
            }

            else
            {
                // 判断文章的文件类型,支持 pdf/caj/doc/docx 格式  //by XW

                /*
                 * var ext = System.IO.Path.GetExtension(file.FileName);
                 * if ((ext != ".pdf") & (ext != ".caj") & (ext != ".doc") & (ext != ".docx"))
                 * {
                 *  return Content("文章附件格式有误,请重新选择,支持 pdf/caj/doc/docx 格式");
                 * }
                 */

                // 判断文章的文件大小,支持小于20MB的

                /*var filesize = file.ContentLength;
                 * if (filesize >= 20971520)
                 * {
                 *  return Content("文章附件过大,请选择20MB以下的文件");
                 * }*/

                // 先添加发表文章申请
                var apply = new article_apply()
                {
                    apply_user_id   = CurrentUser.id,
                    apply_user_name = CurrentUser.name,
                    apply_status    = ArticleApplyStatusType.待审批, // 设置为待审批状态 by XW
                    apply_dt        = DateTime.Now,
                };
                apply = ArticleMgr.InsertArticleApply(apply);

                // 记录申请信息
                article.apply_id = apply.id;

                article.publish_dt = DateTime.Now; // 只是为了避免数据库错误

                // 处理附件信息
                article.file_path = file.FileName;
                article.file_size = file.ContentLength;
                article.file_type = file.ContentType;


                ArticleMgr.InsertArticle(article); // 保存文章记录,为了获取id

                // 保存附件到服务器文件夹
                var folder = "~/FileUpload/article/" + article.id.ToString() + "/";
                System.IO.Directory.CreateDirectory(Server.MapPath(folder));
                file.SaveAs(Server.MapPath(folder + file.FileName));

                return(Content("OK"));
            }
        }
Example #17
0
 public ActionResult DeleteArticleComments(int id, int comments_id)
 {
     ArticleMgr.DeleteArticleComments(comments_id);
     return(Content("OK"));
 }
Example #18
0
        /// <summary>
        /// 显示学术文章列表
        /// </summary>
        /// <returns></returns>
        public ActionResult ArticleList()
        {
            var all = ArticleMgr.GetArticles();

            return(View(all));
        }
Example #19
0
        private TData Add(string tdid, BaseUnit cast = null, Callback <TData> action = null, bool isAutoTrigger = false)
        {
            if (!TDLuaMgr.Contains(tdid))
            {
                if (CommonAlert == tdid)
                {
                    CLog.Error("没有:{0},请手动添加CommonAlert", tdid);
                }
                else
                {
                    CLog.Error("没有:{0},请手动添加Alert", tdid);
                }
                return(null);
            }

            TData sourceAlert = TDLuaMgr.Get <TData>(tdid);

            sourceAlert.Cast     = cast ? cast : LocalPlayer;
            sourceAlert.AlertMgr = this;

            //判断通知是否可以被合并
            var finalAlert = CanMerge(sourceAlert);

            if (finalAlert != null)
            {
                finalAlert.OnMerge();
                Callback_OnMerge?.Invoke(finalAlert);
            }
            else
            {
                finalAlert    = sourceAlert.Copy <TData>();
                finalAlert.ID = IDUtil.Gen();
                finalAlert.OnBeAdded(SelfBaseUnit);
                Data.Add(finalAlert);
                if (finalAlert.Type == AlertType.Interaction)
                {
                    //推送最近一次的谈判信息
                    if (ArticleMgr.IsStarNegotiation)
                    {
                        ArticleMgr.PushNagotiationToAlert(finalAlert);
                    }
                    InteractionData.Add(finalAlert);
                    Callback_OnInteractionChange?.Invoke(finalAlert);
                }
                else if (finalAlert.Type == AlertType.Disposable)
                {
                    DisposableData.Add(finalAlert);
                    Callback_DisposableChange?.Invoke(finalAlert);
                }
                else if (finalAlert.Type == AlertType.Continue)
                {
                    ContinueData.Add(finalAlert);
                    Callback_ContinueChange?.Invoke(finalAlert);
                }
                action?.Invoke(finalAlert);
                if (BaseGlobal.IsUnReadData)
                {
                    Callback_OnAdded?.Invoke(finalAlert);
                }
            }
            if (finalAlert.IsAutoTrigger || isAutoTrigger)
            {
                finalAlert.DoLeftClickTrigger();
            }
            return(finalAlert);
        }
Example #20
0
        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult RemoveArticle(int id)
        {
            var res = ArticleMgr.Remove(id);

            return(Json(res));
        }
Example #21
0
        public void TestGetArticlesEF()
        {
            var res = ArticleMgr.GetArticlesEF(-1, "");

            Assert.IsNotNull(res);
        }