trycatch39ni trycatch39ni - 1 month ago 13
ASP.NET (C#) Question

Combine to lists of same type but less fields in each

I am trying to cobine three lists that will always return certain properties out of a list of assets i need to combine these three lists into one list. But not all fields of the master list is filled in

List<Asset> allAssets = new List<Asset>();

List<Asset> _vheiclesList = new List<Asset>();

_vheiclesList = getallVechiclesForSlate();

List<Asset> _propertyList = new List<Asset>();

_vheiclesList = getAllPropertyForSlate();



var AllAssets = allAssets.Concat(_vheiclesList)
.Concat(_propertyList)
.ToList();

_createCase.Assets = AllAssets;


But i am getting a nullable object must have a value and I dont no why.

public List<Asset> getAllPropertyForSlate()
{

try
{


List<tbl_Property> _property = new List<tbl_Property>();
Asset _asset = new Asset();

_property = dal.GetPropertiesById(caseid);
foreach (var property in _property)
{

_asset.Id = Guid.NewGuid();
_asset.AssetType =(int) slateExportsConstants.AsssetTypes.Property;

_asset.Description = property.addressLine1 + " " + property.addressLine2 + property.county + " " + property.country + " " + property.postCode;
_asset.CurrentValue =(int) Math.Round(Convert.ToDecimal(property.valueOfProperty.Value));

string valuationDateIso = JsonConvert.SerializeObject(property.dateofValuation.Value);
_asset.ValuationDate = valuationDateIso;
if (property.thirdPartyOwner == new Guid(fhsConstants.fhsPartner))
{
_asset.Owner = (int)slateExportsConstants.Applicant.Applicant2;
}
else if (property.thirdPartyOwner == new Guid(fhsConstants.fhsExPartner))
{
_asset.Owner = (int)slateExportsConstants.Applicant.Joint; }

if(property.isHomeAddress==true)
{
_asset.Home =(bool) property.isHomeAddress;

}


if (property.housingAssoication == true)
{
_asset.HousingAssociation = property.housingAssoicationShare.ToString();

}

if (property.isHomeAddress == true)
{
_asset.Home = true;
}


_asset.Equity = Convert.ToInt32(property.valueOfEquity);

_asset.IsSharedOwnership = property.coOwnerdByAnyOtherParty;

_assets.Add(_asset);
}
return _assets;

}
catch(Exception ex)
{

return null;
}
}



public class Asset
{
public Guid Id { get; set; }
public string Description { get; set; }
public int CurrentValue { get; set; }
public string ValuationDate { get; set; }
public int Owner { get; set; }
public int OutstandingFinance { get; set; }
public int FinanceAccountHolder { get; set; }
public int FinanceMonthlyPayment { get; set; }
public DateTime FinanceEndDate { get; set; }
public bool Home { get; set; }
public int AssetType { get; set; }
public DateTime FixedPeriodEndDate { get; set; }
public int ValuationSource { get; set; }
public int Equity { get; set; }
public bool IsSharedOwnership { get; set; }
public string HousingAssociation { get; set; }
public int HousingAssociationShareOfPropertyPercent { get; set; }
public bool BeneficialInterest { get; set; }
public int JointOwner1 { get; set; }
public int JointOwner2 { get; set; }
public string JointOwner3 { get; set; }
public int RentalIncome { get; set; }
public string AccountNumber { get; set; }
public string PropertySecuredAgainstId { get; set; }
public string FinanceCompany { get; set; }
}

Answer

Is it because of the line:

_vheiclesList = getAllPropertyForSlate();

Should it read:

_propertyList = getAllPropertyForSlate();