Example #1
0
        //Get all requests with supplies
        // Default
        // RETURNS ONE SUPPLY REQUEST BY TENANT ID WITH: Mapping with Supplies
        // change all
        public IEnumerable <SupplyRequestWithTenant> GetSupplyRequestWithSuppliesAll()
        {
            var content = db.SupplyRequests.ToList();

            if (content.Count() == 0)
            {
                return(null);
            }
            else
            {
                List <SupplyRequestWithTenant> requests = new List <SupplyRequestWithTenant>();
                RequestSuppliesMapsHelper      map      = new RequestSuppliesMapsHelper();
                TenantsHelper tenant = new TenantsHelper();
                foreach (var item in content)
                {
                    SupplyRequestWithTenant request = new SupplyRequestWithTenant
                    {
                        SupplyRequestId = item.supplyRequestId,
                        TenantId        = item.tenantId ?? default(int),
                        Active          = item.active ?? default(bool),

                        RequestSuppliesMaps = map.GetRequestSuppliesMapsWithSupplyByRequest(item.supplyRequestId),
                        Tenant = tenant.GetTenantForRequests(item.tenantId ?? 0)
                    };
                    requests.Add(request);
                }
                return(requests);
            }
        }
        // Get One basic table, used for housing maintenace request
        // DEFAULT
        // RETURNS A LIST OF MAINTENANCE REQUESTS ALL
        // change
        public IEnumerable <MaintenanceRequestWithTenantMapper> GetMaintenanceRequestsAll()
        {
            var content = db.MaintenanceRequests.ToList();

            if (content.Count() == 0)
            {
                return(null);
            }
            else
            {
                List <MaintenanceRequestWithTenantMapper> requests = new List <MaintenanceRequestWithTenantMapper>();
                TenantsHelper tenant = new TenantsHelper();
                foreach (var item in content)
                {
                    MaintenanceRequestWithTenantMapper request = new MaintenanceRequestWithTenantMapper
                    {
                        Active = item.active ?? default(bool),
                        MaintenanceRequestId = item.maintenanceRequestId,
                        Message  = item.message,
                        TenantId = item.tenantId ?? default(int),

                        Tenant = tenant.GetTenantForRequests(item.tenantId ?? 0)
                    };
                    requests.Add(request);
                }
                return(requests);
            }
        }
        // Get All supply request by House Unit/tenat
        // DEFAULT
        // RETURNS ALL THE HOUSING UNITS WITH: Address, and Tenants with Supply Requests
        public IEnumerable <HousingUnitProviderTenantSupplyMapper> GetHousingUnitsSupplyRequest(int housingUnitId)
        {
            var content = db.HousingUnits.Where(j => j.housingUnitId == housingUnitId).ToList();

            if (content.Count() == 0)
            {
                return(null);
            }
            else
            {
                List <HousingUnitProviderTenantSupplyMapper> housingUnits = new List <HousingUnitProviderTenantSupplyMapper>();
                AddressesHelper address = new AddressesHelper();
                TenantsHelper   tenants = new TenantsHelper();
                foreach (var item in content)
                {
                    HousingUnitProviderTenantSupplyMapper housingUnit = new HousingUnitProviderTenantSupplyMapper
                    {
                        HousingUnitId    = item.housingUnitId,
                        ProviderId       = item.providerId ?? 0,
                        AddressId        = item.addressId ?? 0,
                        HousingSignature = item.housingSignature,
                        Capacity         = item.capacity,

                        Address = address.GetAddress(item.addressId ?? 0),
                        Tenants = tenants.GetTenantsWithSupplies(item.housingUnitId)
                    };
                    housingUnits.Add(housingUnit);
                }
                return(housingUnits);
            }
        }
        // Get One housing unit with Tenants
        // DEFAULT
        // RETURNS ONE HOUSING UNIT WITH: Tenants with Batch, Contact, Gender, and Car Relationship
        public HousingUnitTenantInfoMapper GetHousingUnitWithTenants(int housingUnitId)
        {
            var content = db.HousingUnits.Where(j => j.housingUnitId == housingUnitId).FirstOrDefault();

            if (content == null)
            {
                return(null);
            }
            else
            {
                AddressesHelper             address     = new AddressesHelper();
                TenantsHelper               tenants     = new TenantsHelper();
                HousingUnitTenantInfoMapper housingUnit = new HousingUnitTenantInfoMapper()
                {
                    HousingUnitId    = content.housingUnitId,
                    ProviderId       = content.providerId ?? 0,
                    AddressId        = content.addressId ?? 0,
                    HousingSignature = content.housingSignature,
                    Capacity         = content.capacity,

                    Address = address.GetAddress(content.addressId ?? 0),
                    Tenants = tenants.GetTenantsWithInfoByHousing(content.housingUnitId)
                };
                return(housingUnit);
            }
        }
        // Get All housing units with Tenants
        // DEFAULT
        // RETURNS ALL THE HOUSING UNITS WITH: Tenants with Batch, Contact, Gender, and Car Relationship
        public IEnumerable <HousingUnitAvailableMapper> GetHousingUnitsWithTenantsAvailable()
        {
            var content = db.HousingUnits.Where(j => j.housingUnitId != 0).ToList();

            if (content.Count() == 0)
            {
                return(null);
            }
            else
            {
                List <HousingUnitAvailableMapper> housingUnits = new List <HousingUnitAvailableMapper>();
                AddressesHelper address = new AddressesHelper();
                TenantsHelper   tenants = new TenantsHelper();
                foreach (var item in content)
                {
                    HousingUnitAvailableMapper housingUnit = new HousingUnitAvailableMapper()
                    {
                        HousingUnitId    = item.housingUnitId,
                        ProviderId       = item.providerId ?? 0,
                        AddressId        = item.addressId ?? 0,
                        HousingSignature = item.housingSignature,
                        Capacity         = item.capacity,

                        Address = address.GetAddress(item.addressId ?? 0),
                        Tenants = tenants.GetTenantsWithInfoByHousing(item.housingUnitId)
                    };

                    if (housingUnit.Tenants != null)
                    {
                        housingUnit.Occupied  = housingUnit.Tenants.Count();
                        housingUnit.Available = housingUnit.Capacity - housingUnit.Tenants.Count();
                    }
                    else
                    {
                        housingUnit.Occupied  = 0;
                        housingUnit.Available = housingUnit.Capacity;
                    }

                    housingUnits.Add(housingUnit);
                }
                return(housingUnits);
            }
        }
        // Get One housing unit with Tenants
        // DEFAULT
        // RETURNS ONE HOUSING UNIT WITH: Tenants with Batch, Contact, Gender, and Car Relationship
        public HousingUnitAvailableMapper GetHousingUnitsWithTenantsAvailable(int housingUnitId)
        {
            var content = db.HousingUnits.Where(j => j.housingUnitId == housingUnitId).FirstOrDefault();

            if (content == null)
            {
                return(null);
            }
            else
            {
                AddressesHelper            address     = new AddressesHelper();
                TenantsHelper              tenants     = new TenantsHelper();
                HousingUnitAvailableMapper housingUnit = new HousingUnitAvailableMapper()
                {
                    HousingUnitId    = content.housingUnitId,
                    ProviderId       = content.providerId ?? 0,
                    AddressId        = content.addressId ?? 0,
                    HousingSignature = content.housingSignature,
                    Capacity         = content.capacity,

                    Address = address.GetAddress(content.addressId ?? 0),
                    Tenants = tenants.GetTenantsWithInfoByHousing(content.housingUnitId)
                };

                if (housingUnit.Tenants != null)
                {
                    housingUnit.Occupied  = housingUnit.Tenants.Count();
                    housingUnit.Available = housingUnit.Capacity - housingUnit.Tenants.Count();
                }
                else
                {
                    housingUnit.Occupied  = 0;
                    housingUnit.Available = housingUnit.Capacity;
                }

                return(housingUnit);
            }
        }
        // Get One batch with its tenants
        // DEFAULT
        // RETURNS A BATCH WITH: Tenants with Housing unitt with Address, Contact, Gender and Car relationship
        public BatchTenantMapper GetBatchwithHousingAddress(int batchId)
        {
            var content = db.Batches.FirstOrDefault(j => j.batchId == batchId);

            if (content == null)
            {
                return(null);
            }
            else
            {
                TenantsHelper     tenants = new TenantsHelper();
                BatchTenantMapper batch   = new BatchTenantMapper
                {
                    BatchId   = content.batchId,
                    StartDate = content.startDate ?? default(DateTime),
                    EndDate   = content.endDate ?? default(DateTime),
                    Name      = content.name,

                    Tenant = tenants.GetTenantsAddressByBatch(content.batchId)
                };
                return(batch);
            }
        }