Skip to content

Instantly share code, notes, and snippets.

@erikdietrich
Created March 3, 2013 20:07
Show Gist options
  • Save erikdietrich/5078046 to your computer and use it in GitHub Desktop.
Save erikdietrich/5078046 to your computer and use it in GitHub Desktop.
public class SomeClass
{
private readonly List<Customer> _customers = new List<Customer>();
public void AddCustomerForModelIfValid(CustomerModel modelOfCustomer)
{
if (IsModelValidForAdding(modelOfCustomer))
AddCustomerForModel(modelOfCustomer);
}
private bool IsModelValidForAdding(CustomerModel modelOfCustomer)
{
return modelOfCustomer.IsActive && !_customers.Any(c => c.Name == modelOfCustomer.Name);
}
private void AddCustomerForModel(CustomerModel modelOfCustomer)
{
var customerBasedOnModel = new Customer()
{
Name = modelOfCustomer.Name
};
_customers.Add(customerBasedOnModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment