public ActionResult AddCpyNewsInfo() { // var currentCpy= GetCurrentUser(); string guid = Request["cpyUserId"]; //从分布式缓存拿出来的对象不能进行延迟加载。 var currentCpy = Common.CacheHelper.Get(guid) as Company; try { News news = new News() { CompanyId = currentCpy.Id, Title = Request["title"], Game = Request["gameName"], Kewords = Request["keyword"], Type = Request["type"], Memo = Request["memo"], Msg = Request["msg"], State = "2", InTime = DateTime.Now, Rec_Forum_Index = "0", Rec_Forum_Time = DateTime.Now, Rec_Hot_Index = "0", Rec_Hot_Time = DateTime.Now, Editor = null, EditTitle = null, CheckName = null, AddedBy = null, Source = null, Views = 0, LeaveMsgId = 0 }; if (NewsBll.Add(news) != null) { return(Content("ok")); } else { return(Content("no")); } } catch (Exception ex) { throw new Exception("发布新闻时抛异常啦" + ex.Message); } }
/// <summary> /// 确定提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { string strError = Validates(); if (!string.IsNullOrEmpty(strError)) { this.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('" + strError + "');</script>"); return; } model.CategoryId = Convert.ToInt32(this.ddlType.SelectedValue); model.Title = SafeRequest.GetFormString("txtTitle"); model.SubHead = SafeRequest.GetFormString("txtSubHead"); model.PublicationUnit = SafeRequest.GetFormString("txtUnit"); model.FromSource = SafeRequest.GetFormString("txtFromSouce"); // model.KeyWord = SafeRequest.GetFormString("txtKeyWord"); model.ReleaseDate = !string.IsNullOrEmpty(this.txtReleaseDate.Text.Trim()) ? Convert.ToDateTime(this.txtReleaseDate.Text.Trim()) : System.DateTime.Now; model.IsTop = 0; //SafeRequest.GetFormInt("radioTopList", 0); model.IndexCommend = 0; //SafeRequest.GetFormInt("radioIndexCommentList", 0); model.HotPic = SafeRequest.GetFormString("radioHotList"); model.HotDays = SafeRequest.GetFormInt("txtHotDays", 3); //model.ArticleType = SafeRequest.GetFormInt("radioArticleTypeList", 0); model.Body = this.fckBody.Text; //追加底部 if (cbFooter.Checked) { if (model.Body.IndexOf("start_auto_footer") == -1 && model.Body.IndexOf("end_auto_footer") == -1) { string autoFooter = "<!--start_auto_footer-->" + this.fckBodyFooter.Text + "<!--end_auto_footer-->"; model.Body = model.Body + autoFooter; } //写入缓存 NG.CachHelper.Redis.RedisHelper redis = new NG.CachHelper.Redis.RedisHelper(); redis.SetStringCash("News_Footer", this.fckBodyFooter.Text); redis.Close(); } // model.IsComment = 0;// SafeRequest.GetFormInt("radioIsComment", 0); model.Approved = SafeRequest.GetFormInt("radioApproved", 0); model.Sort = SafeRequest.GetFormInt("txtSort", 99); model.AddedDate = System.DateTime.Now; model.ExpireDate = System.DateTime.Now; model.ViewCount = 0; // model.IsScrool = 0; // model.AddedUserId = Convert.ToInt32(_userId);//默认登录进来人的编号 model.AddedUserId = 1; //~/upload/News/ #region 保存图片 if (!this.picUpload.Value.Equals("") && this.picUpload.PostedFile.ContentLength > 10) { string FileTZM = this.picUpload.PostedFile.FileName.Substring(this.picUpload.PostedFile.FileName.LastIndexOf(".") + 1);//得到文件的扩展名 if (!IsPic(FileTZM.ToLower())) { JSUtility.Alert("上传图片格式不正确!"); return; } if (this.picUpload.PostedFile.ContentLength > 1048576) { JSUtility.Alert("上传图片过大!"); return; } Random rnd = new Random(); string UpLoadFileTime = DateTime.Now.ToString("yyMMddHHmmss") + rnd.Next(9999).ToString("0000"); //生成一个新的数图片名称 string fileName = UpLoadFileTime + "." + FileTZM; //产生上传图片的名称 if (!Directory.Exists(Request.MapPath("~/upload/News/"))) { Directory.CreateDirectory(Request.MapPath("~/upload/News/")); } string Url = Request.MapPath("~/upload/News/" + fileName); picUpload.PostedFile.SaveAs(Url); model.ImgLink = "/upload/News/" + fileName; } else { model.ImgLink = ViewState["ImgLink"].ToString(); } #endregion if (_Pid != "") { model.NewsID = _Pid; if (bll.Update(model)) { this.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('修改成功');layer_close_refresh();</script>"); } } else { model.NewsID = IdCreator.CreateId("T_News", "NewsId"); if (bll.Add(model)) { JSUtility.AlertAndRedirect("添加成功,请继续添加!", Request.RawUrl.ToString()); } } }