C# Linq set merged lists as datasource - c#

I'm currently merging to lists will be the datasource of a gridview. This is my code:
// Get models
var products = await API.Zelkon.Products.GetAll();
var productsCurrencies = await API.Zelkon.CurrenciesBackend.Get();
// Merge lists
var results = products.Item1.Zip(productsCurrencies.Item1, (x, y) => new Tuple<Models.Products, Models.Zelkon.CurrenciesBackend>(x, y));
// Create datasource
var datasource = results.Select(r => new { r.Item2.price, r.Item2.setup_fee, r.Item1.product_number });
GridProducts.DataSource = datasource;
// GridProducts.VisibleColumns("name");
UI.CustomizeGridDefault(GridProducts);
My problem is that the value of r.Item2.setup_fee is always the value of the first row. I have checked the collection and the data is correct there.
Am I doing something wrong?
Below are the structures:
class CurrenciesBackend
{
public string currency_name { get; set; }
public string currency_code { get; set; }
public double price { get; set; }
public double recommended_price { get; set; }
public double setup_fee { get; set; }
public int product_number { get; set; }
}
class Products
{
public string name { get; set; }
public string description { get; set; }
public string invoice_layout { get; set; }
public string layout_number { get; set; }
public string payment_terms_name { get; set; }
public string payment_terms_number { get; set; }
public DateTime creation_date { get; set; }
public int enabled { get; set; }
public int is_subscription { get; set; }
public int is_delivery_required { get; set; }
public int allow_discount { get; set; }
public int allow_trial { get; set; }
public int max_discount { get; set; }
public int max_discount_duration { get; set; }
public int vat_percentage { get; set; }
public int trial_period { get; set; }
public int binding_period { get; set; }
public int days_of_credit { get; set; }
public int unit { get; set; }
public string allowed_country_codes { get; set; }
public int product_number { get; set; }
public int authorize_invoice { get; set; }
}
Thanks in advance

Related

How can I convert a StringContent() type to an object of type <MyModelClass> in C# with Visual Studio 2019

