My user can delete multiple entities in a DataGrid. Should I create now a DeleteCustomer method in my customerService class
like
Presenter/ViewModel:
public void DeleteCustomers()
{
foreach(...SelectedCustomers)
{
customerService.DeleteCustomer(item);
}
}
OR
public void DeleteCustomers()
{
customerService.DeleteCustomers(SelectedCustomers);
// The DataProvider is enumerating the list...
}
What do you think is better?
You've already answered the question yourself. In deleting a singular customer, you call:
customerService.DeleteCustomer(item);
This indicates that you are passing the items to be deleted back to the service (which here is really an abstraction over a specific way of how to handle customers). You are making a clear indication that the service has the best knowledge as to how to perform this operation.
To that end, deleting multiple customers should be like the latter option:
customerService.DeleteCustomers(SelectedCustomers);
You gain a few benefits here: