Example #1
0
 /// <summary>
 /// 更新文章
 /// </summary>
 /// <param name="post"></param>
 /// <returns></returns>
 public async Task<bool> Update(Post post)
 {
     var update = Builders<Post>.Update.Set(t => t.Title, post.Title)
         .Set(t => t.Alias, post.Alias)
         .Set(t => t.CategoryAlias, post.CategoryAlias)
         .Set(t => t.Labels, post.Labels)
         .Set(t => t.Summary, post.Summary)
         .Set(t => t.Content, post.Content)
         .Set(t => t.Source, post.Source)
         .Set(t => t.Url, post.Url)
         .Set(t => t.ModifyTime, DateTime.Now);
     var task = await _posts.Collection.UpdateOneAsync(t => t.UniqueId.ToUpper() == post.UniqueId.ToUpper(), update);
     if (task.ModifiedCount > 0)
     {
         return true;
     }
     return false;
 }
Example #2
0
 public async Task<string> AddArticle(Post post)
 {
     var uniqueId = StringHelper.GenerateShortGuid();
     post.UniqueId = uniqueId;
     post.CreateTime = post.ModifyTime = DateTime.Now;
     post.ViewCount = 0;
     post.IsActive = true;
     await _postRepository.Insert(post);
     return uniqueId;
 }
Example #3
0
 /// <summary>
 /// 新增文章
 /// </summary>
 /// <param name="post"></param>
 /// <returns></returns>
 public async Task Insert(Post post)
 {
     await _posts.Collection.InsertOneAsync(post);
 }
Example #4
0
 public async Task<bool> UpdateArticle(Post post)
 {
     return await _postRepository.Update(post);
 }