public int MatchOrCreatePerson(PersonMatch personMatch) { try { Person person = personMatch.person; Location location = personMatch.location; RockContext context = new RockContext(); PersonService personService = new PersonService(context); var matchPerson = personService.GetByMatch(person.FirstName, person.LastName, person.BirthDate, person.Email, person.PhoneNumbers.Select(pn => pn.Number).FirstOrDefault(), location.Street1, location.PostalCode); if (matchPerson != null && matchPerson.Count() > 0) { return(matchPerson.FirstOrDefault().Id); } else { personService.Add(person); context.SaveChanges(); return(person.Id); } } catch (Exception e) { GenerateResponse(HttpStatusCode.InternalServerError, e.Message); throw e; } }
public ModifyResult Create(Person person) { var modifyResult = new ModifyResult(); // We have a minimum set of data required if (person.LastName == null || person.LastName.Length < 2) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "ShortLastName"; result.Message = "Last name must be at least 2 characters"; modifyResult.ValidationResults.Add(result); } if (person.FirstName == null || person.FirstName.Length < 2) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "ShortFirstName"; result.Message = "First name must be at least 2 characters"; modifyResult.ValidationResults.Add(result); } if (person.BirthDate == null && person.HomePhone == null && person.FirstActiveEmail == null) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "NotEnoughInfo"; result.Message = "At least one of the following fields is required: Birth Date, Home Phone, or Email Adress"; modifyResult.ValidationResults.Add(result); } if (modifyResult.ValidationResults.Count > 0) { modifyResult.Successful = "False"; return modifyResult; } try { PersonMatch pm = new PersonMatch(); pm.FirstName = person.FirstName; pm.LastName = person.LastName; pm.Email = person.FirstActiveEmail; pm.HomePhone = person.HomePhone; if (person.Addresses.Count > 0) { pm.Address.Street = person.Addresses.FirstOrDefault().StreetLine1; pm.Address.City = person.Addresses.FirstOrDefault().City; pm.Address.State = person.Addresses.FirstOrDefault().State; pm.Address.PostalCode = person.Addresses.FirstOrDefault().PostalCode; } Core.Person corePerson = pm.MatchOrCreateArenaPerson(); if (corePerson != null) { modifyResult.Successful = "True"; modifyResult.Link = String.Format("cust/secc/person/{0}", corePerson.PersonID); } } catch (Exception e) { modifyResult.Successful = "False"; modifyResult.ErrorMessage = e.Message; } return modifyResult; }
static void Main(string[] args) { // Collect the data from test cases Reader reader = GetFileFormatFromUser(); if (reader == null) { return; } string dataFileName = GetFilenameFromUser(); if (string.IsNullOrWhiteSpace(dataFileName)) { return; } PersonCollection collection = new PersonCollection() { myReader = reader, MyDataFile = dataFileName }; try { collection.Read(); } catch { Console.WriteLine("Error: Input file not found"); EndProgram(); return; } // Collect output file information Writer writer = GetOutputFileFormatFromUser(); if (writer == null) { return; } string outputFileName = ""; if (writer != Writers[0]) { outputFileName = GetOutputFilenameFromUser(); if (string.IsNullOrWhiteSpace(outputFileName)) { return; } } PersonMatch personMatcher = new PersonMatch() { myWriter = writer, MyOutputFile = outputFileName, myPersonCollection = collection }; //Run algorithm on unmatched pairs and create matched pairs personMatcher.CreateUnmatchedPairs(); personMatcher.myPairs.myAlg = GetAlgorithmFromUser(); personMatcher.RunTest(); personMatcher.Write(); Console.WriteLine(""); EndProgram(); return; }
public ModifyResult Create(Person person) { var modifyResult = new ModifyResult(); // We have a minimum set of data required if (person.LastName == null || person.LastName.Length < 2) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "ShortLastName"; result.Message = "Last name must be at least 2 characters"; modifyResult.ValidationResults.Add(result); } if (person.FirstName == null || person.FirstName.Length < 2) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "ShortFirstName"; result.Message = "First name must be at least 2 characters"; modifyResult.ValidationResults.Add(result); } if (person.BirthDate == null && person.HomePhone == null && person.FirstActiveEmail == null) { ModifyValidationResult result = new ModifyValidationResult(); result.Key = "NotEnoughInfo"; result.Message = "At least one of the following fields is required: Birth Date, Home Phone, or Email Adress"; modifyResult.ValidationResults.Add(result); } if (modifyResult.ValidationResults.Count > 0) { modifyResult.Successful = "False"; return(modifyResult); } try { PersonMatch pm = new PersonMatch(); pm.FirstName = person.FirstName; pm.LastName = person.LastName; pm.Email = person.FirstActiveEmail; pm.HomePhone = person.HomePhone; if (person.Addresses.Count > 0) { pm.Address.Street = person.Addresses.FirstOrDefault().StreetLine1; pm.Address.City = person.Addresses.FirstOrDefault().City; pm.Address.State = person.Addresses.FirstOrDefault().State; pm.Address.PostalCode = person.Addresses.FirstOrDefault().PostalCode; } Core.Person corePerson = pm.MatchOrCreateArenaPerson(); if (corePerson != null) { modifyResult.Successful = "True"; modifyResult.Link = String.Format("cust/secc/person/{0}", corePerson.PersonID); } } catch (Exception e) { modifyResult.Successful = "False"; modifyResult.ErrorMessage = e.Message; } return(modifyResult); }