/// <summary> /// Return list of contact records /// </summary> /// <returns>list of contact DTO</returns> public ContactResponse Get() { ContactResponse response = new ContactResponse(); try { response.contacts = Mapper.Map<List<Contact>, List<ContactBO>>(this.Contactrepository.GetAllContacts()); } catch (Exception e) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occurred, please try again"), ReasonPhrase = "Critical exception" }); } return response; }
/// <summary> /// Returns a single contact record that matches with the id /// </summary> /// <param name="id">contact id</param> /// <returns>single contact DTO</returns> public ContactResponse Get(int id) { ContactResponse response = new ContactResponse(); response.contact = Mapper.Map<Contact, ContactBO>(this.Contactrepository.GetContactById(id)); if(response.contact == null) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No Contact with ID = {0}", id)), ReasonPhrase = "Contact ID Not Found" }; throw new HttpResponseException(resp); } return response; }