mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
using System; |
|
using System.Threading; |
|
using System.Threading.Tasks; |
|
using ErsatzTV.Core; |
|
using ErsatzTV.Core.Domain.Filler; |
|
using ErsatzTV.Infrastructure.Data; |
|
using LanguageExt; |
|
using MediatR; |
|
using Microsoft.EntityFrameworkCore; |
|
using Unit = LanguageExt.Unit; |
|
|
|
namespace ErsatzTV.Application.Filler.Commands |
|
{ |
|
public class CreateFillerPresetHandler : IRequestHandler<CreateFillerPreset, Either<BaseError, Unit>> |
|
{ |
|
private readonly IDbContextFactory<TvContext> _dbContextFactory; |
|
|
|
public CreateFillerPresetHandler(IDbContextFactory<TvContext> dbContextFactory) |
|
{ |
|
_dbContextFactory = dbContextFactory; |
|
} |
|
|
|
public async Task<Either<BaseError, Unit>> Handle(CreateFillerPreset request, CancellationToken cancellationToken) |
|
{ |
|
try |
|
{ |
|
await using TvContext dbContext = _dbContextFactory.CreateDbContext(); |
|
|
|
var fillerPreset = new FillerPreset |
|
{ |
|
Name = request.Name, |
|
FillerKind = request.FillerKind, |
|
FillerMode = request.FillerMode, |
|
Duration = request.Duration, |
|
Count = request.Count, |
|
PadToNearestMinute = request.PadToNearestMinute, |
|
CollectionType = request.CollectionType, |
|
CollectionId = request.CollectionId, |
|
MediaItemId = request.MediaItemId, |
|
MultiCollectionId = request.MultiCollectionId, |
|
SmartCollectionId = request.SmartCollectionId |
|
}; |
|
|
|
await dbContext.FillerPresets.AddAsync(fillerPreset, cancellationToken); |
|
await dbContext.SaveChangesAsync(cancellationToken); |
|
|
|
return Unit.Default; |
|
} |
|
catch (Exception ex) |
|
{ |
|
return BaseError.New(ex.Message); |
|
} |
|
} |
|
} |
|
}
|
|
|