public ContactResult Delete(int id) { var contactResult = new ContactResult {Success = false}; try { var isValid = _contactInputValidator.IsInputValidForDelete(id); if (isValid) { _contactDataAccessor.Delete(id); contactResult.Success = true; } else { var errorMessage = string.Format(@"Contact could not be deleted. '{0}' is not a valid contact id.", id); contactResult.ErrorMessage = errorMessage; } } catch (Exception) { var errorMessage = string.Format(@"Contact could not be deleted. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; //TODO: Log exception for future diagnosis. } return contactResult; }
public ContactResult Get() { var contactResult = new ContactResult { Success = false }; try { var contactList = _contactDataAccessor.SelectList(); if (contactList != null) { contactResult.Success = true; contactResult.ContactList = contactList; } else { var errorMessage = string.Format(@"Contact list could not be retrieved. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; } } catch (Exception) { var errorMessage = string.Format(@"Contact list could not be retrieved. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; //TODO: Log exception for future diagnosis. } return contactResult; }
public ContactResult Put( [FromUri] int id, [FromUri] string fullName, [FromUri] string address) { var contactResult = new ContactResult { Success = false }; try { var isValid = _contactInputValidator.IsInputValidForUpdate(id, fullName, address); if (isValid) { var contact = _contactDataAccessor.Update(id, fullName, address); if (contact != null) { contactResult.Success = true; contactResult.Contact = contact; } else { var errorMessage = string.Format(@"Contact could not be updated. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; } } else { var errorMessage = String.Format(@"Contact could not be updated. Id must be valid and both full name and address must be provided."); contactResult.ErrorMessage = errorMessage; } } catch (Exception) { var errorMessage = String.Format(@"Contact could not be updated. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; //TODO: Log exception for future diagnosis. } return contactResult; }
public ContactResult Get(int id) { var contactResult = new ContactResult { Success = false }; try { var isValid = _contactInputValidator.IsInputValidForSelect(id); if (isValid) { var contact = _contactDataAccessor.Select(id); if (contact != null) { contactResult.Success = true; contactResult.Contact = contact; } else { var errorMessage = string.Format(@"Contact could not be retrieved. No contact exists with the id '{0}'.", id); contactResult.ErrorMessage = errorMessage; } } else { var errorMessage = String.Format(@"Contact could not be retrieved. '{0}' is not a valid contact id.", id); contactResult.ErrorMessage = errorMessage; } } catch (Exception) { var errorMessage = string.Format(@"Contact could not be retrieved. An unexpected error occured, please try again."); contactResult.ErrorMessage = errorMessage; //TODO: Log exception for future diagnosis. } return contactResult; }