public ActionResult Create(ModelArticle model, FormCollection fc) { ViewBag.Categorys = QueryCategoryAll(model.Categoryid.ToString()); ViewBag.CategorysTwo = QueryCategoryAll(model.CategoryTwo); var result = new ResultBase(); var resultMsg = string.Empty; var fileName = CommonMethod.ImageUpload(out result, this.HttpContext); if (result.result == -2) { ViewBag.CustomScript = UtilityScript.ShowMessage(result.resultMsg, isCreate: true); return View(model); } model.Context = fc["editorValue"]; model.Thumbnails = string.IsNullOrWhiteSpace(fileName) ? model.Thumbnails : fileName; model.Status = Convert.ToInt32(model.IsPermission); model.Isrecommend = Convert.ToInt32(model.IsRec); LogicArticle artDal = new LogicArticle(); var res = artDal.ArticleInsertUpdate(out resultMsg, model); if (res > 0) { resultMsg = "操作成功!"; ViewBag.CustomScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: true, funName: "Goto"); } else { resultMsg = "操作失败,请检查数据是否正确后重新操作!"; ViewBag.CustomScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: true, funName: "BtnShow"); } return View(model); }
/// <summary> /// ��ѯʵ�� /// </summary> /// <param name="id">ModelId ���</param> /// <returns>ModelArticle</returns> public ModelArticle ArticleDetail(out string resultMsg,Int32 id ) { resultMsg = string.Empty; var model = new ModelArticle(); try { //�洢�������� string sql = "USP_ARTICLE_SELECT_DETAIL_BY_ID"; //������� IList<DBParameter> parm = new List<DBParameter>(); parm.Add(new DBParameter() { ParameterName = "ID", ParameterValue = id, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); //��ѯִ�� using (IDataReader dr = DBHelper.ExecuteReader(sql, true, parm)) { IList<ModelArticle> list = GetModel(dr); model = list.First(); } } catch (Exception ex) { resultMsg = string.Format("{0} {1}", BaseDict.ErrorPrefix, ex.ToString()); } return model; }
public ActionResult Create(ModelArticle model, FormCollection fc) { var customScript = string.Empty; IList<SelectListItem> categorys = new List<SelectListItem>(); IList<SelectListItem> categorysTwo = new List<SelectListItem>(); try { categorys = QueryCategoryAll(model.Categoryid.ToString()); categorysTwo = QueryCategoryAll(model.CategoryTwo); var result = new ResultBase(); var resultMsg = string.Empty; var fileName = CommonMethod.ImageUpload(out result, this.HttpContext); if (result.result == -2) { customScript = UtilityScript.ShowMessage(result.resultMsg, isCreate: true); return View(model); } model.Context = fc["editorValue"]; model.Thumbnails = string.IsNullOrWhiteSpace(fileName) ? model.Thumbnails : fileName; model.Status = Convert.ToInt32(model.IsPermission); model.Isrecommend = Convert.ToInt32(model.IsRec); model.Createdate = model.Createdate; LogicArticle artDal = new LogicArticle(); var resultInsertUpdate = artDal.ArticleInsertUpdate(out resultMsg,base.AuthorizeInfo, model); if (resultInsertUpdate > 0) customScript = UtilityScript.ShowMessage(BaseDict.OperationSuccessfullyMsg, isCreate: true, isSuccess: true, funName: "Goto"); else customScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: false, funName: "BtnShow"); } catch (AuthorizeException ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告", isSuccess: false, funName: "GotoLogin"); } catch (Exception ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告"); } ViewBag.Categorys = categorys; ViewBag.CategorysTwo = categorysTwo; ViewBag.CustomScript = customScript; return View(model); }
/// <summary> /// 新增文章 /// </summary> public ActionResult Create(string Id = null) { var model = new ModelArticle(); if (!string.IsNullOrWhiteSpace(Id)) { var idx = Convert.ToInt32(Id); LogicArticle artDal = new LogicArticle(); var resultMsg = string.Empty; model = artDal.ArticleDetail(out resultMsg, idx); model.IsPermission = model.Status == 1 ? true : false; model.IsRec = model.Isrecommend == 1 ? true : false; ViewBag.Categorys = QueryCategoryAll(model.Id.ToString()); ViewBag.CustomScript = string.Empty; } else { ViewBag.Categorys = QueryCategoryAll(); ViewBag.CustomScript = string.Empty; } return View(model); }
/// <summary> /// 新增文章 /// </summary> public ActionResult Create(string Id = null) { var model = new ModelArticle(); var customScript = string.Empty; IList<SelectListItem> categorys = new List<SelectListItem>(); IList<SelectListItem> categorysTwo = new List<SelectListItem>(); try { if (!string.IsNullOrWhiteSpace(Id)) { var idx = Convert.ToInt32(Id); LogicArticle artDal = new LogicArticle(); var resultMsg = string.Empty; model = artDal.ArticleDetail(out resultMsg, base.AuthorizeInfo, idx); model.IsPermission = model.Status == 1 ? true : false; model.IsRec = model.Isrecommend == 1 ? true : false; categorys = QueryCategoryAll(model.Id.ToString()); customScript = string.Empty; } else { model.Createdate = DateTime.Now; categorys = QueryCategoryAll(); customScript = string.Empty; } } catch (AuthorizeException ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告", isSuccess: false, funName: "GotoLogin"); } catch (Exception ex) { customScript = Library.Common.UtilityScript.ShowMessage("系统出错,错误信息:" + ex.Message, title: "警告"); } ViewBag.Categorys = categorys; ViewBag.CategorysTwo = categorysTwo; ViewBag.CustomScript = customScript; return View(model); }
/// <summary> /// ��ѯʵ�� /// </summary> /// <param name="categoryId">ModelId ���</param> /// <returns>ModelArticle</returns> public ModelArticle ArticleDetailByIsRecommend(out string resultMsg, Int32 categoryId) { resultMsg = string.Empty; var model = new ModelArticle(); try { //�洢�������� string sql = "usp_article_select_detail_by_isrecommend"; //������� IList<DBParameter> parm = new List<DBParameter>(); parm.Add(new DBParameter() { ParameterName = "ID", ParameterValue = categoryId, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); //��ѯִ�� using (IDataReader dr = DBHelper.ExecuteReader(sql, true, parm)) { IList<ModelArticle> list = GetModel(dr); model = list.First(); } } catch (Exception ex) { resultMsg = string.Format("{0} {1}", BaseDict.ErrorPrefix, ex.ToString()); } return model; }
/// <summary> /// Model ��ֵ IDataReader /// </summary> private IList<ModelArticle> GetModel(IDataReader dr) { var modelList = new List<ModelArticle>(); while (dr.Read()) { var model = new ModelArticle(); model.Id = dr["Id"]== DBNull.Value ? 0 : Convert.ToInt32(dr["Id"]); model.Title = dr["Title"]== DBNull.Value ? string.Empty : dr["Title"].ToString(); model.Author = dr["Author"]== DBNull.Value ? string.Empty : dr["Author"].ToString(); model.Source = dr["Source"]== DBNull.Value ? string.Empty : dr["Source"].ToString(); model.Context = dr["Context"]== DBNull.Value ? string.Empty : dr["Context"].ToString(); model.Abstract = dr["Abstract"]== DBNull.Value ? string.Empty : dr["Abstract"].ToString(); model.Thumbnails = dr["Thumbnails"]== DBNull.Value ? string.Empty : dr["Thumbnails"].ToString(); model.Categoryid = dr["CategoryId"] == DBNull.Value ? 0 : Convert.ToInt32(dr["CategoryId"]); model.CategoryTwo = dr["CategoryTwo"] == DBNull.Value ? string.Empty : dr["CategoryTwo"].ToString(); model.Keyword = dr["Keyword"]== DBNull.Value ? string.Empty : dr["Keyword"].ToString(); model.Isrecommend = dr["IsRecommend"]== DBNull.Value ? 0 : Convert.ToInt32(dr["IsRecommend"]); model.Titlecolor = dr["TitleColor"]== DBNull.Value ? string.Empty : dr["TitleColor"].ToString(); model.Titleisbold = dr["TitleIsBold"]== DBNull.Value ? 0 : Convert.ToInt32(dr["TitleIsBold"]); model.Status = dr["Status"] == DBNull.Value ? 0 : Convert.ToInt32(dr["Status"]); model.CategoryName = dr["CategoryName"] == DBNull.Value ? string.Empty : Convert.ToString(dr["CategoryName"]); model.Createdate = dr["CreateDate"]== DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(dr["CreateDate"]); modelList.Add(model); } return modelList; }
/// <summary> /// ���� ���/���� /// </summary> /// <param name="article">ʵ��</param> /// <returns>ִ�н��</returns> public int ArticleInsertUpdate(out string resultMsg,ModelArticle article,DbTransaction tran =null) { resultMsg = string.Empty; int res = 0; try { //�洢�������� string sql = "USP_ARTICLE_INSERT_UPDATE"; //������� IList<DBParameter> parm = new List<DBParameter>(); parm.Add(new DBParameter() { ParameterName = "ID", ParameterValue = article.Id, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); parm.Add(new DBParameter() { ParameterName = "TITLE", ParameterValue = article.Title, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "AUTHOR", ParameterValue = article.Author, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "SOURCE", ParameterValue = article.Source, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "CONTEXT", ParameterValue = article.Context, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "ABSTRACT", ParameterValue = article.Abstract, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "THUMBNAILS", ParameterValue = article.Thumbnails, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "CATEGORYID", ParameterValue = article.Categoryid, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); parm.Add(new DBParameter() { ParameterName = "Categorytwo", ParameterValue = article.CategoryTwo, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); parm.Add(new DBParameter() { ParameterName = "KEYWORD", ParameterValue = article.Keyword, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "ISRECOMMEND", ParameterValue = article.Isrecommend, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); parm.Add(new DBParameter() { ParameterName = "TITLECOLOR", ParameterValue = article.Titlecolor, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); parm.Add(new DBParameter() { ParameterName = "TITLEISBOLD", ParameterValue = article.Titleisbold, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); parm.Add(new DBParameter() { ParameterName = "STATUS", ParameterValue = article.Status, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.Int32 }); //����/����ִ�� res = DBHelper.ExecuteNonQuery(sql, true, parm, tran); } catch (Exception ex) { if(tran != null) tran.Rollback(); resultMsg = string.Format("{0} {1}", BaseDict.ErrorPrefix, ex.ToString()); } return res; }