public ActionResult Add(int cat_id) { var cat = Db.Where <Site_News_Category>(m => m.Id == cat_id).TakeFirst(); if (cat == null) { return(RedirectToAction("Index", "Management")); } Site_News model = new Site_News(); model.CategoryId = cat.Id; model.Category_Name = cat.Name; model.LanguageCode = cat.LanguageCode; model.isNew = true; model.IsActive = true; return(View(model)); }
/// <summary> /// 编辑新闻 /// 创建人:lwj /// 时间:2015-6-16 /// </summary> /// <param name="context"></param> private void EditNews(HttpContext context) { string title = context.Request["title"] ?? ""; string content = context.Request["content"] ?? ""; string id = context.Request["id"] ?? ""; string deletepic = context.Request["deletepic"] ?? "";//要删除的图片的id string source = context.Request["source"] ?? ""; string subtitle = context.Request["subtitle"] ?? ""; string draftbox = context.Request["draftbox"] ?? "0";//是否保存草稿箱 0 否 1是 add by fuzhenzhen Site_News_BLL newsbll = new Site_News_BLL(); Site_News news = newsbll.SelectNews(id); string oldContent = news.N_Content; List <Site_News_Pic> pic = new List <Site_News_Pic>(); //记录要删除的新闻轮播图片 if (!string.IsNullOrEmpty(deletepic)) { pic = newsbll.SelectNewsPic(deletepic.Remove(deletepic.Length - 1)); } //编辑新闻内容和图片 //deit by fuzhenzhen 09-15 string result = newsbll.UpdateNews(id, title, content, Site_News_Pic.imgPath, deletepic, source, subtitle, Convert.ToInt32(draftbox)); if (result == "1") { #region 剔除新闻内容里的文件夹图片 string regex = "<img.*?/>"; MatchCollection notu = StringHelper.GetValue(regex, content); MatchCollection oldtu = StringHelper.GetValue(regex, oldContent); for (int j = 0; j < oldtu.Count; j++) { if (!content.Contains(oldtu[j].Value)) { //现在的不包含以前的 int place = oldtu[j].Value.IndexOf("src=") + 5; string hou = oldtu[j].Value.Substring(place); int yin = hou.IndexOf("\""); string src = hou.Substring(0, yin);//图片路径 if (!string.IsNullOrEmpty(src)) { try { string pa = System.Web.HttpContext.Current.Server.MapPath("~/" + src); if (File.Exists(pa)) { File.Delete(pa); } } catch { continue; } } } } #endregion #region 除文件夹里的图片 if (pic.Count > 0) { foreach (var item in pic) { try { string pa = System.Web.HttpContext.Current.Server.MapPath("~/" + item.PicPath); if (File.Exists(pa)) { File.Delete(pa); } } catch { continue; } } } #endregion //添加日志 LogHelper.InserLog((int)EnumClass.OperateType.编辑操作, PageBase.CurrentOperatName, "编辑了标题为" + title + "的新闻"); } //重置公共变量 Site_News_Pic.imgPath = new List <Site_News_Pic>(); Site_News_Pic.count = 0; context.Response.Write(result); }
public ActionResult Update(Site_News model, IEnumerable <HttpPostedFileBase> FileUp) { if (string.IsNullOrEmpty(model.Name)) { ViewBag.Error = "Please enter news title"; return(View("Add", model)); } if (model.PublishSchedule && model.PublishOn.CompareTo(model.UnPublishOn) > 0) { ViewBag.Error = "Please check Publish schedule date"; return(View("Add", model)); } if (model.Tag != null) { // parse domain list var tag = model.Tag.First(); var tokens = tag.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); model.Tag = tokens.ToList(); } else { model.Tag = new List <string>(); } // generate seo name string random = ""; do { if (string.IsNullOrEmpty(model.SeoName)) { model.SeoName = model.Name + random; model.SeoName = model.SeoName.ToSeoUrl(); } else { model.SeoName = model.SeoName.ToSeoUrl(); } // check exist if (Db.Count <Site_News>(m => m.SeoName == model.SeoName && m.Id != model.Id) == 0) { break; } random = "_" + random.GenerateRandomText(3); model.SeoName = ""; } while (0 < 1); Site_News current_item = new Site_News(); if (model.Id > 0) { var z = Db.Where <Site_News>(m => m.Id == model.Id); if (z.Count == 0) { // the ID is not exist return(JsonError("Please dont try to hack us")); } else { current_item = z.First(); } } if (model.Id == 0) { model.CreatedOn = DateTime.Now; model.CreatedBy = AuthenticatedUserID; } else { model.CreatedOn = current_item.CreatedOn; model.CreatedBy = current_item.CreatedBy; model.Statistic_Views = current_item.Statistic_Views; } if (FileUp != null && FileUp.Count() > 0 && FileUp.First() != null) { model.ThumbnailFile = UploadFile(AuthenticatedUserID, User.Identity.Name, "", FileUp); } else { model.ThumbnailFile = current_item.ThumbnailFile; } if (model.Id == 0) { Db.Insert <Site_News>(model); } else { Db.Update <Site_News>(model); } return(RedirectToAction("Index", new { cat_id = model.CategoryId })); }
/// <summary> /// 添加新闻包括图片 /// 创建人:lwj /// 时间:2015-6-16 /// </summary> /// <param name="title"></param> /// <param name="content"></param> /// <param name="userid"></param> /// <param name="dt"></param> /// <returns></returns> public string InsertEntity(Site_News newsM, List <Site_News_Pic> picList) { return(dal.InsertNewsPic(newsM, picList)); }