Exemple #1
0
        private async Task CreateInventory()
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
            {
                // create new inventory and insert in db
                var       ingredient = (newInventoryPicker.SelectedItem as Ingredient);
                Inventory inventory  = new Inventory
                {
                    Id             = Guid.NewGuid().ToString(),
                    CartId         = CartConstants.CartId,
                    IngredientId   = ingredient.Id,
                    IngredientName = ingredient.Name,
                    MaxStock       = ingredient.Stock,
                    Stock          = ingredient.Stock,
                    Threshold      = ingredient.Threshold,
                    Resupplying    = false
                };
                await _client.GetTable <Inventory>().InsertAsync(inventory);

                _inventories.Add(inventory);
                _inventories = new ObservableCollection <Inventory>(_inventories.OrderBy(x => x.IngredientName));
                inventoryListView.ItemsSource = _inventories;

                // check if there are any missing ingredients left
                _missingIngredients.Remove(ingredient);
                if (_missingIngredients.Count == 0)
                {
                    newInventoryPicker.IsVisible    = false;
                    createInventoryButton.IsVisible = false;
                    return;
                }
                newInventoryPicker.ItemsSource   = _missingIngredients;
                newInventoryPicker.SelectedIndex = 0;
            }
        }
 private async void OnUpdateClicked(object sender, EventArgs e)
 {
     using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
     {
         await GetOrders();
     }
 }
Exemple #3
0
 private async void OnUpdateClicked(object sender, EventArgs e)
 {
     using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
     {
         CartConstants.OfflineCarts = await _client.GetTable <Cart>().OrderBy(x => x.Identifier).ToCollectionAsync();
     }
     cartPicker.ItemsSource = CartConstants.OfflineCarts;
 }
Exemple #4
0
        private async Task RefreshItems(bool showActivityIndicator)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator, layoutToEnable))
            {
                CartConstants.OfflineIngredients = await _client.GetTable <Ingredient>().ToCollectionAsync();

                CartConstants.OfflineCarts = await _client.GetTable <Cart>().OrderBy(x => x.Identifier).ToCollectionAsync();
            }
        }
        private async void OnOrderSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var response = await DisplayAlert("Finish Order", "Order fulfilled?", "Yes", "No");

            if (response)
            {
                using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
                {
                    await OrderProcess(e.SelectedItem as Order);

                    await GetOrders();
                }
            }
        }
Exemple #6
0
        private async Task CreateCart(string identifier)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
            {
                // create new cart while using current location as default
                Location location = await Geolocation.GetLocationAsync();

                var placemark = await Geocoding.GetPlacemarksAsync(location);

                var  position = placemark.FirstOrDefault().Thoroughfare;
                Cart cart     = new Cart
                {
                    Id         = Guid.NewGuid().ToString(),
                    Identifier = identifier,
                    Longitude  = location.Longitude,
                    Latitude   = location.Latitude,
                    Position   = position
                };
                await _client.GetTable <Cart>().InsertAsync(cart);

                cartListView.ItemsSource = await _client.GetTable <Cart>().OrderBy(x => x.Identifier).ToCollectionAsync();

                // creating fully stocked inventory and insert to db
                var ingredientList = await _client.GetTable <Ingredient>().ToListAsync();

                foreach (Ingredient ingredient in ingredientList)
                {
                    Inventory inventory = new Inventory
                    {
                        Id             = Guid.NewGuid().ToString(),
                        CartId         = cart.Id,
                        IngredientId   = ingredient.Id,
                        IngredientName = ingredient.Name,
                        MaxStock       = ingredient.Stock,
                        Stock          = ingredient.Stock,
                        Threshold      = ingredient.Threshold,
                        Resupplying    = false
                    };
                    await _client.GetTable <Inventory>().InsertAsync(inventory);
                }
                CartConstants.OfflineCarts = await _client.GetTable <Cart>().ToCollectionAsync();
                await DisplayAlert("Success", "New cart " + cart.Identifier + " successfully created", "Ok");
            }
        }
Exemple #7
0
        private async void OnInventorySelected(object sender, SelectedItemChangedEventArgs e)
        {
            // resupply an inventory with delivered ingredients
            var inventory = e.SelectedItem as Inventory;
            var response  = await DisplayAlert(inventory.IngredientName, "Resupply " + inventory.IngredientName + "?", "Yes", "Cancel");

            if (response)
            {
                inventory.Stock       = inventory.MaxStock;
                inventory.Resupplying = false;
                using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
                {
                    await _client.GetTable <Inventory>().UpdateAsync(inventory);

                    _inventories = await _client.GetTable <Inventory>().Where(x => x.CartId == CartConstants.CartId).ToCollectionAsync();

                    inventoryListView.ItemsSource = _inventories;
                }
            }
        }
Exemple #8
0
        private async void OnUpdateLocationClicked(object sender, EventArgs e)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, true, layoutToEnable))
            {
                var cartList = await _client.GetTable <Cart>().Where(x => x.Id == CartConstants.CartId).ToListAsync();

                Cart     cart     = cartList[0];
                Location location = await Geolocation.GetLocationAsync();

                var placemark = await Geocoding.GetPlacemarksAsync(location);

                var position = placemark.FirstOrDefault().Thoroughfare;
                cart.Longitude = location.Longitude;
                cart.Latitude  = location.Latitude;
                cart.Position  = position;

                await _client.GetTable <Cart>().UpdateAsync(cart);

                var index = CartConstants.OfflineCarts.IndexOf(CartConstants.OfflineCarts.FirstOrDefault(x => x.Id == cart.Id));
                CartConstants.OfflineCarts[index].Latitude  = cart.Latitude;
                CartConstants.OfflineCarts[index].Longitude = cart.Longitude;
                CartConstants.OfflineCarts[index].Position  = cart.Position;
            }
        }