public Contoso.Apps.Insurance.Data.DTOs.Person GetPerson(int id) { Contoso.Apps.Insurance.Data.DTOs.Person person; using (var ctx = new ContosoInsuranceContext()) { person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id)); } return(person); }
// GET api/people/5 public Data.DTOs.Person GetPerson(int id) { Data.DTOs.Person person; using (var ctx = new ContosoInsuranceContext(_connectionString)) { person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id)); } return(person); }
public static DTOs.Dependent MapEntityToDto(Dependent source) { var destination = new DTOs.Dependent { Id = source.Id, Active = source.Active, PersonId = source.PersonId, PolicyHolderId = source.PolicyHolderId, PolicyHolderName = $"{source.PolicyHolder?.Person?.LName}, {source.PolicyHolder?.Person?.FName}" }; //if (source.PolicyHolder != null) //{ // destination.PolicyHolder = PolicyHolderMapping.MapEntityToDto(source.PolicyHolder); //} if (source.Person != null) { destination.Person = PersonMapping.MapEntityToDto(source.Person); } return(destination); }