From 23b3f79f4d1b48eb4a230402b1ad88a8d5409d24 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 20 Nov 2019 16:40:41 +0800 Subject: Change post content to null instead of delete the entity when deleting post. --- Timeline/Services/TimelineService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Timeline/Services/TimelineService.cs') diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index a2ff4098..9ae9dc1c 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -348,7 +348,7 @@ namespace Timeline.Services throw new ArgumentNullException(nameof(name)); var timelineId = await FindTimelineId(name); - var postEntities = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId).ToListAsync(); + var postEntities = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.Content != null).ToListAsync(); var posts = new List(await Task.WhenAll(postEntities.Select(async p => new TimelinePostInfo { Id = p.Id, @@ -418,7 +418,9 @@ namespace Timeline.Services if (post == null) throw new TimelinePostNotExistException(id); - Database.TimelinePosts.Remove(post); + post.Content = null; + post.LastUpdated = Clock.GetCurrentTime(); + await Database.SaveChangesAsync(); } -- cgit v1.2.3