async Task LoadUserOrderWithStatus(string value) { LoadingManager.OnLoading(); Status _statusvalue = (Status)Enum.Parse(typeof(Status), value); var orderData = await orderDataStore.GetOrdersOfUserWithSpecificStatus(App.LogUser.UserId, _statusvalue, App.TokenDto.Token); if (!KeyValues.ContainsKey("orderAdded")) { KeyValues.Add("orderAdded", orderData); } switch (_statusvalue) { case Status.Completed: { List <Order> tempData = new List <Order>(); var data = await orderDataStore.GetOrdersOfUserWithSpecificStatusDifferent(KeyValues["orderAdded"], _statusvalue, App.LogUser.UserId); if (data != null) { foreach (var item in KeyValues["orderAdded"]) { if (!tempData.Any(o => o.OrderId == item.OrderId)) { tempData.Add(item); } } foreach (var item in data) { if (!tempData.Any(s => s.StoreId == item.StoreId)) { tempData.Add(item); } } KeyValues.Clear(); KeyValues.Add("orderAdded", tempData); foreach (var item in KeyValues["orderAdded"]) { if (!UserOrders.Any(s => s.OrderId == item.OrderId)) { //Task.Run(async() => //{ // item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); //}).Wait(); item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); var presenter = new OrderPresenter(item); UserOrders.Add(presenter); } } } break; } case Status.NotSubmited: { List <Order> tempData = new List <Order>(); var data = await orderDataStore.GetOrdersOfUserWithSpecificStatusDifferent(KeyValues["orderAdded"], _statusvalue, App.LogUser.UserId); if (data != null) { foreach (var item in KeyValues["orderAdded"]) { if (!tempData.Any(o => o.OrderId == item.OrderId)) { tempData.Add(item); } } foreach (var item in data) { if (!tempData.Any(s => s.StoreId == item.StoreId)) { tempData.Add(item); } } KeyValues.Clear(); KeyValues.Add("orderAdded", tempData); foreach (var item in KeyValues["orderAdded"]) { if (!UserOrders.Any(s => s.OrderId == item.OrderId)) { item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); var presenter = new OrderPresenter(item); UserOrders.Add(presenter); } } } break; //UserOrders.Clear(); //foreach (var item in orderData) //{ // item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); // var presenter = new OrderPresenter(item); // UserOrders.Add(presenter); //} } case Status.Submited: { List <Order> tempData = new List <Order>(); var data = await orderDataStore.GetOrdersOfUserWithSpecificStatusDifferent(KeyValues["orderAdded"], _statusvalue, App.LogUser.UserId); if (data != null) { foreach (var item in KeyValues["orderAdded"]) { if (!tempData.Any(o => o.OrderId == item.OrderId)) { tempData.Add(item); } } foreach (var item in data) { if (!tempData.Any(s => s.StoreId == item.StoreId)) { tempData.Add(item); } } KeyValues.Clear(); KeyValues.Add("orderAdded", tempData); foreach (var item in KeyValues["orderAdded"]) { if (!UserOrders.Any(s => s.OrderId == item.OrderId)) { item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); var presenter = new OrderPresenter(item); UserOrders.Add(presenter); } } } //UserOrders.Clear(); //foreach (var item in orderData) //{ // item.StoreOrder = await StoreDataStore.GetItemAsync(item.StoreId.ToString()); // var presenter = new OrderPresenter(item); // UserOrders.Add(presenter); //} break; } default: break; } LoadingManager.OffLoading(); }