public async Task <string> SaveOrder(DNSalesOrder salesOrder) { var url = string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/sales_orders/"); string jsonPayload = JsonConvert.SerializeObject(salesOrder); var httpResponse = await DNAPIHandler.Current.PostResponseAsync(url, jsonPayload); var so = DNAPIHandler.Current.ReadResponse <DNSalesOrder>(httpResponse); return(so.OrderNumber); }
public override async Task <bool> LoadAsync() { try { this.IsBusy = true; await Task.Delay(100); this.SelectedOrder = null; string url = string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/sales_orders/Headers/"); if (this.Orders.Count > 0) { string tempLastrefreshDatetime = LastRefreshTime.ToString("yyyy-MM-dd HH:mm"); tempLastrefreshDatetime = tempLastrefreshDatetime.Replace(".", ":"); url = string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/sales_orders/Headers/?lastchangedate={0}", tempLastrefreshDatetime); } else { url = string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/sales_orders/Headers/"); } var httpWebRequest = await DNAPIHandler.Current.GetWebRequestAsync("GET", url); var httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync(); if (httpResponse.StatusCode == HttpStatusCode.OK) { using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var OrderResponses = JsonConvert.DeserializeObject(streamReader.ReadToEnd()) as Newtonsoft.Json.Linq.JArray; if (OrderResponses != null) { foreach (var order in OrderResponses) { DNSalesOrder ObjOrder = new DNSalesOrder(); foreach (JProperty property in order.Values <JToken>()) { switch (property.Name) { case "order_number": ObjOrder.OrderNumber = property.Value.ToString(); break; case "customer_number": ObjOrder.CustomerNumber = property.Value.ToLong(); break; case "customer_name": ObjOrder.CustomerName = property.Value.ToString(); break; case "shop_number": ObjOrder.ShopNumber = property.Value.ToInt(); break; case "name": ObjOrder.ShopName = property.Value.ToSafeString(); break; case "date": ObjOrder.OrderDate = property.Value.ToLong().ToLocalDateTime(); break; case "total_Order_amount": ObjOrder.TotalAmount = property.Value.ToDouble(); break; case "total_order_qty": ObjOrder.TotalOrderedQuantity = property.Value.ToDouble(); break; case "total_delivery_qty": ObjOrder.TotalDeliveredQuantity = property.Value.ToDouble(); break; case "order_statuscode": ObjOrder.Status = property.Value.ToSafeString(); break; case "total_lines": ObjOrder.TotalOrderedLines = property.Value.ToInt(); break; case "total_delivered_lines": ObjOrder.TotalOrderedeliveredLines = property.Value.ToInt(); break; } } var tempexistingorder = this.Orders.Where(c => c.OrderNumber == ObjOrder.OrderNumber).SingleOrDefault(); if (tempexistingorder != null) { if (ObjOrder.Status.ToLower() == "sold") { this.Orders.Remove(tempexistingorder); } else { tempexistingorder.CustomerNumber = ObjOrder.CustomerNumber; tempexistingorder.CustomerName = ObjOrder.CustomerName; tempexistingorder.ShopNumber = ObjOrder.ShopNumber; tempexistingorder.ShopName = ObjOrder.ShopName; tempexistingorder.OrderDate = ObjOrder.OrderDate; tempexistingorder.TotalAmount = ObjOrder.TotalAmount; tempexistingorder.TotalOrderedQuantity = ObjOrder.TotalOrderedQuantity; tempexistingorder.TotalDeliveredQuantity = ObjOrder.TotalDeliveredQuantity; tempexistingorder.Status = ObjOrder.Status; tempexistingorder.TotalOrderedLines = ObjOrder.TotalOrderedLines; tempexistingorder.TotalOrderedeliveredLines = ObjOrder.TotalOrderedeliveredLines; } } else { if (ObjOrder.Status.ToLower() != "sold") { this.Orders.Add(ObjOrder); } } } } } } } catch (Exception ex) { } finally { IsBusy = false; LastRefreshTime = System.DateTime.Now; } return(await base.LoadAsync()); }