public async Task Create(MediaInfo mediaInfo) { using (var ctx = new EfStorageDbContext()) { var mediaInfoEntity = new EfStorageDbContext.MediaInfoEntity() { UserId = mediaInfo.UserId, MediaId = mediaInfo.MediaId, CreatedAt = mediaInfo.CreatedAt, ContentType = mediaInfo.ContentType, }; ctx.MediaInfo.Add(mediaInfoEntity); await ctx.SaveChangesAsync(); } }
public async Task<bool> InsertOrUpdate(UserInfo userInfo) { using (var ctx = new EfStorageDbContext()) { var userInfoEntity = ctx.UserInfo .Where(x => x.UserId == userInfo.UserId) .FirstOrDefault(); if (userInfoEntity == null) { userInfoEntity = new EfStorageDbContext.UserInfoEntity() { UserId = userInfo.UserId }; ctx.UserInfo.Add(userInfoEntity); } userInfoEntity.AuthHash = userInfo.AuthHash; return (await ctx.SaveChangesAsync() == 1); } }
public async Task Delete(MediaInfo mediaInfo) { using (var ctx = new EfStorageDbContext()) { var target = ctx.MediaInfo.FirstOrDefault(x => x.MediaId == mediaInfo.MediaId); if (target != null) { ctx.MediaInfo.Remove(target); } await ctx.SaveChangesAsync(); } }