コード例 #1
0
        public IActionResult GetShoppingList(int userId)
        {
            var tempShopList = _context.ShoppingLists.FirstOrDefault(s => s.UserId == userId);

            if (tempShopList == null)
            {
                return(NotFound());
            }
            var shoppingListId = tempShopList.Id;
            var tmpItemList    = from itemListPtr in _context.Items
                                 where itemListPtr.ShoppingListId == shoppingListId
                                 select itemListPtr;
            var tempItemList = tmpItemList.ToList();

            List <ItemVM> itemList = new List <ItemVM>();

            foreach (Item item in tempItemList)
            {
                var tempItem = new ItemVM();
                tempItem.ItemName = item.ItemName;
                tempItem.ItemQty  = item.ItemQty;
                tempItem.ItemUnit = item.ItemUnit;
                itemList.Add(tempItem);
            }

            var shoppingList = new ShoppingListVM();

            shoppingList.ListName       = tempShopList.ListName;
            shoppingList.ShoppingListId = tempShopList.Id;
            shoppingList.UserId         = tempShopList.UserId;
            shoppingList.Items          = itemList;

            return(new ObjectResult(shoppingList));
        }
コード例 #2
0
        public ShoppingListPage()
        {
            InitializeComponent();
            // Stops the ListView from going into the Status Bar:
            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
            var assembly = typeof(ShoppingListPage);

            viewModel      = new ShoppingListVM();
            BindingContext = viewModel;

            // Messaging Centre Subscriptions:
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.POPUP_PAGE_FINISHED, async(sender) =>
            {
                var items = await viewModel.refresh(Preferences.Get(Constants.SORT_BY, Constants.SORT_BY_DEFAULT));
                //itemListView.ItemsSource = items;
            });
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.SORT_BY_DEFAULT_SELECTED, async(sender) =>
            {
                Preferences.Set(Constants.SORT_BY, Constants.SORT_BY_DEFAULT);
                var items = await viewModel.refresh(Preferences.Get(Constants.SORT_BY, Constants.SORT_BY_DEFAULT));
                //itemListView.ItemsSource = items;
            });
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.SORT_BY_NAME_SELECTED, async(sender) =>
            {
                Preferences.Set(Constants.SORT_BY, Constants.SORT_BY_NAME);
                var items = await viewModel.refresh(Preferences.Get(Constants.SORT_BY, Constants.SORT_BY_DEFAULT));
                //itemListView.ItemsSource = items;
            });

            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.REFRESH_SHOPPING_LIST, async(sender) =>
            {
                var items = await viewModel.refresh(Preferences.Get(Constants.SORT_BY, Constants.SORT_BY_DEFAULT));
                //itemListView.ItemsSource = items;
            });

            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.SELECT_MODE_TOGGLED, (sender) =>
            {
                // TO-DO:
                //ItemSelectTick
            });

            MessagingCenter.Subscribe <ItemDetailVM, Item>(this, Constants.ITEM_DELETED, (sender, deletedItem) => {
                Navigation.PushPopupAsync(new ShoppingListPageUndoPopup(deletedItem));
            });

            // No items in cart, displaying empty view:
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.DISPLAY_EMPTY_VIEW, (sender) =>
            {
                emptyViewRefreshView.IsVisible    = true;
                itemListView.IsVisible            = false;
                noInternetRefreshView.IsVisible   = false;
                emptyViewRefreshView.IsRefreshing = false;
                itemListView.IsRefreshing         = false;
            });

            // Display Network Error:
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.DISPLAY_NETWORK_ERROR, (sender) =>
            {
                emptyViewRefreshView.IsVisible  = false;
                itemListView.IsVisible          = false;
                noInternetRefreshView.IsVisible = true;
                CrossToastPopUp.Current.ShowToastError(Strings.UNABLE_TO_CONNECT);
                noInternetRefreshView.IsRefreshing = false;
                itemListView.IsRefreshing          = false;
            });

            MessagingCenter.Subscribe <App, SelectableObservableCollection <Item> >((App)Application.Current, Constants.LISTVIEW_REFRESH_COMPLETE, (sender, Items) =>
            {
                itemListView.IsVisible             = true;
                noInternetRefreshView.IsVisible    = false;
                noInternetRefreshView.IsRefreshing = false;
                emptyViewRefreshView.IsVisible     = false;
                itemListView.IsRefreshing          = false;
                itemListView.ItemsSource           = Items;
            });
        }
コード例 #3
0
 public NavigationCommand(ShoppingListVM shoppingListVM, int mode)
 {
     ShoppingListVM = shoppingListVM;
     Mode           = mode;
 }
コード例 #4
0
 public NavigationCommand(ShoppingListVM shoppingListVM)
 {
     ShoppingListVM = shoppingListVM;
 }
コード例 #5
0
 public RefreshCommand(ShoppingListVM viewModel)
 {
     ViewModel = viewModel;
 }