Beispiel #1
0
        public ActionResult Details(long myid)
        {
            TeacherArticleModel myArticlDataContent = new TeacherArticleModel();

            //
            using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities())//数据库操作
            {
                Teacher_Article myTable           = myOperating.Teacher_Article.FirstOrDefault(p => p.ArticlId == myid && p.Status == 200);
                DataMethodClass myDataMethodClass = new DataMethodClass();
                if (myTable != null)
                {
                    myArticlDataContent.ArticlId     = myid;
                    myArticlDataContent.ArticleTitle = myTable.ArticleTitle;
                    if (!String.IsNullOrWhiteSpace(myTable.ArticleImages))
                    {
                        myArticlDataContent.ArticleImages = StaticVarClass.myDomain + myTable.ArticleImages;
                    }
                    if (!String.IsNullOrWhiteSpace(myTable.ArticleVideo))
                    {
                        myArticlDataContent.ArticleVideo = StaticVarClass.myDomain + myTable.ArticleVideo;
                    }
                    DateTime myDateTime = DateTime.Now;
                    DateTime.TryParse(myTable.AddDate.ToString(), out myDateTime);
                    myArticlDataContent.AddDate        = myDateTime;
                    myArticlDataContent.ArticleAuthor  = myTable.ArticleAuthor;
                    myArticlDataContent.ArticleContent = myTable.ArticleContent;
                    myArticlDataContent.CommentCount   = myOperating.Teacher_Article_Comment.Count(p => p.AboutId == myid);
                    myArticlDataContent.ReadTimes      = myTable.ReadTimes;
                    //
                    #region 阅读次数加一
                    if (myTable.ReadTimes != null)
                    {
                        myTable.ReadTimes = myTable.ReadTimes + 1;
                    }
                    else
                    {
                        myTable.ReadTimes = 1;
                    }
                    myOperating.SaveChanges();
                    #endregion
                }
            }
            return(View(myArticlDataContent));
        }
Beispiel #2
0
        //
        #region 文章添加-编辑
        public ActionResult TeacherCommunityAdd(TeacherArticleModel model, string ReturnUrl, Nullable <long> myid = 0, int ClassId = 0)
        {
            #region 获取来路路径
            if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
            {
                ViewBag.ReturnUrl = System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery;
            }
            #endregion
            ViewBag.Headline    = "文章添加";                                         //栏目主题
            ViewBag.ButtonValue = "添加";                                           //按钮名称
            //
            using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
            {
                if ((myid > 0) && (model.Operate == null))
                {
                    long mySelfId = 0;
                    long.TryParse(myid.ToString(), out mySelfId);
                    ViewBag.Headline    = "文章编辑";
                    ViewBag.ButtonValue = "修改";
                    model.Operate       = "edit";
                    //
                    #region 取出数据
                    Teacher_Article editRecord = myOperating.Teacher_Article.FirstOrDefault(p => p.ArticlId == mySelfId);
                    if (editRecord != null)
                    {
                        ClassId              = editRecord.ClassId;
                        model.ArticlId       = editRecord.ArticlId;
                        model.ClassId        = editRecord.ClassId;
                        model.ArticleTitle   = editRecord.ArticleTitle;
                        model.ArticleAuthor  = editRecord.ArticleAuthor;
                        model.ArticleSummary = editRecord.ArticleSummary;
                        model.ArticleImages  = editRecord.ArticleImages;
                        model.ArticleVideo   = editRecord.ArticleVideo;
                        model.ArticleContent = editRecord.ArticleContent;
                        model.OrderBy        = editRecord.OrderBy;
                    }
                    #endregion
                }
                else if (model.Operate == "add")
                {
                    #region 保存添加
                    if (ModelState.IsValid)
                    {
                        Teacher_Article addRecord = new Teacher_Article();
                        addRecord.ClassId        = model.ClassId;
                        addRecord.ArticleTitle   = model.ArticleTitle;
                        addRecord.ArticleAuthor  = model.ArticleAuthor;
                        addRecord.ArticleSummary = model.ArticleSummary;
                        addRecord.ArticleImages  = model.ArticleImages;
                        addRecord.ArticleVideo   = model.ArticleVideo;
                        addRecord.ArticleContent = model.ArticleContent;
                        addRecord.OrderBy        = model.OrderBy;
                        addRecord.AddDate        = DateTime.Now;
                        addRecord.ArticleDate    = DateTime.Now;
                        addRecord.ReadTimes      = 0;
                        addRecord.PraiseCount    = 0;
                        addRecord.Status         = 200;
                        //
                        myOperating.Teacher_Article.Add(addRecord);
                        myOperating.SaveChanges();
                        //
                        return(RedirectToLocal(ReturnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("", "输入错误");
                    }
                    #endregion
                }
                else if (model.Operate == "edit")
                {
                    //
                    #region 保存编辑
                    if (ModelState.IsValid)
                    {
                        Teacher_Article editSaveRecord = myOperating.Teacher_Article.FirstOrDefault(p => p.ArticlId == model.ArticlId);
                        if (editSaveRecord != null)
                        {
                            editSaveRecord.ClassId        = model.ClassId;
                            editSaveRecord.ArticleTitle   = model.ArticleTitle;
                            editSaveRecord.ArticleAuthor  = model.ArticleAuthor;
                            editSaveRecord.ArticleSummary = model.ArticleSummary;
                            editSaveRecord.ArticleImages  = model.ArticleImages;
                            editSaveRecord.ArticleVideo   = model.ArticleVideo;
                            editSaveRecord.ArticleContent = model.ArticleContent;
                            editSaveRecord.OrderBy        = model.OrderBy;
                            //
                            myOperating.SaveChanges();
                            //
                            return(RedirectToLocal(ReturnUrl));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "输入错误");
                    }
                    #endregion
                }
                else
                {                            //初次加载-添加
                    model.ClassId = ClassId; //类别编号
                    model.Operate = "add";
                    #region 默认值
                    try
                    {
                        if (ClassId != 0)
                        {
                            model.OrderBy = myOperating.Teacher_Article.Where(p => p.ClassId == ClassId).Max(p => p.OrderBy) + 1;
                        }
                        else
                        {
                            model.OrderBy = myOperating.Teacher_Article.Max(p => p.OrderBy) + 1;
                        }
                    }
                    catch
                    {
                        model.OrderBy = 0;
                    }
                    if (model.OrderBy == null)
                    {
                        model.OrderBy = 1;
                    }
                    #endregion
                }
                #region 教师社区类别

                List <Teacher_Article_Class> ClassTable = myOperating.Teacher_Article_Class.Where(p => p.Status == 200).ToList();
                ViewBag.DataListClass = ClassTable;
                #endregion
            }
            //
            return(View(model));
        }