Reputation: 23
I have a HttpGet endpoint, and it should return a collection of transfers, I'm using my Entity Transfer
to do that
but I'm trying to change to use my CommandResponse(or viewmodel) GetTransferResponse
, and I don't know how to use my var transfer
in my CommandResponse
I already use it when it's only one transfer, but with a collection, I Don't know how create the constructor in this case, I think it's going to looks like this, but it's going to be a collection:
my repository:
Upvotes: 0
Views: 120
Reputation: 356
You can use extension methods to convert ICollection<Transfer>
to ICollection<GetTransferResponse>
.
Make sure to include:
using System.Linq;
Update your GetAll
method to:
public ICollection<GetTransferResponse> GetAll()
{
var transfer = _repo.GetAll()
.Select(x => new GetTransferResponse(x))
.ToList();
return transfer;
}
Upvotes: 1