// INSIDE HELPER: USED BY REQUESTS // RETURNS A TENANT BY ID WITH: Housing unit with Address public TenantRequestMapper GetTenantForRequests(int tenantId) { var content = db.Tenants.FirstOrDefault(j => j.tenantId == tenantId); if (content == null) { return(null); } else { HousingUnitsHelper housingUnits = new HousingUnitsHelper(); ContactsHelper contact = new ContactsHelper(); TenantRequestMapper tenant = new TenantRequestMapper { TenantId = content.tenantId, ContactId = content.contactId ?? 0, BatchId = content.batchId ?? 0, HousingUnitId = content.housingUnitId ?? 0, GenderId = content.genderId ?? 0, MoveInDate = content.moveInDate, HasMoved = content.hasMoved ?? default(bool), HasKey = content.hasKey ?? default(bool), HousingUnit = housingUnits.GetHousingUnitWithAddress(content.housingUnitId ?? 0), Contact = contact.GetContact(content.contactId ?? 0) }; return(tenant); } }
// DEFAULT // RETURNS TENANTS WITH: Housing unitt with Address, batch, contact, gender and car Relationship public IEnumerable <TenantInfoMapper> GetTenantsInfo() { var content = db.Tenants.ToList(); if (content.Count() == 0) { return(null); } else { List <TenantInfoMapper> tenants = new List <TenantInfoMapper>(); HousingUnitsHelper housingUnits = new HousingUnitsHelper(); BatchesHelpers batch = new BatchesHelpers(); ContactsHelper contact = new ContactsHelper(); GendersHelper gender = new GendersHelper(); TenantCarRelationshipsHelper tenantCarRelationships = new TenantCarRelationshipsHelper(); foreach (var item in content) { TenantInfoMapper tenant = new TenantInfoMapper { TenantId = item.tenantId, ContactId = item.contactId ?? 0, BatchId = item.batchId ?? 0, HousingUnitId = item.housingUnitId ?? 0, GenderId = item.genderId ?? 0, MoveInDate = item.moveInDate, HasMoved = item.hasMoved ?? default(bool), HasKey = item.hasKey ?? default(bool), HousingUnit = housingUnits.GetHousingUnitWithAddress(item.housingUnitId ?? 0), Batch = batch.GetBatch(item.batchId ?? 0), Contact = contact.GetContact(item.contactId ?? 0), Gender = gender.GetGender(item.genderId ?? 0), TenantCarRelationships = tenantCarRelationships.GetTenantCarRelationship(item.tenantId) }; tenants.Add(tenant); } return(tenants); } }
// DEFAULT: ONE TENANT WITH ALL INFO // RETURNS A TENANT BY ID WITH: Housing unit with Address, Batch, Contact, Gender and Car Relationship public TenantInfoMapper GetTenantInfo(int contactId) { var content = db.Tenants.FirstOrDefault(j => j.contactId == contactId); if (content == null) { return(null); } else { HousingUnitsHelper housingUnits = new HousingUnitsHelper(); BatchesHelpers batch = new BatchesHelpers(); ContactsHelper contact = new ContactsHelper(); GendersHelper gender = new GendersHelper(); TenantCarRelationshipsHelper car = new TenantCarRelationshipsHelper(); TenantInfoMapper tenant = new TenantInfoMapper { TenantId = content.tenantId, ContactId = content.contactId ?? 0, BatchId = content.batchId ?? 0, HousingUnitId = content.housingUnitId ?? 0, GenderId = content.genderId ?? 0, MoveInDate = content.moveInDate, HasMoved = content.hasMoved ?? default(bool), HasKey = content.hasKey ?? default(bool), HousingUnit = housingUnits.GetHousingUnitWithAddress(content.housingUnitId ?? 0), Batch = batch.GetBatch(content.batchId ?? 0), Contact = contact.GetContact(content.contactId ?? 0), Gender = gender.GetGender(content.genderId ?? 0), TenantCarRelationships = car.GetTenantCarRelationship(content.tenantId) }; return(tenant); } }