public object GetNewsAndPolicyDetail(NewsAndPolicyParams bane) { if (!ModelState.IsValid) { return(OperateContext.Current.RedirectWebApi(WebResultCode.Exception, "参数验证失败", null)); } T_MessageNotice news = operateContext.bllSession.T_MessageNotice.Select(s => s.m_id == bane.m_id).FirstOrDefault(); if (news == null) { return(OperateContext.Current.RedirectWebApi(WebResultCode.Exception, "查无此新闻政策~", "")); } //1.数据 NewsAndPolicyDetialModel baneResult = new NewsAndPolicyDetialModel { m_type = news.m_type, messDetail_url = news.focus_imgage, m_content = news.m_content, m_id = news.m_id, news_title = news.m_title, browse_num = news.browse_num, issue_date = (news.create_date != null) ? ((DateTime)news.create_date).ToString("D") : DateTime.Now.ToString("D") }; //2.请求的新闻,政策浏览次数+1 news.browse_num = news.browse_num + 1; operateContext.bllSession.T_MessageNotice.Modify(news, s => s.m_id == bane.m_id, "browse_num"); return(OperateContext.Current.RedirectWebApi(WebResultCode.Ok, "数据获取成功", baneResult)); }
public ActionResult DeleteNews(int id) { T_MessageNotice notice = operateContext.bllSession.T_MessageNotice.Select(s => s.m_id == id).FirstOrDefault(); if (notice == null) { return(operateContext.RedirectAjax(1, "需要删除的新闻对象不存在~", "", "")); } string[] str = notice.focus_imgage.Split('/'); if (str.Length > 4) { string url = "~"; for (int i = 4; i < str.Length - 1; i++) { url += "/" + str[i]; } if (!string.IsNullOrEmpty(url) && Directory.Exists(Server.MapPath(url))) { Directory.Delete(Server.MapPath(url), true); } } int mark = operateContext.bllSession.T_MessageNotice.Delete(s => s.m_id == id); if (mark <= 0) { return(operateContext.RedirectAjax(1, "删除新闻失败~", "", "")); } return(operateContext.RedirectAjax(0, "删除新闻成功~", "", "")); }
/// <summary> /// 新增或者是编辑新闻公告 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool UpdateMess(object obj) { FormCollection param = (FormCollection)obj; T_MessageNotice mes = new T_MessageNotice(); mes.m_title = param["m_title"]; mes.m_type = param["m_type"]; mes.m_content = param["m_content"]; mes.create_user_id = HCQ2UI_Helper.OperateContext.Current.Usr.user_id.ToString(); mes.create_user_name = HCQ2UI_Helper.OperateContext.Current.Usr.user_name; mes.create_date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); if (!string.IsNullOrEmpty(param["m_image"])) { string imagePath = param["m_image"]; mes.m_image_src = imagePath; byte[] str = HCQ2_Common.ImageHelper.ImageToBytes(HttpContext.Current.Server.MapPath(imagePath)); mes.m_image = str; } bool isAccess = false; if (!string.IsNullOrEmpty(param["mes_id"])) { //编辑 int mes_id = int.Parse(param["mes_id"]); isAccess = base.Modify(mes, o => o.m_id == mes_id, "m_title", "m_type", "m_content", "m_image") > 0; } else { isAccess = base.Add(mes) > 0; } return(isAccess); }
/// <summary> /// 编辑新闻 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool EditNews(T_MessageNotice model) { if (model == null) { return(false); } Modify(model, s => s.m_id == model.m_id, "m_title", "m_content", "m_type", "focus_imgage", "messList_imgage", "messDetail_imgage"); return(true); }
public ActionResult EditNews(T_MessageNotice model) { bool mark = operateContext.bllSession.T_MessageNotice.EditNews(model); if (!mark) { return(operateContext.RedirectAjax(1, "编辑新闻失败~", "", "")); } return(operateContext.RedirectAjax(0, "编辑新闻成功~", "", "")); }
/// <summary> /// 添加新闻 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddNews(T_MessageNotice model) { if (model == null) { return(false); } model.create_date = DateTime.Now; model.create_user_name = HCQ2UI_Helper.OperateContext.Current.Usr.user_name; model.create_user_id = HCQ2UI_Helper.OperateContext.Current.Usr.user_id; return(Add(model) > 0); }
/// <summary> /// 新增或者是编辑新闻公告 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool UpdateMess(object obj) { FormCollection param = (FormCollection)obj; T_MessageNotice mes = new T_MessageNotice(); mes.m_title = param["m_title"]; mes.m_type = param["m_type"]; mes.m_content = param["m_content"]; mes.create_user_id = HCQ2UI_Helper.OperateContext.Current.Usr.user_id; mes.create_user_name = HCQ2UI_Helper.OperateContext.Current.Usr.user_name; mes.create_date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); if (!string.IsNullOrEmpty(param["m_image"])) { //封面图片 string imagePath = param["m_image"]; mes.m_image_src = imagePath; byte[] str = ImageToBytes(HttpContext.Current.Server.MapPath(imagePath)); mes.m_image = str; //焦点新闻图片 string img = imagePath.Substring(imagePath.LastIndexOf("/")), imgName = img.Substring(0, img.LastIndexOf(".")), imgType = img.Substring(img.LastIndexOf(".")); string tempName = imagePath.Substring(0, imagePath.LastIndexOf("/")) + imgName + "_focus_imgage" + imgType; CompressImage(HttpContext.Current.Server.MapPath(imagePath), HttpContext.Current.Server.MapPath(tempName), 300, 720, 100, ImageCompressType.Cut); mes.focus_imgage = tempName; //列表新闻图片 tempName = imagePath.Substring(0, imagePath.LastIndexOf("/")) + imgName + "_messList_imgage" + imgType; CompressImage(HttpContext.Current.Server.MapPath(imagePath), HttpContext.Current.Server.MapPath(tempName), 210, 360, 100, ImageCompressType.Cut); mes.messList_imgage = tempName; //新闻详情图片 //tempName = imagePath.Substring(0, imagePath.LastIndexOf("/")) + imgName + "_messDetail_imgage" + imgType; //CompressImage(HttpContext.Current.Server.MapPath(imagePath), HttpContext.Current.Server.MapPath(tempName), 210, 360, 1, ImageCompressType.Cut); //mes.messDetail_imgage = tempName; } bool isAccess = false; if (!string.IsNullOrEmpty(param["mes_id"])) { //编辑 int mes_id = int.Parse(param["mes_id"]); isAccess = base.Modify(mes, o => o.m_id == mes_id, "m_title", "m_type", "m_content", "m_image", "focus_imgage", "messDetail_imgage") > 0; } else { isAccess = base.Add(mes) > 0; } return(isAccess); }
/// <summary> /// 删除新闻公告 /// </summary> /// <param name="mess_id"></param> /// <returns></returns> public ActionResult DeleteMess(int mess_id) { T_MessageNotice notice = operateContext.bllSession.T_MessageNotice.Select(s => s.m_id == mess_id).FirstOrDefault(); if (notice == null) { return(Content("fin")); } string img_url = (!string.IsNullOrEmpty(notice.m_image_src))? notice.m_image_src.Substring(0, notice.m_image_src.LastIndexOf("/")) :""; if (!string.IsNullOrEmpty(img_url)) { Directory.Delete(Server.MapPath(img_url), true); } string str = operateContext.bllSession.T_MessageNotice.DeleteMess(mess_id) ? "ok" : "fin"; return(Content(str)); }
public ActionResult UploadNewsImg() { int id = RequestHelper.GetIntByName("id"); Result result = new Result(); result.avatarUrls = new List <string>(); result.success = false; result.msg = "图片上传成功!"; // 取服务器时间+8位随机码作为部分文件名,确保文件名无重复。 string fileName = DateTime.Now.ToString("yyyyMMddhhmmssff") + uploadHelper.CreateRandomCode(8); #region 处理上传文件夹 #region 编辑删除文件 if (id > 0) { T_MessageNotice notice = operateContext.bllSession.T_MessageNotice.Select(s => s.m_id == id).FirstOrDefault(); string focus_imgage_url = notice?.focus_imgage; if (!string.IsNullOrEmpty(focus_imgage_url)) { string[] str = focus_imgage_url.Split('/'); string url = "~"; for (int i = 4; i < str.Length - 1; i++) { url += "/" + str[i]; } if (!string.IsNullOrEmpty(url) && Directory.Exists(Server.MapPath(url))) { Directory.Delete(Server.MapPath(url), true); } } } #endregion string path = Server.MapPath("~/UpFile/SysNewsImg/" + operateContext.Usr.user_id + "/" + fileName); if (!Directory.Exists(path.ToString())) { Directory.CreateDirectory(path.ToString());//文件夹不存在则创建 } #endregion #region 处理头像图片 result.sourceUrl = string.Format("http://" + request.Url.Host + ":" + request.Url.Port + request.ApplicationPath + "/UpFile/SysNewsImg/" + operateContext.Usr.user_id + "/{0}", fileName); HttpPostedFileBase file = Request.Files["__source"];//__avatar1 //默认的 file 域名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names string[] avatars = new string[3] { "__avatar1", "__avatar2", "__avatar3" }; int avatars_length = avatars.Length; string name = string.Empty; for (int i = 0; i < avatars_length; i++) { switch (i) { case 0: name = "focus_imgage"; break; case 1: name = "messDetail_imgage"; break; case 2: name = "messList_imgage"; break; } file = Request.Files[avatars[i]]; if (file == null) { break; } string virtualPath = string.Format("~/UpFile/SysNewsImg/" + operateContext.Usr.user_id + "/{0}/csharp_{1}.jpg", fileName, name); result.avatarUrls.Add("http://" + request.Url.Host + ":" + request.Url.Port + request.ApplicationPath + virtualPath.Replace("~", "")); file.SaveAs(Server.MapPath(virtualPath)); } #endregion result.success = true; result.msg = "Success!"; //返回图片的保存结果(返回内容为json字符串,可自行构造,该处使用Newtonsoft.Json构造) return(Json(result)); }