public static IReadOnlyList <NicoVideoInfo> GetAll() { using (var db = new NicoVideoDbContext()) { return(db.VideoInfos.ToList()); } }
public static NicoVideoInfo Get(string rawVideoId) { using (var db = new NicoVideoDbContext()) { return(db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId)); } }
public static void AddOrUpdate(string rawVideoId, CommentResponse commentRes) { using (var db = new NicoVideoDbContext()) { var comment = db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId); if (comment == null) { comment = new NicoVideoComment() { ThreadId = rawVideoId, CommentCount = commentRes.GetCommentCount() }; db.Comments.Add(comment); } else { comment.CommentCount = commentRes.GetCommentCount(); comment.SetComments(commentRes.Chat); db.Comments.Update(comment); } db.SaveChanges(); } }
public static UserInfo Get(string userId) { using (var db = new NicoVideoDbContext()) { return(db.Users.SingleOrDefault(x => x.UserId == userId)); } }
public static NicoVideoComment Get(string rawVideoId) { using (var db = new NicoVideoDbContext()) { return(db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId)); } }
public static async Task InitializeAsync() { using (var db = new NicoVideoDbContext()) { await db.Database.EnsureCreatedAsync(); } }
public static async Task <NicoVideoInfo> GetAsync(string threadId) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { return(await db.VideoInfos.SingleOrDefaultAsync(x => x.RawVideoId == threadId)); } }
public static void Remove(UserInfo info) { using (var db = new NicoVideoDbContext()) { db.Users.Remove(info); db.SaveChanges(); } }
public static async Task <UserInfo> GetAsync(string userId) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { return(await db.Users.SingleOrDefaultAsync(x => x.UserId == userId)); } }
public static async Task RemoveAsync(NicoVideoInfo nicoVideoInfo) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { db.VideoInfos.Remove(nicoVideoInfo); await db.SaveChangesAsync(); } }
public static async Task RemoveRangeAsync(IEnumerable <NicoVideoInfo> removeTargets) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { db.VideoInfos.RemoveRange(removeTargets); await db.SaveChangesAsync(); } }
public static async Task UpdateAsync(NicoVideoInfo info) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { info.LastUpdated = DateTime.Now; db.VideoInfos.Update(info); await db.SaveChangesAsync(); } }
public static void Remove(string rawVideoId) { using (var db = new NicoVideoDbContext()) { var comment = db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId); if (comment != null) { db.Comments.Remove(comment); db.SaveChanges(); } } }
public static void Deleted(string rawVideoId) { using (var db = new NicoVideoDbContext()) { var info = db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId); if (info != null) { info.IsDeleted = true; db.VideoInfos.Update(info); db.SaveChanges(); } } }
public static void Remove(string rawVideoId) { var nicoVideoInfo = Get(rawVideoId); if (nicoVideoInfo == null) { return; } using (var db = new NicoVideoDbContext()) { db.VideoInfos.Remove(nicoVideoInfo); db.SaveChanges(); } }
public static async Task AddOrReplaceAsync(string userId, string name, string iconUrl = null) { using (var releaser = await _AsyncLock.LockAsync()) using (var db = new NicoVideoDbContext()) { bool isAlreadHasUser = db.Users.Any(x => x.UserId == userId); if (isAlreadHasUser) { var info = await db.Users.SingleAsync(x => x.UserId == userId); if (name != null) { info.Name = name; } if (iconUrl != null) { info.IconUri = iconUrl; } db.Users.Update(info); } else { var info = new UserInfo() { UserId = userId, Name = name, IconUri = iconUrl }; db.Users.Add(info); } await db.SaveChangesAsync(); } }
public static async Task <NicoVideoInfo> GetEnsureNicoVideoInfoAsync(string rawVideoId) { using (var db = new NicoVideoDbContext()) { var info = db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId); if (info == null) { info = new NicoVideoInfo() { RawVideoId = rawVideoId, LastUpdated = DateTime.Now }; using (var releaser = await _AsyncLock.LockAsync()) { db.VideoInfos.Add(info); await db.SaveChangesAsync(); } } return(info); } }