コード例 #1
0
ファイル: EssaysController.cs プロジェクト: paulcp303/MyBlog
        public HttpResponseMessage DeleteEssay(Essays obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                int i = obj.Delete(" Essayid=@Essayid", obj.Essayid);
                if (i > 0)
                {
                    rh.msg    = "删除文章成功";
                    rh.totals = i;
                }
                else
                {
                    rh.msg  = "删除文章失败";
                    rh.code = 400;
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "服务器错误,请通知管理员";
            }

            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }
コード例 #2
0
ファイル: EssaysController.cs プロジェクト: paulcp303/MyBlog
        public HttpResponseMessage GetEssayItem()
        {
            ReturnHelper rh      = new ReturnHelper(200, null, 0, "");
            string       essayid = HttpContext.Current.Request["essayid"];

            try
            {
                if (string.IsNullOrEmpty(essayid))
                {
                    rh.msg  = "缺少文章id";
                    rh.code = 300;
                }
                else
                {
                    Essays    obj      = new Essays();
                    string    strWhere = string.Format(" Essayid='{0}'", essayid);
                    DataTable dt       = obj.GetPage("*", "Report_Time desc", strWhere, 0, 1);
                    if (dt.Rows.Count > 0)
                    {
                        rh.totals = 1;
                        rh.data   = dt;
                        rh.msg    = "获取成功";
                    }
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "处理错误";
            }

            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }
コード例 #3
0
ファイル: EssaysController.cs プロジェクト: paulcp303/MyBlog
        public HttpResponseMessage UpdateEssay(Essays obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                obj.Update_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                obj.Ip          = IPHelper.GetHostIP();
                obj.Address     = IPHelper.GetHostAddress(obj.Ip);
                int i = obj.Update(" Essayid=@Essayid", obj.Essayid);
                if (i > 0)
                {
                    rh.msg    = "更新文章成功";
                    rh.totals = i;
                }
                else
                {
                    rh.msg  = "更新文章失败";
                    rh.code = 400;
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "服务器错误,请通知管理员";
            }

            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }
コード例 #4
0
        //
        // GET: /TimeConsole/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Essays essays = db.Essays.Find(id);

            if (essays == null)
            {
                return(HttpNotFound());
            }
            string initialPreview             = "";
            IList <InitialPreviewConfig> list = new List <InitialPreviewConfig>();

            if (!string.IsNullOrEmpty(essays.imgurls))
            {
                int i = 1;
                foreach (var img in essays.imgurls.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    list.Add(new InitialPreviewConfig(i, "/assets/ueditor/net/controller.ashx?action=deletefile", new DataExtra(img)));
                    initialPreview += "<img src='" + img + "' class='file-preview-image'>|";
                }
                initialPreview = initialPreview.Substring(0, initialPreview.Length - 1);
                i++;
            }
            ViewBag.initialPreview       = initialPreview;
            ViewBag.initialPreviewConfig = JsonConvert.SerializeObject(list);
            return(View(essays));
        }
コード例 #5
0
 public ActionResult Edit(Essays essays)
 {
     if (ModelState.IsValid)
     {
         db.Entry(essays).State = EntityState.Modified;
         essays.publishTime     = DateTime.Now;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(essays));
 }
コード例 #6
0
        public string Delete(int id = 0)
        {
            Essays essays = db.Essays.Find(id);

            if (essays == null)
            {
                return("F");
            }
            db.Essays.Remove(essays);
            db.SaveChanges();
            return("S");
        }
コード例 #7
0
        public ActionResult Create(Essays essays)
        {
            if (ModelState.IsValid)
            {
                var temp = db.Essays.Select(s => s.orderNum).Max();
                essays.orderNum    = temp + 1;
                essays.publishTime = DateTime.Now;
                db.Essays.Add(essays);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(essays));
        }
コード例 #8
0
ファイル: EssaysController.cs プロジェクト: paulcp303/MyBlog
        public HttpResponseMessage GetEssaysPage()
        {
            ReturnHelper rh    = new ReturnHelper(200, null, 0, "");
            string       key   = HttpContext.Current.Request["key"];
            string       limit = HttpContext.Current.Request["limit"];
            string       page  = HttpContext.Current.Request["page"];

            try
            {
                if (string.IsNullOrEmpty(limit) || string.IsNullOrEmpty(page))
                {
                    rh.msg  = "缺少分页参数";
                    rh.code = 300;
                }
                else
                {
                    Essays obj      = new Essays();
                    string strWhere = " 1=1";
                    if (!string.IsNullOrEmpty(key))
                    {
                        strWhere += string.Format(" and (Essay_Type like '%{0}%' or Essay_Title like '%{0}%' or Essay_Label like '%{0}%')", key);
                    }
                    int       begin = (Convert.ToInt32(page) - 1) * Convert.ToInt32(limit);
                    int       end   = Convert.ToInt32(page) * Convert.ToInt32(limit);
                    DataTable dt    = obj.GetPage("*", "Report_Time desc", strWhere, begin, end);
                    if (dt.Rows.Count > 0)
                    {
                        rh.totals = SqlHelper.Count(string.Format("select count(*) from Essays where {0}", strWhere), SqlHelper.CreateConn());
                        rh.data   = dt;
                        rh.msg    = "获取成功";
                    }
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "处理错误";
            }
            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }
コード例 #9
0
ファイル: EssaysController.cs プロジェクト: paulcp303/MyBlog
        public HttpResponseMessage ViewEssay(Essays obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                string selectsql = string.Format(" select Views from Essays where Essayid='{0}'", obj.Essayid);
                string times     = SqlHelper.ShowData(selectsql, "Views", SqlHelper.CreateConn());
                if (!string.IsNullOrEmpty(times))
                {
                    obj.Views = Convert.ToInt32(times) + 1;//访问次数+1
                }
                else
                {
                    obj.Views = 1;//第一次访问
                }
                int i = obj.Update(" Essayid=@Essayid", obj.Essayid);
                if (i > 0)
                {
                    rh.msg    = "查看成功";
                    rh.totals = i;
                }
                else
                {
                    rh.msg  = "查看次数更新失败";
                    rh.code = 400;
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "服务器错误,请通知管理员";
            }

            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }