diff options
author | crupest <crupest@outlook.com> | 2020-02-24 16:58:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-24 16:58:01 +0800 |
commit | cc7dd9ec82ab9f1efd46544e378fd910021f45db (patch) | |
tree | 15a9ecbe1339813d59af04b571f350043df36abc /Timeline/Services/TimelineService.cs | |
parent | 4475246be00d0f9d1a5df6c181589ed0b2a7009b (diff) | |
parent | bcae79d0b753cccecffac3ae3c7f049b56a8d800 (diff) | |
download | timeline-cc7dd9ec82ab9f1efd46544e378fd910021f45db.tar.gz timeline-cc7dd9ec82ab9f1efd46544e378fd910021f45db.tar.bz2 timeline-cc7dd9ec82ab9f1efd46544e378fd910021f45db.zip |
Merge pull request #61 from crupest/devv0.1.0-alpha
Add delete timeline feature.
Diffstat (limited to 'Timeline/Services/TimelineService.cs')
-rw-r--r-- | Timeline/Services/TimelineService.cs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 76acc7d7..f12a7fcc 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -269,6 +269,15 @@ namespace Timeline.Services /// <exception cref="ConflictException">Thrown when the timeline already exists.</exception>
/// <exception cref="UserNotExistException">Thrown when the owner user does not exist.</exception>
Task<TimelineInfo> CreateTimeline(string name, long owner);
+
+ /// <summary>
+ /// Delete a timeline.
+ /// </summary>
+ /// <param name="name">The name of the timeline.</param>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when timeline name is invalid.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown when the timeline does not exist.</exception>
+ Task DeleteTimeline(string name);
}
public interface IPersonalTimelineService : IBaseTimelineService
@@ -733,6 +742,22 @@ namespace Timeline.Services Members = new List<UserInfo>()
};
}
+
+ public async Task DeleteTimeline(string name)
+ {
+ if (name == null)
+ throw new ArgumentNullException(nameof(name));
+
+ ValidateTimelineName(name, nameof(name));
+
+ var entity = await Database.Timelines.Where(t => t.Name == name).SingleOrDefaultAsync();
+
+ if (entity == null)
+ throw new TimelineNotExistException(name);
+
+ Database.Timelines.Remove(entity);
+ await Database.SaveChangesAsync();
+ }
}
public class PersonalTimelineService : BaseTimelineService, IPersonalTimelineService
|