public async Task <Article> UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto) { Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne(); if (article.CreateUserId != _currentUser.Id) { throw new LinCmsException("您无权修改他人的随笔"); } if (article == null) { throw new LinCmsException("没有找到相关随笔"); } _mapper.Map(updateArticleDto, article); article.WordNumber = article.Content.Length; article.ReadingTime = article.Content.Length / 400; await _articleRepository.UpdateAsync(article); ArticleDraft articleDraft = _mapper.Map <ArticleDraft>(article); bool exist = await _articleDraftRepository.Select.AnyAsync(r => r.Id == article.Id); if (exist) { await _articleDraftRepository.UpdateAsync(articleDraft); } else { await _articleDraftRepository.InsertAsync(articleDraft); } return(article); }
private void PublishAticle() { _currentArticleDraft = ArticleDraftGenerator.GetDraft(); OpenPage(_currentArticleDraft.SitePostId, () => UpdateOrPublishPost(_currentArticleDraft), () => _timer.Change(100, Timeout.Infinite)); }
public async Task <Guid> CreateAsync(CreateUpdateArticleDto createArticle) { Article article = _mapper.Map <Article>(createArticle); article.Archive = DateTime.Now.ToString("yyy年MM月"); article.WordNumber = createArticle.Content.Length; article.ReadingTime = createArticle.Content.Length / 800; article.Tags = new List <Tag>(); foreach (var articleTagId in createArticle.TagIds) { article.Tags.Add(new Tag() { Id = articleTagId, }); _tagService.UpdateArticleCount(articleTagId, 1); } ArticleDraft articleDraft = new ArticleDraft() { Content = createArticle.Content, Editor = createArticle.Editor, Title = createArticle.Title }; await _articleRepository.InsertAsync(article); articleDraft.Id = article.Id; await _articleDraftRepository.InsertAsync(articleDraft); await _classifyService.UpdateArticleCountAsync(createArticle.ClassifyId, 1); return(article.Id); }
public async Task <bool> Update(ArticleDraft articledraft) { string update = string.Format(@"update ArticleDraft set where ArticleDraftId = @ArticleDraftId"); try { connection.Execute(update, articledraft); return(true); } catch { return(false); } }
private void UpdateOrPublishPost(ArticleDraft draft) { try { NotifyStatus("发布中... 标题:" + draft.Title); _state = WebBrowserState.Request; var scripts = GetInvokeJS(draft); //每执行一个脚本 等待 foreach (var scriptKv in scripts) { _browser.ExecuteScriptAsync(scriptKv.Value); switch (scriptKv.Key) { case JSType.ADD_META: { _browser.ReqHandler.IsResponceSuccess = IsAddMetaSuccess; _browser.ReqHandler.ResponceSuccess = AddMetaSuccess; //等待添加Meta完成 WaitResponceSuccess(); } break; case JSType.ADD_META_NO_SUBMIT: case JSType.PUBLISH: break; } } _browser.ReqHandler.IsResponceSuccess = IsPublishSuccess; _browser.ReqHandler.ResponceSuccess = PublishSuccess; //等待文章发布/更新 if (!WaitResponceSuccess()) { var logInfo = new StringBuilder(); foreach (var script in scripts) { logInfo.AppendLine(script.Value); } Logger.Info("\n发布超时:" + logInfo); NotifyStatus("发布超时!标题:" + draft.Title); ResetReqHandler(); } } catch (Exception ex) { Logger.Error(ex); } }
public async Task <bool> Create(ArticleDraft articledraft) { string insert = string.Format(@"insert into ArticleDraft () values ()"); try { await connection.ExecuteAsync(insert, articledraft); return(true); } catch { return(false); } }
public async Task UpdateAsync(Guid id, UpdateArticleDraftDto updateArticleDto) { ArticleDraft articleDraft = await _articleDraftRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (articleDraft != null && articleDraft.CreateUserId != _currentUser.Id) { throw new LinCmsException("您无权修改他人的随笔"); } if (articleDraft == null) { articleDraft = new ArticleDraft { Id = id, CreateUserId = _currentUser.Id ?? 0, CreateTime = DateTime.Now }; } _mapper.Map(updateArticleDto, articleDraft); await _articleDraftRepository.InsertOrUpdateAsync(articleDraft); }
public ActionResult Save(ArticleDraft model) { var draft = GetArticleDrafts().FirstOrDefault(i => i.Id == model.Id); if (draft != null) { draft.Title = model.Title; draft.Content = model.Content; draft.Time = DateTime.Now; } else { model.SiteId = CurrentSiteId; model.Time = DateTime.Now; BlogDataContext.ArticleDrafts.Add(model); } SaveChanges(); return(Json(new { Model = model, DraftCount = GetArticleDrafts().Count() })); }
public async Task UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto) { Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne(); if (article.CreateUserId != CurrentUser.Id) { throw new LinCmsException("您无权修改他人的随笔"); } if (article == null) { throw new LinCmsException("没有找到相关随笔"); } if (article.ClassifyId != updateArticleDto.ClassifyId) { await _classifyService.UpdateArticleCountAsync(article.ClassifyId, -1); await _classifyService.UpdateArticleCountAsync(updateArticleDto.ClassifyId, 1); } Mapper.Map(updateArticleDto, article); article.WordNumber = article.Content.Length; article.ReadingTime = article.Content.Length / 800; await _articleRepository.UpdateAsync(article); ArticleDraft articleDraft = Mapper.Map <ArticleDraft>(article); bool exist = await _articleDraftRepository.Select.AnyAsync(r => r.Id == article.Id); if (exist) { await _articleDraftRepository.UpdateAsync(articleDraft); } else { await _articleDraftRepository.InsertAsync(articleDraft); } }
public async Task <ArticleDraftDto> GetAsync(Guid id) { ArticleDraft articleDraft = await _articleDraftRepository.Where(r => r.Id == id && r.CreateUserId == _currentUser.Id).ToOneAsync(); return(_mapper.Map <ArticleDraftDto>(articleDraft)); }
private Dictionary <JSType, string> GetInvokeJS(ArticleDraft draft) { var result = new Dictionary <JSType, string>(); var subjectTime = draft.PublishTime; var metas = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(draft.PostMetas)) { metas.Add("PostMetas", draft.PostMetas); } var index = 0; foreach (var meta in metas) { index++; var isLast = index == metas.Count; var jsSubmit = isLast ? "" : "jQuery('#newmeta-submit').click();"; var jsType = isLast ? JSType.ADD_META_NO_SUBMIT : JSType.ADD_META; var metav = meta.Value.Replace("'", "\\'").RemoveLineBreak(); result.Add(jsType, string.Format( "if(jQuery(\"#the-list input[type='text'][value='{0}']\").length==0){{ jQuery('#metakeyinput').val('{0}'); jQuery('#metavalue').val('{1}'); {2}}}", meta.Key, metav, jsSubmit)); } var title = draft.Title.RemoveLineBreak(); if (title.Length > 55) { title = title.Substring(0, 55); } title = title.Replace("\\", "\\\\").Replace("'", "\\'"); var titleEn = draft.TitleEn.Replace("'", " ").RemoveLineBreak(); if (titleEn.Length > 55) { titleEn = titleEn.Substring(0, 55); } //选择分类 js var sbArticleTypes = new StringBuilder(); var articleTypeArray = draft.Categories.Split(','); foreach (var articleType in articleTypeArray) { var siteCategery = _currentSiteInfo.Categories.Find( x => string.Equals(x.Name, articleType.Trim(), StringComparison.CurrentCultureIgnoreCase)); if (siteCategery == null) { draft.Tags = string.IsNullOrEmpty(draft.Tags.Trim()) ? articleType : string.Format("{0},{1}", draft.Tags, articleType); continue; } var tempCategoryJs = $"jQuery(\"input[value = '{siteCategery.Id}'][name = 'post_category[]']\").click();"; sbArticleTypes.Append(tempCategoryJs); } var catJs = sbArticleTypes.ToString(); var js = WordPressHelper.JQueryTemplate.FormatWith(title, ToSafeString(draft.Content), catJs, draft.Tags, subjectTime.Month.ToString(WordPressHelper.Str00), subjectTime.Day.ToString(WordPressHelper.Str00), subjectTime.Year, subjectTime.Hour.ToString(WordPressHelper.Str00), subjectTime.Minute.ToString(WordPressHelper.Str00), titleEn); result.Add(JSType.PUBLISH, js); return(result); }