32 lines
1012 B
C#
32 lines
1012 B
C#
using MediatR;
|
|
using Modules.Library.Application.Gateways;
|
|
using Modules.Library.Domain.Entities.MediaContent.Items.Anime;
|
|
|
|
namespace Modules.Library.Application.Commands.Anime.Season;
|
|
|
|
public class AddEpisodeCommand : IRequest<Guid>
|
|
{
|
|
public Guid TitleId { get; set; }
|
|
public Guid SeasonId { get; set; }
|
|
public AnimeEpisodeType Type { get; set; }
|
|
|
|
}
|
|
|
|
public enum AnimeEpisodeType
|
|
{
|
|
Regilar,
|
|
FullLength,
|
|
Ova,
|
|
}
|
|
|
|
public class AddEpisodeCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<AddEpisodeCommand, Guid>
|
|
{
|
|
public async Task<Guid> Handle(AddEpisodeCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var title = await titleGateway.GetById(request.TitleId);
|
|
var season = title.Items.OfType<AnimeSeason>().First(q => q.Id == request.SeasonId);
|
|
var episode = season.AddEpisode((Domain.Entities.MediaContent.Items.Anime.AnimeEpisodeType)request.Type);
|
|
await titleGateway.Update(title);
|
|
return episode.Id;
|
|
}
|
|
} |