I'm trying to turn the string result below in the first line of code into an object of type "Root.cs". I have "Root.cs" class set up in my Visual Studio 2019 "solution" with proper classes set up to turn the string result into the object.
This line of code works fine to get me the string I need:
var result = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result;
Here's the contents of the string "result":
{"sections":[{"id":"Building_Configuration","name":"Building_Configuration","sections":[{"id":"B uilding_Configuration.Parameters_SP","name":"Building_Configuration.Parameters_SP","sectio ns":[],"variables":[{"id":"Building_Configuration.Parameters_SP.fixtureStrategy_SP","name":"Bui lding_Configuration.Parameters_SP.fixtureStrategy_SP","valueType":"String","distinctValueCou nt":3.0,"allowMultipleAssignments":false,"values":[{"name":"ETA","value":"ETA","properties":[{ "id":"fullyqualifiedname","value":"ETA","type":"String"},{"id":"name","value":"ETA","type":"Stri ng"}],"type":"SingletonValue","assigned":"byDefault","incompatible":false},{"name":"ETD","valu e":"ETD","properties":[{"id":"fullyqualifiedname","value":"ETD","type":"String"},{"id":"name","v alue":"ETD","type":"String"}],"type":"SingletonValue","incompatible":false},{"name":"ETA/ETD", "value":"ETA/ETD","properties":[{"id":"fullyqualifiedname","value":"ETA/ETD","type":"String"},{ "id":"name","value":"ETA/ETD","type":"String"}],"type":"SingletonValue","incompatible":false}],"
Now, I need to create the object of type "Root" (My Model Class) for the purpose of picking and choosing certain values out of it. Shouldn't this line work for that?
Root MyObject = JsonConvert.DeserializeObject<Root>(result);
Here's the definition of Root.cs:
public class Root
{
public List<Sections> sections { get; set; }
public RemovedAssignments removedAssignments { get; set; }
public Arguments arguments { get; set; }
public bool isComplete { get; set; }
public bool isConfigurable { get; set; }
public Debug debug { get; set; }
public string language { get; set; }
public string packagePath { get; set; }
}
public class Sections
{
public string id { get; set; }
public string name { get; set; }
public List<Sections> sections { get; set; }
public List<Variable> variables { get; set; }
public List<Property> properties { get; set; }
}
public class RemovedAssignments
{
public List<VariableAssignment> variableAssignments { get; set; }
public List<object> priceLineAssignments { get; set; }
}
public class Debug
{
public List<ScriptError> scriptError { get; set; }
}
public class Property
{
public string id { get; set; }
public string value { get; set; }
public string type { get; set; }
}
public class ScriptError
{
public string scriptName { get; set; }
public string Error { get; set; }
}
public class Value
{
public string name { get; set; }
public object value { get; set; }
public List<Property> properties { get; set; }
public string type { get; set; }
public string assigned { get; set; }
public bool incompatible { get; set; }
public double? lower { get; set; }
public double? upper { get; set; }
}
public class Value3
{
public string value { get; set; }
public string name { get; set; }
public bool exclude { get; set; }
}
public class Variable
{
public string id { get; set; }
public string name { get; set; }
public string valueType { get; set; }
public double distinctValueCount { get; set; }
public bool allowMultipleAssignments { get; set; }
public List<Value> values { get; set; }
public List<Property> properties { get; set; }
}
public class Variable3
{
public string id { get; set; }
public string name { get; set; }
public string valueType { get; set; }
public bool allowMultipleAssignments { get; set; }
}
public class VariableAssignment
{
public Variable variable { get; set; }
public Value value { get; set; }
}
public class Arguments
{
public Configuration Configuration { get; set; }
}
public class Configuration
{
[JsonProperty("Building_Configuration.Parameters_SP.fixtureStrategy_SP")]
public string BuildingConfigurationParametersSPFixtureStrategySP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.dimensionSelection_SP")]
public string BuildingConfigurationParametersSPDimensionSelectionSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.controllerRobotic_SP")]
public bool BuildingConfigurationParametersSPControllerRoboticSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.controllerBACNet_SP")]
public bool BuildingConfigurationParametersSPControllerBACNetSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.digitalPI_SP")]
public string BuildingConfigurationParametersSPDigitalPISP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.interGroupEmergencyPower_SP")]
public string BuildingConfigurationParametersSPInterGroupEmergencyPowerSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.customJewel_SP")]
public string BuildingConfigurationParametersSPCustomJewelSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.loweringSequenceJewel_SP")]
public string BuildingConfigurationParametersSPLoweringSequenceJewelSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.inServiceJewel_SP")]
public string BuildingConfigurationParametersSPInServiceJewelSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.cat5CableFeetRequired_SP")]
public int BuildingConfigurationParametersSPCat5CableFeetRequiredSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.fiberOpticConnectorsSetOf4_SP")]
public int BuildingConfigurationParametersSPFiberOpticConnectorsSetOf4SP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.cGADevices_SP")]
public int BuildingConfigurationParametersSPCGADevicesSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.fiberOpticCableFeetRequired_SP")]
public int BuildingConfigurationParametersSPFiberOpticCableFeetRequiredSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfGatewayForLiftNet_SP")]
public int BuildingConfigurationParametersSPQtyOfGatewayForLiftNetSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfGroupEthernetBoxWIMSSoftwareOnly_SP")]
public int BuildingConfigurationParametersSPQtyOfGroupEthernetBoxWIMSSoftwareOnlySP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.interGroupStarBox_SP")]
public int BuildingConfigurationParametersSPInterGroupStarBoxSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.mediaConverterAndPowerSource_SP")]
public int BuildingConfigurationParametersSPMediaConverterAndPowerSourceSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfSoftwareSiteKeyJBFiles_SP")]
public int BuildingConfigurationParametersSPQtyOfSoftwareSiteKeyJBFilesSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.doorOpenSignalJewel_SP")]
public bool BuildingConfigurationParametersSPDoorOpenSignalJewelSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.mountingProvisionsForMonitor_SP")]
public bool BuildingConfigurationParametersSPMountingProvisionsForMonitorSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.intercomSpace_SP")]
public bool BuildingConfigurationParametersSPIntercomSpaceSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.specialEngraving_SP")]
public bool BuildingConfigurationParametersSPSpecialEngravingSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.lobbyPanelFinish_SP")]
public string BuildingConfigurationParametersSPLobbyPanelFinishSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.includeAGILEDesignCenter_SP")]
public int BuildingConfigurationParametersSPIncludeAGILEDesignCenterSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyKiosksOver300Ft_SP")]
public int BuildingConfigurationParametersSPQtyKiosksOver300FtSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.dDSecurityInterfaceType_SP")]
public bool BuildingConfigurationParametersSPDDSecurityInterfaceTypeSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.iMSOwnersStandard_SP")]
public int BuildingConfigurationParametersSPIMSOwnersStandardSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfIMSOwnersEnhanced_SP")]
public int BuildingConfigurationParametersSPQtyOfIMSOwnersEnhancedSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.totalGroupHallStation_SP")]
public int BuildingConfigurationParametersSPTotalGroupHallStationSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.totalUnitHallStation_SP")]
public int BuildingConfigurationParametersSPTotalUnitHallStationSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.totalBuildingEquip_SP")]
public int BuildingConfigurationParametersSPTotalBuildingEquipSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.IsSmartRescue10_Bool_SP")]
public bool BuildingConfigurationParametersSPIsSmartRescue10BoolSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.IsSmartRescue5_Bool_SP")]
public bool BuildingConfigurationParametersSPIsSmartRescue5BoolSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.lobbyPanel_SP")]
public string BuildingConfigurationParametersSPLobbyPanelSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfSmartRescuePhone10_StndAlone_SP")]
public int BuildingConfigurationParametersSPQtyOfSmartRescuePhone10StndAloneSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfSmartRescuePhone5_Lobby_SP")]
public int BuildingConfigurationParametersSPQtyOfSmartRescuePhone5LobbySP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfSmartRescuePhone5_StndAlone_SP")]
public int BuildingConfigurationParametersSPQtyOfSmartRescuePhone5StndAloneSP { get; set; }
[JsonProperty("Building_Configuration.Parameters_SP.qtyOfSmartRescuePhone10_Lobby_SP")]
public int BuildingConfigurationParametersSPQtyOfSmartRescuePhone10LobbySP { get; set; }
[JsonProperty("Building_Configuration.Parameters.ASYEAR_INT")]
public int BuildingConfigurationParametersASYEARINT { get; set; }
[JsonProperty("Building_Configuration.Parameters.BLANDINGS")]
public int BuildingConfigurationParametersBLANDINGS { get; set; }
[JsonProperty("Building_Configuration.Parameters.ASTYPE")]
public string BuildingConfigurationParametersASTYPE { get; set; }
[JsonProperty("Building_Configuration.Parameters.ASYEAR")]
public string BuildingConfigurationParametersASYEAR { get; set; }
[JsonProperty("Building_Configuration.Parameters.BLDGNAME")]
public string BuildingConfigurationParametersBLDGNAME { get; set; }
[JsonProperty("Building_Configuration.Parameters.IBCSDS")]
public int BuildingConfigurationParametersIBCSDS { get; set; }
[JsonProperty("Building_Configuration.Parameters.ELEVBASE")]
public int BuildingConfigurationParametersELEVBASE { get; set; }
[JsonProperty("Building_Configuration.Parameters.SEISZONE")]
public string BuildingConfigurationParametersSEISZONE { get; set; }
[JsonProperty("Building_Configuration.Parameters.SEISEQUIP")]
public string BuildingConfigurationParametersSEISEQUIP { get; set; }
[JsonProperty("Building_Configuration.Parameters.ISSEISMIC")]
public string BuildingConfigurationParametersISSEISMIC { get; set; }
[JsonProperty("Building_Configuration.Parameters.IBCSDC")]
public string BuildingConfigurationParametersIBCSDC { get; set; }
[JsonProperty("Building_Configuration.Parameters.IBCIP")]
public string BuildingConfigurationParametersIBCIP { get; set; }
[JsonProperty("Building_Configuration.Parameters.NBCCPDB")]
public string BuildingConfigurationParametersNBCCPDB { get; set; }
[JsonProperty("Building_Configuration.Parameters.NBCCIE")]
public int BuildingConfigurationParametersNBCCIE { get; set; }
[JsonProperty("Building_Configuration.Parameters.NBCCFA")]
public int BuildingConfigurationParametersNBCCFA { get; set; }
[JsonProperty("Building_Configuration.Parameters.NBCCSA02")]
public int BuildingConfigurationParametersNBCCSA02 { get; set; }
[JsonProperty("Building_Configuration.Parameters.BLDGCODE")]
public string BuildingConfigurationParametersBLDGCODE { get; set; }
[JsonProperty("Building_Configuration.Parameters.HALLFIN")]
public string BuildingConfigurationParametersHALLFIN { get; set; }
[JsonProperty("Building_Configuration.Parameters.MRP")]
public string BuildingConfigurationParametersMRP { get; set; }
[JsonProperty("Building_Configuration.Parameters.HALLMAT")]
public string BuildingConfigurationParametersHALLMAT { get; set; }
My "result" and my "Root.cs" class are each larger than the 30,000 characters limit here. So, I've had to only post a portion of my string "result" and my "Root.cs" class. I'm trying to simplify this question. Please forgive me while I learn how to use this...
Answer: I was making the newbie mistake of trying to return a string that I picked out of a "Root.cs" Model class as a Root object. I had the return type of the method set to Root instead of string. Upon changing the return type to string, that part of my solution works fine.
It works fine like this:
public string CreateExecPost(FormData person2){
var payload = new StringContent(newPost, Encoding.UTF8, "application/json");
var result = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result;//result is already in JSON
Root MyObject = JsonConvert.DeserializeObject<Root>(result);
//return MyObject.language; //WORKS
return MyObject.language;
}

Including foreign key values into a DTO for a single record

It's been a while since I have done this, but I know there is an easy way to do this that I have forgotten. Below I have a class designed to populate a single record of a data object. But I cannot get the values from another table (related by foreign key) to populate using the lambda statement because I am missing something (the two values being pulled in from another table below can be seen as dto.LeaseName and dto.CarName). How should I write the lambda for the object dm?
public StationUnloadingLogDTO GetSingleRecordforLog(int Id)
{
StationUnloadingLogDTO dto = new StationUnloadingLogDTO();
StationUnloadingLog dm = new StationUnloadingLog();
dm = entity.StationUnloadingLog
.Where(x => x.Id == Id)
.FirstOrDefault();
dto.Id = dm.Id;
dto.DateLogged = dm.DateLogged;
dto.DriverName = dm.DriverName;
dto.TruckNumber = dm.TruckNumber;
dto.CarName = dm.Carrier.CarName;
dto.CarrierId = dm.CarrierId;
dto.SpecificGravity = dm.SpecificGravity;
dto.LactMeterOpen = dm.LactMeterOpen;
dto.LactMeterClose = dm.LactMeterClose;
dto.EstimatedBarrels = dm.EstimatedBarrels;
dto.TicketNumber = dm.TicketNumber;
dto.LeaseNumber = dm.LeaseNumber;
dto.LeaseName = dm.Company.CmpName;
dto.StationId = dm.StationId;
return dto;
}
Here are the related data classes
namespace Data.Models
{
public partial class Company
{
public Company()
{
StationUnloadingLog = new HashSet<StationUnloadingLog>();
}
public string CmpId { get; set; }
public string CmpName { get; set; }
public string CmpAddress1 { get; set; }
public string CmpAddress2 { get; set; }
public int? CmpCity { get; set; }
public string CmpZip { get; set; }
public string CmpPrimaryphone { get; set; }
public ICollection<StationUnloadingLog> StationUnloadingLog { get; set; }
}
public class StationUnloadingLogDTO
{
public int Id { get; set; }
public DateTime? DateLogged { get; set; }
public string DriverName { get; set; }
public string TruckNumber { get; set; }
public string CarrierId { get; set; }
public string CarName { get; set; }
public decimal? SpecificGravity { get; set; }
public decimal? LactMeterOpen { get; set; }
public decimal? LactMeterClose { get; set; }
public int? EstimatedBarrels { get; set; }
public string TicketNumber { get; set; }
public string LeaseName { get; set; }
public string LeaseNumber { get; set; }
public string StationId { get; set; }
}
public partial class StationUnloadingLog
{
public int Id { get; set; }
public DateTime? DateLogged { get; set; }
public string DriverName { get; set; }
public string TruckNumber { get; set; }
public string CarrierId { get; set; }
public decimal? SpecificGravity { get; set; }
public decimal? LactMeterOpen { get; set; }
public decimal? LactMeterClose { get; set; }
public int? EstimatedBarrels { get; set; }
public string TicketNumber { get; set; }
public string LeaseNumber { get; set; }
public string StationId { get; set; }
public Carrier Carrier { get; set; }
public Company Company { get; set; }
public Tractorprofile Tractorprofile { get; set; }
}
public partial class Carrier
{
public Carrier()
{
StationUnloadingLog = new HashSet<StationUnloadingLog>();
}
public string CarId { get; set; }
public string CarName { get; set; }
public string CarAddress1 { get; set; }
public string CarAddress2 { get; set; }
public int? CtyCode { get; set; }
public string CarZip { get; set; }
public string CarContact { get; set; }
public ICollection<StationUnloadingLog> StationUnloadingLog { get; set; }
}
You should query for your record with child entities like this.
dm = DbSet<StationUnloadingLog>
.Where(x => x.Id == Id).Include(x => x.Carrrier)
.FirstOrDefault();

How to add a list of objects inside a list in C# MVC

I have a view model containing list of sections like below. I need to create a list of ResponseEntryViewModel and add sections and sub sections inside sections and questions inside subsections.
Any suggestions?
public class ResponseEntryViewModel
{
public int TypeID { get; set; }
public string TypeName { get; set; }
public int User_ID { get; set; }
public List<SectionDataModel> Sections{ get; set; }
public ResponseEntryViewModel()
{
Sections = new List<SectionDataModel>();
}
public class SectionDataModel
{
public int SectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int TypeId { get; set; }
public List<SubSectionModel> SubSections { get; set; }
public SectionDataModel()
{
SubSections = new List<SubSectionModel>();
}
}
public class SubSectionModel
{
public int SubSectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int SectionId { get; set; }
public List<QuestionModel> QuestionsList { get; set; }
public SubSectionModel()
{
QuestionsList = new List<QuestionModel>();
}
}
public class QuestionModel
{
public int SubSectionID { get; set; }
public int QuestionID { get; set; }
public string Question { get; set; }
}
}
Try this:
public class ResponseEntryViewModel
{
public int TypeID { get; set; }
public string TypeName { get; set; }
public int User_ID { get; set; }
public List<SectionDataModel> Sections { get; set; }
public ResponseEntryViewModel(SectionDataModel obj)
{
Sections = new List<SectionDataModel>();
Sections.Add(obj);
}
public class SectionDataModel
{
public int SectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int TypeId { get; set; }
public List<SubSectionModel> SubSections { get; set; }
public SectionDataModel(SubSectionModel obj)
{
SubSections = new List<SubSectionModel>();
SubSections.Add(obj);
}
}
public class SubSectionModel
{
public int SubSectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int SectionId { get; set; }
public List<QuestionModel> QuestionsList { get; set; }
public SubSectionModel(QuestionModel obj)
{
QuestionsList = new List<QuestionModel>();
QuestionsList.Add(obj);
}
}
public class QuestionModel
{
public int SubSectionID { get; set; }
public int QuestionID { get; set; }
public string Question { get; set; }
}
}

Form with list of lists

I have been struggling with what seems to me to be a simple thing. I need to create a form with list of lists.
This is the model that I want to make a form of:
public OrderViewModel()
{
DeliveryAddress = new ProjectDeliveryAddressViewModel();
OrderItems = new List<OrderItemView>();
}
public int ProjectDeliveryId { get; set; }
public long ProjectId { get; set; }
[Display(ResourceType = typeof(Res.ViewModels.Common), Name = "CustomerOrderNumber")]
public string CustomerOrderNumber { get; set; }
[Display(ResourceType = typeof(Res.ViewModels.Common), Name = "DeliveryDate")]
public string RequestedDeliveryDate { get; set; }
public ProjectDeliveryAddressViewModel DeliveryAddress { get; set; }
public IList<OrderItemView> OrderItems { get; set; }
}
public class OrderItemView
{
public OrderItemView()
{
Additionalitems = new List<AdditionalItem>();
}
public long ProjectItemId { get; set; }
public string ItemName { get; set; }
public string ImageData { get; set; }
public int Quantity { get; set; }
public decimal Price { get; set; }
public string AaCompany { get; set; }
public string SupplierName { get; set; }
public int SupplierModelId { get; set; }
public IList<AdditionalItem> Additionalitems { get; set; }
}
public class AdditionalItem
{
public string Name { get; set; }
public string Id { get; set; }
public bool Value { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
}
What is the simplest way of doing this so that I can easily post the form to my mvc controller later on?

Cannot convert model type..... to ServiceStack.Text.JsonObject

I'm using ServiceStack.Text to parse WorldWeatherOnline's Marine Api on Monotouch.
This is the error "Cannot implicitly convert type DiveConditions.Model.Weather' toServiceStack.Text.JsonObject'"
Here's the offending method
JsonObject result = JsonObject.Parse(content).ConvertTo(x=> new Weather{
WeatherData = x.Object("weather").ConvertTo(w=> new WeatherData{
RequestDate = DateTime.Parse(x.Get("date")),
MinTempCentigrade = Convert.ToInt32(x.Get("mintempC")),
MaxTempCentigrade = Convert.ToInt32(x.Get("maxtempC")),
HourlyWeather = x.ArrayObjects("hourly").ConvertAll(h => new HourlyWeather{
CloudCover = Convert.ToInt32(h.Get("cloudcover")),
Humidity = Convert.ToInt32(h.Get ("humidity")),
Precipitation = Convert.ToDouble(h.Get ("precipitation")),
Pressure = Convert.ToInt32(h.Get ("pressure")),
SigWaveHeight = Convert.ToDouble(h.Get("sigHeight_m")),
SwellHeight = Convert.ToDouble(h.Get ("swellHeight_m")),
SwellDirection = Convert.ToInt32(h.Get("swellDir")),
SwellPeriod = Convert.ToDouble(h.Get ("swellPeriod_secs")),
TempCentigrade = Convert.ToInt32(h.Get("tempC")),
TempFahrenheit = Convert.ToInt32(h.Get("tempF")),
Time = Convert.ToInt32(h.Get("time")),
Visibility = Convert.ToInt32(h.Get("visibility")),
WaterTempCentigrade = Convert.ToInt32(h.Get("waterTemp_C")),
WaterTempFahrenheit = Convert.ToInt32(h.Get("waterTemp_F")),
WeatherCode = Convert.ToInt32(h.Get("weatherCode")),
WeatherIconUrl = h.Get("weatherIconUrl"),
WindDirection = h.Get("winddir16Point"),
WindDirectionDegrees = Convert.ToInt32(h.Get("winddirDegree")),
WindSpeedKmph = Convert.ToInt32(h.Get("windspeedKmph")),
WindSpeedMph = Convert.ToInt32(h.Get("windspeedMiles"))
})
}),
NearestArea = x.Object("nearest_area").ConvertTo(n => new NearestArea{
MilesFromReq = Convert.ToDouble(n.Get("distance_miles")),
RetLatitude = Convert.ToDouble(n.Get ("latitude")),
RetLongitude = Convert.ToDouble(n.Get ("longitude"))
}),
WeatherRequest = x.Object("request").ConvertTo(r=> new WeatherRequest{
Query = r.Get("query"),
RequestType = r.Get("type")
})
});
Here's the Model
public class Weather{
public WeatherData WeatherData { get; set; }
public NearestArea NearestArea { get; set; }
public WeatherRequest WeatherRequest {get; set;}
}
public class WeatherData
{
public DateTime RequestDate { get; set; }
public int MinTempCentigrade { get; set; }
public int MaxTempCentigrade { get; set; }
public List<HourlyWeather> HourlyWeather { get; set; }
}
public class NearestArea
{
public double RetLatitude { get; set; }
public double RetLongitude { get; set; }
public double MilesFromReq { get; set; }
}
public class WeatherRequest
{
public string Query { get; set; }
public string RequestType { get; set; }
}
public class HourlyWeather
{
public int CloudCover { get; set; }
public int Humidity { get; set; }
public double Precipitation { get; set; }
public int Pressure { get; set; }
public int SwellDirection { get; set; }
public double SigWaveHeight { get; set; }
public double SwellHeight { get; set; }
public double SwellPeriod { get; set; }
public int TempCentigrade { get; set; }
public int TempFahrenheit { get; set; }
public int Time { get; set; }
public int Visibility { get; set; }
public int WaterTempCentigrade { get; set; }
public int WaterTempFahrenheit { get; set; }
public int WeatherCode { get; set; }
public string WeatherIconUrl { get; set; }
public string WindDirection { get; set; }
public int WindDirectionDegrees{ get; set; }
public int WindSpeedKmph { get; set; }
public int WindSpeedMph { get; set; }
}
Can anyone spot what might be causing this?
Thanks in advance

Categories