/// <summary> /// 更新分类 /// </summary> public string EditNovelCategory(NovelCategory category) { string result = "更新失败"; var conn = DBRepository.GetSqlConnection(); try { conn.Open(); if (category != null) { if (!string.IsNullOrEmpty(category.Id) && !string.IsNullOrEmpty(category.Name) && category.Sort > 0) { if (DBRepository.Update<NovelCategory>(category, "Id", conn)) { result = "success"; } } } else { result = "category对象为空"; LogService.Log("NovelService.EditNovelCategory", "category对象为空"); } } catch (Exception e) { result = "程序出现异常,详情见日志"; LogService.Log("更新分类", e.ToString()); } finally { conn.Close(); } return result; }
public ActionResult EditCategory(NovelCategory category) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } if (category != null) { if (!string.IsNullOrEmpty(category.Id) && !string.IsNullOrEmpty(category.Name) && category.Sort > 0) { category.IsActive = true; NovelService novelService = new NovelService(); novelService.EditNovelCategory(category); } } return Redirect(Request.UrlReferrer.AbsoluteUri); }
/// <summary> /// 添加分类(成功返回success) /// </summary> public string AddNovelCategory(NovelCategory category) { string result = "添加失败"; var conn = DBRepository.GetSqlConnection(); try { conn.Open(); if (category != null) { if (!string.IsNullOrEmpty(category.Id) && !string.IsNullOrEmpty(category.Name) && category.Sort > 0) { NovelCategory temp = DBRepository.SelectOne<NovelCategory>("Id", category.Id, conn); conn.Close(); conn.Open(); if (temp == null) { category.IsActive = true; if (DBRepository.Insert<NovelCategory>(category, conn)) { result = "success"; } } } } else { result = "category对象为空"; LogService.Log("NovelService.AddNovelCategory", "category对象为空"); } } catch (Exception e) { result = "程序出现异常,详情见日志"; LogService.Log("添加分类", e.ToString()); } finally { conn.Close(); } return result; }