private static string ValidateID(CreateCustomer command, Dictionary <string, Customer> existingCustomers, Source source) { //a use case is that when customers are created through the browser an ID is assigned to them if (source == Source.Web) { if (!string.IsNullOrEmpty(command.id)) { command.LogError(nameof(command.id), "ID can't be set"); } //simplistic way to create new id command.id = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); } else //while when they are created through other means ID is provided to them { //often we need to proceed with processing and we can create temporary values to proceed with furter validations var id = (command.id ?? "TEMP-ID").ToUpperInvariant(); if (string.IsNullOrEmpty(command.id)) { command.LogError(nameof(command.id), "ID must be provided"); } else if (existingCustomers.ContainsKey(id)) { command.LogError(nameof(command.id), "ID already taken"); } command.id = id; } return(command.id); }