This is my model class.
In RootObject class I have a list of Trans class.In .net core when I am passing values to RootObject through Postman,I am getting null in RootObject.
public class Trans
{
public string SubDetailID { get; set; }
public string TrnType { get; set; }
public decimal amount { get; set; }
public string BankCurrencyRate { get; set; }
public decimal AccountID { get; set; }
public string Currency { set; get; }
public string CurrencyRate { set; get; }
public decimal JVID { get; set; }
public string coa { get; set; }
public decimal BusinessID { get; set; }
}
public class RootObject
{
public int JVID { get; set; }
public string InvoiceRef { get; set; }
public DateTime JVDate { get; set; }
public string StoreID { get; set; }
public decimal BusinessID { get; set; }
public string UserID { get; set; }
public string Currency { get; set; }
public string Rate { get; set; }
public DateTime DueDate { get; set; }
public string Reference { get; set; } = "Client";
public decimal RefID { get; set; }
public string Narration { get; set; }
public string Type { get; set; } = "CA";
public virtual List<Trans> transaction { get; set; }
}
Related
I want to map MinerStatus from Entity.Miner.
I tried to include Miner entity in Issue entity, but it did not happen.
Service
Mapping profiles
I need to do it with AutoMapper, but it returns null.
This is my code:
Issue entity:
namespace Mining_Automation.Entities;
[Table("Issues")]
public class Issue : EntityBase, IAuditableEntity
{
public string? DescriptionForReportIssues { get; set; }
public string? ObjectsInMonitoringRoom { get; set; }
public bool? IsReadyToSendToFarm { get; set; }
public StatusInIssue? CurrentStatusInIssue { get; set; }
public long MinerId { get; set; }
public string Date { get; set; }
public string Time { get; set; } = TimeOnly.FromDateTime(DateTime.UtcNow).ToString();
public string? ProblemDescription { get; set; }
public string? Description { get; set; }
public string? TestRoomDescription { get; set; }
public string? RepairRoomDescription{ get; set; }
public string? RepairRoomIssueDescription { get; set; }
public Miner Miner { get; set; }
}
Miner entity:
namespace Mining_Automation.Entities;
[Table("Miners")]
public class Miner: EntityBase , IAuditableEntity
{
public string MinerName { get; set; }
public string AssetTag { get; set; }
public string MinerSerialNumber { get; set; }
public bool IsMinerActive { get; set; }
public long MinerStatus { get; set; }
public string WorkerName { get; set; }
public string? MinerDescription { get; set; }
public long FarmId { get; set; }
public Farm Farm { get; set; }
public ICollection<Issue> Issues{ get; set; }
public virtual MinerParts MinerParts { get; set; }
public ICollection<WatcherDataByMiner> WatcherDataByMiner { get; set; }
}
AllIssues view model:
namespace Mining_Automation.ViewModels.Issue;
public class ShowAllIssues
{
public long MinerId { get; set; }
public long IssueId { get; set; }
public string Date { get; set; }
public string WorkerName { get; set; }
public string MinerSerialNumber { get; set; }
public MinerStatus MinerStatus { get; set; }
public string DescriptionForReportIssues { get; set; }
public string ObjectsInMonitoringRoom { get; set; }
public bool IsReadyToSendToFarm { get; set; } = false;
public string ProblemDescription { get; set; }
public bool IsDeleted { get; set; }
public long Id { get; set; }
#endregion
}
I am starting to use AutoMapper. What I want is to do the following one-to-many mapping:
public class EntityEstablishment
{
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public int NumberParking { get; set; }
public string EstablishmentImage { get; set; }
public string EstablishmentLogoForDesktop { get; set; }
public string EstablishmentLogoForMobile { get; set; }
public string EstablishmentMap { get; set; }
public int WidthMap { get; set; }
public int HeightMap { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string Status { get; set; } = "enabled";
public bool AvailableToBooking { get; set; } = true;
public string UserId { get; set; }
public EntityUser User { get; set; }
public List<EntityEquipment> Equipments { get; set; }
public List<EntityBookableArea> BookableAreas { get; set; }
public List<EntityParking> Parkings { get; set; }
public List<EntityBankAccount> BankAccounts { get; set; }
}
public class EntityBookableArea
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public BookableAreaType Type { get; set; }
public int Capacity { get; set; }
public int StoreyNumber { get; set; }
public double ValueHour { get; set; }
public double ValueMidday { get; set; }
public double ValueDay { get; set; }
public double ValueWeek { get; set; }
public double ValueHalfMonth { get; set; }
public double ValueMonth { get; set; }
public double ValueSesion { get; set; }
public double ValueHourByStall { get; set; }
public double ValueMiddayByStall { get; set; }
public double ValueDayByStall { get; set; }
public double ValueWeekByStall { get; set; }
public double ValueHalfMonthByStall { get; set; }
public double ValueMonthByStall { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string BookableDays { get; set; }
public string BookableClass { get; set; }
public string Status { get; set; }
public double TaxPercentage { get; set; }
public bool IncludeEquipment { get; set; }
public bool IncludeParking { get; set; }
public string Coordinates { get; set; }
public List<EntityBooking> Bookings { get; set; }
public int EstablishmentId { get; set; }
public EntityEstablishment Establishment { get; set; }
}
public class EstablishmentDto
{
public int Id { get; set; }
[Required(ErrorMessage = "El nombre es requerido.")]
public string Name { get; set; }
[Required(ErrorMessage = "La ubicacion es requerida.")]
public string Location { get; set; }
public int NumberParking { get; set; }
public string EstablishmentImage { get; set; }
public string EstablishmentLogoForDesktop { get; set; }
public string EstablishmentLogoForMobile { get; set; }
public string EstablishmentMap { get; set; }
public int WidthMap { get; set; }
public int HeightMap { get; set; }
[Required]
public DateTime StartTime { get; set; }
[Required]
public DateTime EndTime { get; set; }
public string Status { get; set; } = "enabled";
public bool AvailableToBooking { get; set; } = true;
[Required(ErrorMessage = "El Administrador del establecimiento es requerido.")]
public string UserId { get; set; }
public UserDto User { get; set; }
public List<EquipmentDto> Equipments { get; set; }
public List<ParkingDto> Parkings { get; set; }
public List<BookableAreaDto> BookableAreas { get; set; }
public List<BankAccountDto> BankAccounts { get; set; }
}
How can I map the one-to-many relationship to get the information from the establishment with the BookableAreas?
I was trying the following but I get a mapping error - can you guide me on the matter?
Thank you very much for any help.
CreateMap<EntityEstablishment, EstablishmentDto>()
.ForMember(dest => dest.BookableAreas, opt => opt.MapFrom(src => src.BookableAreas))
.ForMember(dest => dest.Parkings, opt => opt.MapFrom(src => src.Parkings))
i have this Json
{
"queryresult":{
"responseMessage":"success",
"customer":{
"accountNumber":"8292829222",
"meterNumber":"",
"phoneNumber":"",
"lastName":"CHRISTIAN ",
"address":"2 OSISIOMA NGWA, ABIA",
"city":null,
"district":"Damata",
"userCategory":"NON-MD",
"customerType":"unmetered",
"paymentPlan":"Postpaid",
"vat":463.8525,
"tariffCode":"R2SC-NMD",
"tariffRate":53.78,
"arrearsBalance":129324.8435,
"billedAmount":6184.7,
"billedDate":"08-2022",
"lastPayDate":null,
"lastpayment":{
}
},
"responseCode":200,
"status":"true"
},
"status":true
}
When i deserialize with
var data = JsonConvert.DeserializeObject<Data>(readTask);
it throws and error saying
Input String '463.8525' is not a valid integer
which is the vat field
How do i solve this issue? below is my model
public class customer
{
public string accountNumber { get; set; }
public string meterNumber { get; set; }
public string phoneNumber { get; set; }
public string lastName { get; set; }
public string address { get; set; }
public object city { get; set; }
public string district { get; set; }
public string userCategory { get; set; }
public string customerType { get; set; }
public string paymentPlan { get; set; }
public double vat { get; set; }
public string tariffCode { get; set; }
public double tariffRate { get; set; }
public double? arrearsBalance { get; set; }
public double billedAmount { get; set; }
public string? billedDate { get; set; }
public string? lastPayDate { get; set; }
public Lastpayments lastpayment { get; set; }
}
public class Lastpayments
{
public string transactionRef { get; set; }
public int units { get; set; }
public string transactionDate { get; set; }
public string transactionId { get; set; }
public int transactionBookId { get; set; }
public int? amountPaid { get; set; }
public int mscPaid { get; set; }
public string invoiceNumber { get; set; }
}
public class Queryresults
{
public string responseMessage { get; set; }
public customer customer { get; set; }
public int responseCode { get; set; }
public string status { get; set; }
}
public class Data
{
public Queryresults queryresult { get; set; }
public bool status { get; set; }
}
The error points to the vat field. I tried using [JsonIgnore] to Ignore the vat field as i dont really need it but it dint work
Hi I am trying to deserialize this json. And my application does not do it for me.
i am using c#
any suggestion? thanks
this way i try to deserialize
var deserialize = resultado.Content.ReadAsStringAsync().Result;
var a = JsonConvert.DeserializeObject<product>(deserialize);
json received
{"product":{"id":6979552313549,"title":"Balance 100% Whey Protein 2.8kg w\/ FREE Magnesium complete powder","body_html":"Mountaineering backpack","vendor":"Balance","product_type":"physical","created_at":"2022-05-16T17:41:57-06:00","handle":"balance-100-whey-protein-2-8kg-w-free-magnesium-complete-powder-1","updated_at":"2022-05-26T12:34:07-06:00","published_at":"2022-05-16T17:41:57-06:00","template_suffix":null,"status":"active","published_scope":"web","tags":"Protein Powders, Specials, Stacks and Packs, Whey Protein Blend (WPI\/WPC)","admin_graphql_api_id":"gid:\/\/shopify\/Product\/6979552313549","variants":[{"id":40875072585933,"product_id":6979552313549,"title":"Default Title","price":"700.00","sku":"","position":1,"inventory_policy":"deny","compare_at_price":null,"fulfillment_service":"manual","inventory_management":"shopify","option1":"Default Title","option2":null,"option3":null,"created_at":"2022-05-26T12:34:07-06:00","updated_at":"2022-05-26T12:34:07-06:00","taxable":true,"barcode":null,"grams":0,"image_id":null,"weight":0.0,"weight_unit":"kg","inventory_item_id":42969806831821,"inventory_quantity":0,"old_inventory_quantity":0,"requires_shipping":true,"admin_graphql_api_id":"gid:\/\/shopify\/ProductVariant\/40875072585933"}],"options":[{"id":8937193341133,"product_id":6979552313549,"name":"Title","position":1,"values":["Default Title"]}],"images":[{"id":30230589407437,"product_id":6979552313549,"position":1,"created_at":"2022-05-26T12:34:07-06:00","updated_at":"2022-05-26T12:34:07-06:00","alt":null,"width":2862,"height":2143,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/0618\/4189\/9725\/products\/Definici_C3_B3n-del-producto-y-servicio_0bf23268-fee3-4b3b-a577-aeaa2336d6fc.png?v=1653590047","variant_ids":[],"admin_graphql_api_id":"gid:\/\/shopify\/ProductImage\/30230589407437"}],"image":{"id":30230589407437,"product_id":6979552313549,"position":1,"created_at":"2022-05-26T12:34:07-06:00","updated_at":"2022-05-26T12:34:07-06:00","alt":null,"width":2862,"height":2143,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/0618\/4189\/9725\/products\/Definici_C3_B3n-del-producto-y-servicio_0bf23268-fee3-4b3b-a577-aeaa2336d6fc.png?v=1653590047","variant_ids":[],"admin_graphql_api_id":"gid:\/\/shopify\/ProductImage\/30230589407437"}}}
If I have a Model class called "Product"
public class product
{
public long id { get; set; }
public string title { get; set; }
public string body_html { get; set; }
public string vendor { get; set; }
public string product_type { get; set; }
public DateTime created_at { get; set; }
public string handle { get; set; }
public DateTime updated_at { get; set; }
public DateTime published_at { get; set; }
public object template_suffix { get; set; }
public string status { get; set; }
public string published_scope { get; set; }
public string tags { get; set; }
public string admin_graphql_api_id { get; set; }
public List<Models.Producto.Variant> variants { get; set; }
public List<Models.Producto.Option> options { get; set; }
public List<Models.Producto.Images> images { get; set; }
public Models.Producto.Image image { get; set; }
}
I can see that you are using a wrong class to deserialize json, should be
var data=JsonConvert.DeserializeObject<Data>(json);
main classes (I highly recommend you to use a Pascal style for property names)
public partial class Data
{
[JsonProperty("product")]
public Product Product { get; set; }
}
public partial class Product
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("body_html")]
public string BodyHtml { get; set; }
[JsonProperty("vendor")]
public string Vendor { get; set; }
[JsonProperty("product_type")]
public string ProductType { get; set; }
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty("handle")]
public string Handle { get; set; }
[JsonProperty("updated_at")]
public DateTimeOffset UpdatedAt { get; set; }
[JsonProperty("published_at")]
public DateTimeOffset PublishedAt { get; set; }
[JsonProperty("template_suffix")]
public object TemplateSuffix { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("published_scope")]
public string PublishedScope { get; set; }
[JsonProperty("tags")]
public string Tags { get; set; }
[JsonProperty("admin_graphql_api_id")]
public string AdminGraphqlApiId { get; set; }
[JsonProperty("variants")]
public List<Variant> Variants { get; set; }
[JsonProperty("options")]
public List<Option> Options { get; set; }
[JsonProperty("images")]
public List<Image> Images { get; set; }
[JsonProperty("image")]
public Image Image { get; set; }
}
other classes
public partial class Image
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("product_id")]
public long ProductId { get; set; }
[JsonProperty("position")]
public long Position { get; set; }
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty("updated_at")]
public DateTimeOffset UpdatedAt { get; set; }
[JsonProperty("alt")]
public object Alt { get; set; }
[JsonProperty("width")]
public long Width { get; set; }
[JsonProperty("height")]
public long Height { get; set; }
[JsonProperty("src")]
public Uri Src { get; set; }
[JsonProperty("variant_ids")]
public List<object> VariantIds { get; set; }
[JsonProperty("admin_graphql_api_id")]
public string AdminGraphqlApiId { get; set; }
}
public partial class Option
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("product_id")]
public long ProductId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("position")]
public long Position { get; set; }
[JsonProperty("values")]
public List<string> Values { get; set; }
}
public partial class Variant
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("product_id")]
public long ProductId { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("price")]
public string Price { get; set; }
[JsonProperty("sku")]
public string Sku { get; set; }
[JsonProperty("position")]
public long Position { get; set; }
[JsonProperty("inventory_policy")]
public string InventoryPolicy { get; set; }
[JsonProperty("compare_at_price")]
public object CompareAtPrice { get; set; }
[JsonProperty("fulfillment_service")]
public string FulfillmentService { get; set; }
[JsonProperty("inventory_management")]
public string InventoryManagement { get; set; }
[JsonProperty("option1")]
public string Option1 { get; set; }
[JsonProperty("option2")]
public object Option2 { get; set; }
[JsonProperty("option3")]
public object Option3 { get; set; }
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty("updated_at")]
public DateTimeOffset UpdatedAt { get; set; }
[JsonProperty("taxable")]
public bool Taxable { get; set; }
[JsonProperty("barcode")]
public object Barcode { get; set; }
[JsonProperty("grams")]
public long Grams { get; set; }
[JsonProperty("image_id")]
public object ImageId { get; set; }
[JsonProperty("weight")]
public long Weight { get; set; }
[JsonProperty("weight_unit")]
public string WeightUnit { get; set; }
[JsonProperty("inventory_item_id")]
public long InventoryItemId { get; set; }
[JsonProperty("inventory_quantity")]
public long InventoryQuantity { get; set; }
[JsonProperty("old_inventory_quantity")]
public long OldInventoryQuantity { get; set; }
[JsonProperty("requires_shipping")]
public bool RequiresShipping { get; set; }
[JsonProperty("admin_graphql_api_id")]
public string AdminGraphqlApiId { get; set; }
}
try this:
var response = JsonConvert.DeserializeObject<Dictionary<<string, string>>(deserialize);
string value = response["key"];
I'm not able to get the value from OneDay.price_change. The HTTP response is OK and I'm getting the following:
HTTP Response
"[{\"id\":\"BTC\",\"currency\":\"BTC\",\"symbol\":\"BTC\",\"name\":\"Bitcoin\",\"logo_url\":\"https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/btc.svg\",\"status\":\"active\",\"price\":\"60947.08258854\",\"price_date\":\"2021-10-31T00:00:00Z\",\"price_timestamp\":\"2021-10-31T18:51:00Z\",\"circulating_supply\":\"18860037\",\"max_supply\":\"21000000\",\"market_cap\":\"1149464232662\",\"market_cap_dominance\":\"0.4078\",\"num_exchanges\":\"397\",\"num_pairs\":\"67587\",\"num_pairs_unmapped\":\"5196\",\"first_candle\":\"2011-08-18T00:00:00Z\",\"first_trade\":\"2011-08-18T00:00:00Z\",\"first_order_book\":\"2017-01-06T00:00:00Z\",\"rank\":\"1\",\"high\":\"66082.82561618\",\"high_timestamp\":\"2021-10-20T00:00:00Z\",\"1h\":{\"volume\":\"1248590564.91\",\"price_change\":\"-85.32656234\",\"price_change_pct\":\"-0.0014\",\"volume_change\":\"-218879322.04\",\"volume_change_pct\":\"-0.1492\",\"market_cap_change\":\"-1607003923.65\",\"market_cap_change_pct\":\"-0.0014\"},\"1d\":{\"volume\":\"39937857069.60\",\"price_change\":\"-845.68642611\",\"price_change_pct\":\"-0.0137\",\"volume_change\":\"1918883279.43\",\"volume_change_pct\":\"0.0505\",\"market_cap_change\":\"-15892518975.54\",\"market_cap_change_pct\":\"-0.0136\"}}]\n"
However, for some reason, I'm not able to take the 1d price change. I'm not sure what could be the problem. Any help is appreciated!
Model:
public class OneHour
{
public string Volume { get; set; }
public string Price_change { get; set; }
public string Price_change_pct { get; set; }
public string Volume_change { get; set; }
public string Volume_change_pct { get; set; }
public string Market_cap_change { get; set; }
public string Market_cap_change_pct { get; set; }
}
public class OneDay
{
public string Volume { get; set; }
public string Price_change { get; set; }
public string Price_change_pct { get; set; }
public string Volume_change { get; set; }
public string Volume_change_pct { get; set; }
public string Market_cap_change { get; set; }
public string Market_cap_change_pct { get; set; }
}
public class CryptoApiMain
{
public OneHour OneHour { get; set; }
public OneDay OneDay { get; set; }
public string Id { get; set; }
public string Symbol { get; set; }
public string Status { get; set; }
public double Price { get; set; }
public string Price_date { get; set; }
public string Circulating_supply { get; set; }
public string Num_exchanges { get; set; }
public string Num_pairs { get; set; }
public string Rank { get; set; }
public string High { get; set; }
}
var theresponse = settingsService.CryptoApiResult(cryptoStock).Result;
foreach (var rez in theresponse)
{
<span id="stockSymbolCrypto">#cryptoStock</span>
<p>$#Convert.ToInt64(#rez.Price) #rez.OneDay.Price_change</p>
}
#rez.OneDay.Price_change error popup
Problem is that your property name in json (1d) and property name in c# model (OneDay) is not matching.
Use the below if you are using System.Text.Json (.Net Core 3.0 and newer)
[JsonPropertyName("1d")]
public OneDay OneDay { get; set; }
Use the below if you are using Newtonsoft (Before .Net Core 3.0)
[JsonProperty(PropertyName = "1d")]
public OneDay OneDay { get; set; }
Your " public OneHour OneHour { get; set; } " and " public OneDay OneDay { get; set; } " properties should be bind to [JsonProperty("1h")] and [JsonProperty("1d")]
try this
CryptoApiMain[] jsond = JsonConvert.DeserializeObject<CryptoApiMain[]>(json);
var price = jsond[0].OneDay.PriceChange;
result
-845.68642611
classes
public partial class CryptoApiMain
{
[JsonProperty("1h")]
public One OneHour { get; set; }
[JsonProperty("1d")]
public One OneDay { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
[JsonProperty("symbol")]
public string Symbol { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("logo_url")]
public Uri LogoUrl { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("price")]
public string Price { get; set; }
[JsonProperty("price_date")]
public DateTimeOffset PriceDate { get; set; }
[JsonProperty("price_timestamp")]
public DateTimeOffset PriceTimestamp { get; set; }
[JsonProperty("circulating_supply")]
public long CirculatingSupply { get; set; }
[JsonProperty("max_supply")]
public long MaxSupply { get; set; }
[JsonProperty("market_cap")]
public string MarketCap { get; set; }
[JsonProperty("market_cap_dominance")]
public string MarketCapDominance { get; set; }
[JsonProperty("num_exchanges")]
public long NumExchanges { get; set; }
[JsonProperty("num_pairs")]
public long NumPairs { get; set; }
[JsonProperty("num_pairs_unmapped")]
public long NumPairsUnmapped { get; set; }
[JsonProperty("first_candle")]
public DateTimeOffset FirstCandle { get; set; }
[JsonProperty("first_trade")]
public DateTimeOffset FirstTrade { get; set; }
[JsonProperty("first_order_book")]
public DateTimeOffset FirstOrderBook { get; set; }
[JsonProperty("rank")]
public long Rank { get; set; }
[JsonProperty("high")]
public string High { get; set; }
[JsonProperty("high_timestamp")]
public DateTimeOffset HighTimestamp { get; set; }
}
public partial class One
{
[JsonProperty("volume")]
public string Volume { get; set; }
[JsonProperty("price_change")]
public string PriceChange { get; set; }
[JsonProperty("price_change_pct")]
public string PriceChangePct { get; set; }
[JsonProperty("volume_change")]
public string VolumeChange { get; set; }
[JsonProperty("volume_change_pct")]
public string VolumeChangePct { get; set; }
[JsonProperty("market_cap_change")]
public string MarketCapChange { get; set; }
[JsonProperty("market_cap_change_pct")]
public string MarketCapChangePct { get; set; }
}