Пример #1
0
        public ActionResult Add(Novel novel)
        {
            string result = "发布失败";

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

            if (novel == null)
            {
                result = "参数为空";
            }
            else
            {
                if (!string.IsNullOrEmpty(novel.Title) &&
                    !string.IsNullOrEmpty(novel.CategoryId) &&
                    !string.IsNullOrEmpty(novel.Name))
                {
                    novel.ArticleCount = 0;
                    novel.InsertTime = DateTime.Now;
                    novel.ViewTime = 0;
                    novel.IsDelete = false;
                    NovelService novelService = new NovelService();
                    result = novelService.AddNovel(novel);
                }
                else
                {
                    result = "必填项 [标题、分类、名称、作者] 不能为空";
                }
            }

            return Content(result);
        }
Пример #2
0
        public ActionResult Edit(Novel novel)
        {
            string result = "更新失败";

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

            if (novel == null)
            {
                result = "参数为空";
            }
            else
            {
                if (!string.IsNullOrEmpty(novel.Title) &&
                    !string.IsNullOrEmpty(novel.CategoryId) &&
                    !string.IsNullOrEmpty(novel.Name))
                {
                    NovelService novelService = new NovelService();

                    Novel oldNovel = novelService.GetNovelById(novel.Id);
                    if (oldNovel != null)
                    {
                        oldNovel.CategoryId = string.IsNullOrEmpty(novel.CategoryId) ? string.Empty : novel.CategoryId;
                        oldNovel.Title = string.IsNullOrEmpty(novel.Title) ? string.Empty : novel.Title;
                        oldNovel.Keywords = string.IsNullOrEmpty(novel.Keywords) ? string.Empty : novel.Keywords;
                        oldNovel.Description = string.IsNullOrEmpty(novel.Description) ? string.Empty : novel.Description;
                        oldNovel.Name = string.IsNullOrEmpty(novel.Name) ? string.Empty : novel.Name;
                        oldNovel.Author = string.IsNullOrEmpty(novel.Author) ? string.Empty : novel.Author;
                        result = novelService.EditNovel(novel);
                    }
                }
                else
                {
                    result = "必填项 [标题、分类、名称、作者] 不能为空";
                }
            }

            return Content(result);
        }
Пример #3
0
        /// <summary>
        /// 更新小说
        /// </summary>
        public string EditNovel(Novel novel)
        {
            string result = "更新失败";

            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (novel != null)
                {
                    if (!string.IsNullOrEmpty(novel.Title) &&
                    !string.IsNullOrEmpty(novel.CategoryId) &&
                    !string.IsNullOrEmpty(novel.Name))
                    {
                        if (DBRepository.Update<Novel>(novel, "Id", conn))
                        {
                            result = "success";
                        }
                    }
                }
                else
                {
                    result = "category对象为空";
                    LogService.Log("NovelService.EditNovel", "novel对象为空");
                }
            }
            catch (Exception e)
            {
                result = "程序出现异常,详情见日志";
                LogService.Log("更新失败", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Пример #4
0
        /// <summary>
        /// 获取小说
        /// </summary>
        public Novel GetNovelById(int id)
        {
            Novel result = new Novel();
            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                result = DBRepository.SelectOne<Novel>("Id", id, conn);
                if (result != null)
                {
                    DBRepository.UpdateOneColumn<Novel>("ViewTime", result.ViewTime + 1, "Id=" + result.Id.ToString(), conn);
                    result.Category = DBRepository.SelectOne<NovelCategory>("Id", result.CategoryId, conn);
                    if (result.Category == null)
                    {
                        result.Category = new NovelCategory();
                        result.Category.Id = result.CategoryId;
                    }
                }

            }
            catch (Exception e)
            {
                LogService.Log("获取小说", e.ToString());
            }
            finally
            {
                conn.Close();
            }
            return result;
        }
Пример #5
0
        /// <summary>
        /// 发布小说
        /// </summary>
        public string AddNovel(Novel novel)
        {
            string result = "添加失败";

            var conn = DBRepository.GetSqlConnection();
            try
            {
                conn.Open();
                if (novel != null)
                {
                    if (!string.IsNullOrEmpty(novel.Title) &&
                    !string.IsNullOrEmpty(novel.CategoryId) &&
                    !string.IsNullOrEmpty(novel.Name))
                    {
                        List<string> filterColumns = new List<string>() { "Id" };
                        if (DBRepository.Insert<Novel>(novel, conn, filterColumns))
                        {
                            result = "success";
                        }
                    }
                }
                else
                {
                    result = "category对象为空";
                    LogService.Log("NovelService.AddNovel", "novel对象为空");
                }
            }
            catch (Exception e)
            {
                result = "程序出现异常,详情见日志";
                LogService.Log("添加分类", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }