public ActionResult Edit(Base_Article a, int caId = 0) { Base_CatalogArticle ca; if (caId > 0) { ca = _schedule.Article.GetById(caId); if (ca.Article.State == ScheduleEvent.OptionReadOnly) { return(JsonTips("error", SStr.CantChangeReadonlySchedule)); } } else { a.State = ArticleState.Published; ca = new Base_CatalogArticle { CatalogId = ScheduleEvent.Root.Id, }; } ca.Article = a; ca.Article.EditorId = CurrentUserId.ToInt(); ScheduleManager.AdjustAlertTime(ca); _schedule.Article.Save(ca); // Manager.Save(evt); return(JsonTips("success", JStr.SuccessSaved, ca.Article.Title)); }
[ValidateInput(false)] //因为要传递带html标签的art.Text,所以此处不能验证输入 public ActionResult Edit(Base_Article art, int caId = 0) { art.EditorId = CommOp.ToInt(CurrentUserId); art.State = ArticleState.Published; Base_CatalogArticle ca; if (caId == 0) { ca = new Base_CatalogArticle { CatalogId = CatalogId }; } else { ca = _article.GetById(caId); _innerCatalogId = ca.CatalogId; } ca.Article = art; if (art.Id > 0 && caId == 0) { var oldCaId = _article.GetByArticleId(art.Id, CatalogId).Id; ca.Id = oldCaId; } if (BeforeSaving(ca)) { _article.Save(ca); } return(AfterSaved(ca)); }
[ValidateInput(false)] //因为要传递带html标签的art.Text,所以此处不能验证输入 public ActionResult Edit(Base_Article art, int caId = 0) { art.EditorId = CommOp.ToInt(CurrentUserId); art.State = ArticleState.Published; Base_CatalogArticle ca; if (caId == 0) { ca = new Base_CatalogArticle { CatalogId = CatalogId }; } else { ca = _resourceFileService.Article.GetById(caId); _innerCatalogId = ca.CatalogId; } ca.Article = art; if (art.Id > 0 && caId == 0) { var oldCaId = _resourceFileService.Article.GetByArticleId(art.Id, CatalogId).Id; ca.Id = oldCaId; } if (true) { _resourceFileService.Article.Save(ca); } return(JsonTips("success", "", JStr.SuccessSaved0, (object)null, ca.Article.Title)); }
/// <summary> /// 当选择系统默认头像时,保存头像 /// </summary> /// <param name="info"></param> public void SaveAvatar(ResourceFileInfo info) { var myArticle = SiteManager.Kernel.Get <EFAuditDataService <Base_Article> >(); Base_Article art = new Base_Article(); art = myArticle.GetQuery().Include(a => a.Exts).FirstOrDefault(a => a.Id == info.Id); Base_Article newart = new Base_Article { EditorId = Convert.ToInt32(info.UserId), Author = info.UserId, Title = info.UserId + "的头像", State = ArticleState.ReadOnly }; var avatarCatId = Catalog.GetAllValid().First(cat => cat.Name == "UserAvatar" && cat.ParentId == Catalog.GetRootId()).Id; Base_CatalogArticle catArt = new Base_CatalogArticle { Article = newart, CatalogId = avatarCatId, ArticleId = newart.Id, }; var rootId = Catalog.GetRootId(); catArt.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.Key), art.Exts.FirstOrDefault(e => e.CatlogExtId == SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.Key).Id).Value); catArt.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileName), art.Exts.FirstOrDefault(e => e.CatlogExtId == SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileName).Id).Value); catArt.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileSize), art.Exts.FirstOrDefault(e => e.CatlogExtId == SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileSize).Id).Value); _article.Save(catArt); _article.Dispose(); }
/// <summary> /// 删除文件,当文件被多次引用的时候只删除CatalogArticle中的一条记录, /// 只被引用一次的时候就是删除记录并将Article表中的记录标记为Delete /// </summary> /// <param name="t"></param> /// <returns></returns> public override int Delete(Base_CatalogArticle t) { //CatalogArticle中包括的此ArticleId的数据条数 var count = GetQuery().Count(art => art.ArticleId == t.ArticleId); Base_Article article = t.Article; //删除主表中的记录 _context.Entry(t).State = EntityState.Deleted; if (count == 1) { //将从表的标示设为删除(因为从表中的数据还有其他表与之对应,故软删除) article.IsDeleted = true; _context.Entry(article).State = EntityState.Modified; } _context.SaveChanges(); return(count); }
/// <summary> /// 初始化系统自带的头像 /// </summary> private void InnerInitSysAvatar() { var rootpath = HttpContext.Current.Server.MapPath("/"); var filepath = Path.Combine(rootpath, "Avatar"); DirectoryInfo folder = new DirectoryInfo(filepath); //目录的根节点 var rootId = SiteManager.Catalog.GetAllValid().First(cat => cat.Name == "SystemTypes" && cat.ParentId == null).Id; var Article = SiteManager.Kernel.Get <EFAuditDataService <Base_Article> >(); foreach (FileInfo file in folder.GetFiles()) { Base_Article art = new Base_Article { State = ArticleState.ReadOnly | ArticleState.New,//表示是头像 的状态 Title = file.Name, EditorId = Convert.ToInt32(AppManager.Instance.UserManager.GetAll().FirstOrDefault(a => a.Id != null).Id), }; //查找扩展属性ID,对应ID赋值 art.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.Key), "~/Avatar/" + file.Name); art.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileName), file.Name); art.SetExt(SiteManager.Catalog.GetExtByName(rootId, SystemTypes.Root.FileSize), file.Length); Article.Add(art); } }
/// <summary> /// 将信息实体和待发送到的信息存到数据表中 /// 转换规则(Base_Article): /// CreateTime = 计划发送时间 /// Clicks = 发送通道 /// UrlTitle = 点击消息后转到的Url /// EditorId = 要发送到的人 /// /// 转换规则(Base_ArticleRelation) /// RelationType = 是发送还是抄送 /// /// 转换规则 (Base_CatalogArticle) /// Ord = 优先级 /// /// </summary> /// <param name="msg"></param> /// <returns></returns> int SaveGetId(JMessage msg) { using (var article = SiteManager.Get <ArticleManager>()) { Base_CatalogArticle ca = article.CreateByCatalog(MessageRoot.Root.Id); ca.Article.Title = msg.Title; ca.Article.Text = msg.Content; ca.Article.EditorId = msg.SenderId; ca.Article.CreateTime = msg.CreateTime; ca.Article.State = SendResultType.WaitForSend; ca.Article.UrlTitle = msg.Url; ca.Ord = (int)msg.Priority; ca.Article.Clicks = (int)msg.Channel; if (msg.SendToIds.IsEmpty() && msg.CopyToIds.IsEmpty()) { return(0); } foreach (SendChannel channel in Enum.GetValues(typeof(SendChannel))) { if ((msg.Channel & channel) == channel) { foreach (var uid in msg.SendToIds) { Base_Article a = new Base_Article { EditorId = uid, Title = ca.Article.Title, CreateTime = msg.PlanSendTime, State = SendResultType.WaitForSend }; Base_ArticleRelation ra = new Base_ArticleRelation { Source = ca.Article, Target = a, RelationType = SendType.Send }; ca.Article.Targets.Add(ra); } foreach (var uid in msg.CopyToIds) { Base_Article a = new Base_Article { EditorId = uid, Title = ca.Article.Title, CreateTime = msg.PlanSendTime, State = SendResultType.WaitForSend }; Base_ArticleRelation ra = new Base_ArticleRelation { Source = ca.Article, Target = a, RelationType = SendType.Copy }; ca.Article.Targets.Add(ra); } foreach (var attId in msg.AttachmentIds) { Base_ArticleRelation ra = new Base_ArticleRelation { RelationType = ArticleRelationType.Attachment, Source = ca.Article, TargetId = attId, }; ca.Article.Targets.Add(ra); } } } article.Save(ca); return(ca.Id); } }