Files
ersatztv/ErsatzTV.Infrastructure/Data/Repositories/FFmpegProfileRepository.cs
T
Jason DoveandGitHub d4a2197dfa async fixes (#128)
* refactor local metadata provider

* resolve async warnings

* more async fixes
2021-04-03 11:01:20 -05:00

49 lines
1.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Infrastructure.Data.Repositories
{
public class FFmpegProfileRepository : IFFmpegProfileRepository
{
private readonly TvContext _dbContext;
public FFmpegProfileRepository(TvContext dbContext) => _dbContext = dbContext;
public async Task<FFmpegProfile> Add(FFmpegProfile ffmpegProfile)
{
await _dbContext.FFmpegProfiles.AddAsync(ffmpegProfile);
await _dbContext.SaveChangesAsync();
return ffmpegProfile;
}
public async Task<Option<FFmpegProfile>> Get(int id) =>
await _dbContext.FFmpegProfiles
.Include(p => p.Resolution)
.OrderBy(p => p.Id)
.SingleOrDefaultAsync(p => p.Id == id);
public Task<List<FFmpegProfile>> GetAll() =>
_dbContext.FFmpegProfiles
.Include(p => p.Resolution)
.ToListAsync();
public Task Update(FFmpegProfile ffmpegProfile)
{
_dbContext.FFmpegProfiles.Update(ffmpegProfile);
return _dbContext.SaveChangesAsync();
}
public async Task Delete(int ffmpegProfileId)
{
FFmpegProfile ffmpegProfile = await _dbContext.FFmpegProfiles.FindAsync(ffmpegProfileId);
_dbContext.FFmpegProfiles.Remove(ffmpegProfile);
await _dbContext.SaveChangesAsync();
}
}
}