Esempio n. 1
0
        public ActionResult Add(News news)
        {
            string result = "发布失败";

            if (Session["UserId"] == null)
            {
                return Content("长时间未操作,请重新登录。");
            }

            if (news == null)
            {
                result = "参数为空";
            }
            else
            {
                if (!string.IsNullOrEmpty(news.Title) &&
                    !string.IsNullOrEmpty(news.CategoryId) &&
                    !string.IsNullOrEmpty(news.ContentStyle))
                {
                    news.ContentText = news.ContentStyle;
                    news.InsertTime = DateTime.Now;
                    news.UpdateTime = news.InsertTime;
                    news.ViewCount = 0;
                    news.IsActive = true;
                    NewsService newsService = new NewsService();
                    result = newsService.AddNews(news);
                }
                else
                {
                    result = "必填项 [标题、分类、内容] 不能为空";
                }
            }

            return Content(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 发布新闻(成功返回success)
        /// </summary>
        public string AddNews(News news)
        {
            string result = "发布失败";

            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (news != null)
                {
                    if (!string.IsNullOrEmpty(news.Title) &&
                        !string.IsNullOrEmpty(news.CategoryId) &&
                        !string.IsNullOrEmpty(news.ContentStyle))
                    {
                        List<string> filterColumns = new List<string>() { "Id" };
                        if (DBRepository.Insert<News>(news, conn, filterColumns))
                        {
                            result = "success";
                        }
                    }
                    else
                    {
                        result = "标题,分类,内容必须有值";
                        LogService.Log("NewsService.AddNews", "news非空属性没赋值");
                    }
                }
                else
                {
                    result = "新闻对象不能为空";
                    LogService.Log("NewsService.AddNews", "news对象为空");
                }
            }
            catch (Exception e)
            {
                result = "程序出现异常,详情见日志";
                LogService.Log("发布新闻", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Esempio n. 3
0
        /// <summary>
        /// 更新新闻(成功返回success)
        /// </summary>
        public string EditNews(News news)
        {
            string result = "更新失败";

            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (news != null)
                {
                    if (!string.IsNullOrEmpty(news.Title) &&
                        !string.IsNullOrEmpty(news.CategoryId) &&
                        !string.IsNullOrEmpty(news.ContentStyle))
                    {
                        if (DBRepository.Update<News>(news, "Id", conn))
                        {
                            result = "success";
                        }
                    }
                    else
                    {
                        result = "标题,分类,内容必须有值";
                        LogService.Log("NewsService.EditNews", "news非空属性没赋值");
                    }
                }
                else
                {
                    result = "新闻对象不能为空";
                    LogService.Log("NewsService.EditNews", "news对象为空");
                }
            }
            catch (Exception e)
            {
                result = "程序出现异常,详情见日志";
                LogService.Log("更新失败", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Esempio n. 4
0
        public ActionResult Edit(News news)
        {
            string result = "更新失败";

            if (Session["UserId"] == null)
            {
                return Content("长时间未操作,请重新登录。");
            }

            if (news == null)
            {
                result = "参数为空";
            }
            else
            {
                if (!string.IsNullOrEmpty(news.Title) &&
                    !string.IsNullOrEmpty(news.CategoryId) &&
                    !string.IsNullOrEmpty(news.ContentStyle))
                {
                    news.ContentText = news.ContentStyle;
                    news.UpdateTime = DateTime.Now;
                    news.IsActive = true;

                    if (news.Keywords == null)
                    {
                        news.Keywords = string.Empty;
                    }
                    if (news.Description == null)
                    {
                        news.Description = string.Empty;
                    }
                    if (news.Author == null)
                    {
                        news.Author = string.Empty;
                    }
                    if (news.ComeFrom == null)
                    {
                        news.ComeFrom = string.Empty;
                    }
                    if (news.Cover == null)
                    {
                        news.Cover = string.Empty;
                    }
                    if (news.PictureGroup == null)
                    {
                        news.PictureGroup = string.Empty;
                    }

                    NewsService newsService = new NewsService();
                    result = newsService.EditNews(news);
                }
                else
                {
                    result = "必填项 [标题、分类、内容] 不能为空";
                }
            }

            return Content(result);
        }