hn-dotnet/Application/AddLink.cs
2020-12-01 20:36:45 +01:00

34 lines
764 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using HN.Domain;
using MediatR;
namespace HN.Application {
public class AddLinkCommand : IRequest<Guid>
{
public string Url { get; set; }
}
public class AddLinkCommandHandler : IRequestHandler<AddLinkCommand, Guid>
{
private readonly ILinkRepository _repository;
public AddLinkCommandHandler(ILinkRepository repository)
{
this._repository = repository;
}
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
{
var link = Link.FromUrl(request.Url);
await this._repository.AddAsync(link);
return link.Id;
}
}
}