public static ExpressTrackingViewModel ConvertFromFedEx(FedExTrackingViewModel fedExModel, GetExpressTrackResponse_V01 expressInfoResponse) { ExpressTrackingViewModel expressTrack = new ExpressTrackingViewModel(); List <steps> expressTrackSteps = new List <steps>(); TrackingStatus status = TrackingStatus.PreparingShipment; expressTrack.mailno = fedExModel.tracking.detail.tn; expressTrack.remark = expressInfoResponse.ExpressCompanyName; expressTrack.result = "false"; if (fedExModel.tracking.detail.activities.Count >= 1) { expressTrack.result = "true"; status = TrackingStatus.InTransit; } if (fedExModel.tracking.detail.status == "已取件") { //Shipped status = TrackingStatus.Shipped; expressTrack.time = fedExModel.tracking.detail.shipdate; } else if (fedExModel.tracking.detail.status == "已送达") { status = TrackingStatus.Delivered; expressTrack.time = fedExModel.tracking.detail.deliverydate; } else { status = TrackingStatus.InTransit; expressTrack.time = fedExModel.tracking.detail.deliverydate; } if (fedExModel.tracking.detail.activities != null && fedExModel.tracking.detail.activities.Count >= 1) { foreach (var trace in fedExModel.tracking.detail.activities) { var eachstep = new steps { time = trace.datetime, address = trace.scan, station = trace.location, station_phone = string.Empty, status = string.Empty, remark = trace.details, next = string.Empty, next_name = string.Empty }; expressTrackSteps.Add(eachstep); } } expressTrack.status = getNumberValue(status).ToString(); expressTrack.steps = expressTrackSteps; return(expressTrack); }
public static FedExTrackingViewModel ConvertFedExTracking(string fedExTracking) { FedExTrackingViewModel model = new FedExTrackingViewModel(); List <activity> activities = new List <activity>(); detail det = new detail(); tracking tracking = new tracking(); if (fedExTracking.Length > 50) { JObject request = JObject.Parse(File.ReadAllText(fedExTracking)); request.Remove("?xml"); var activityTokens = request["tracking"]["detail"]["activities"].Children(); var detailTokens = request["tracking"]["detail"].Children(); foreach (JToken child in activityTokens.Children()) { foreach (JToken grandChild in child) { activity act = new activity(); foreach (JToken grandGrandChild in grandChild) { var property = grandGrandChild as JProperty; if (property != null) { if (property.Name == "datetime") { act.datetime = property.Value != null?property.Value.ToString() : ""; } if (property.Name == "scan") { act.scan = property.Value != null?property.Value.ToString() : ""; } if (property.Name == "location") { act.location = property.Value != null?property.Value.ToString() : ""; } if (property.Name == "details") { act.details = property.Value != null?property.Value.ToString() : ""; } } } activities.Add(act); } } foreach (JToken child in detailTokens) { var property = child as JProperty; if (property != null) { if (property.Name == "tn") { det.tn = property.Value.ToString(); } if (property.Name == "ptn") { det.ptn = property.Value != null?property.Value.ToString() : ""; } if (property.Name == "destination") { if (property.Value != null) { det.destination = property.Value.ToString(); } } if (property.Name == "shipdate") { if (property.Value != null) { det.shipdate = property.Value.ToString(); } } if (property.Name == "sentby") { if (property.Value != null) { det.sentby = property.Value.ToString(); } } if (property.Name == "deliveredto") { if (property.Value != null) { det.deliveredto = property.Value.ToString(); } } if (property.Name == "signedforby") { if (property.Value != null) { det.signedforby = property.Value.ToString(); } } if (property.Name == "service") { if (property.Value != null) { det.service = property.Value.ToString(); } } if (property.Name == "deliverydate") { if (property.Value != null) { det.deliverydate = property.Value.ToString(); } } if (property.Name == "status") { if (property.Value != null) { det.status = property.Value.ToString(); } } } } } det.activities = activities; tracking.detail = det; model.tracking = tracking; return(model); }