Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        /// <param name="inventoryModel"></param>
        public MainViewModel(IInventoryModel inventoryModel)
        {
            this.inventoryModel = inventoryModel;
            this.FindProductsCommand = new RelayCommand(() => this.FindProducts(), () => !this.IsBusy);
            if (IsInDesignMode)
            {
            #if DEBUG
                this.Products = new ObservableCollection<ProductViewModel>() {
                    new ProductViewModel() { Id = 123, Name = "Domaine De La Seigneurie Des Tourelles Saumur 2008 750 mL bottle" },
                    new ProductViewModel() { Id = 124, Name = "Product 124" }
                };

                StoreViewModel newStoreModel1 = new StoreViewModel() { Id = 123 };
                newStoreModel1.SetAddress("Address 123", "City 123");
                StoreViewModel newStoreModel2 = new StoreViewModel() { Id = 124 };
                newStoreModel2.SetAddress("Address 124", "City 124");
                this.Stores = new ObservableCollection<StoreViewModel>() {
                    newStoreModel1,
                    newStoreModel2
                };

                this.CurrentStore = this.Stores[0];

                this.CurrentProduct = this.Products[0];

                ObservableCollection<InventoryInfo> invInfo = new ObservableCollection<InventoryInfo>();
                invInfo.Add(new InventoryInfo() { NumberInStock = 33, Product = new ProductListItem() { Id = 33, Name = "Domaine De La Seigneurie Des Tourelles Saumur 2008 750 mL bottle" } });
                invInfo.Add(new InventoryInfo() { NumberInStock = 5600, Product = new ProductListItem() { Id = 56, Name = "Canadian" } });

                List<StoreWithInventory> sWithInv = new List<StoreWithInventory>();
                sWithInv.Add(new StoreWithInventory()
                {
                    Inventory = invInfo,
                    Store = new InvStore()
                    {
                        City = "City 123",
                        Address = "Address 123",
                        StoreNumber = 123,
                        Latitude = 43.474249M,
                        Longitude = -79.732728M
                    }
                });
                sWithInv.Add(new StoreWithInventory()
                {
                    Inventory = invInfo,
                    Store = new InvStore()
                    {
                        City = "City 124",
                        Address = "Address 124",
                        StoreNumber = 124,
                        Latitude = 43.574249M,
                        Longitude = -79.632728M
                    }
                });

                this.StoresWithInventories = new ObservableCollection<StoreWithInventoryViewModel>();
                foreach (StoreWithInventory storeWithInventory in sWithInv)
                {
                    this.StoresWithInventories.Add(new StoreWithInventoryViewModel(storeWithInventory));
                }
            #endif
            }
            else
            {
                this.Refresh();
            }
        }
Beispiel #2
0
        private void Refresh()
        {
            inventoryModel.GetProductsForUserAsync((products, error) =>
            {
                if (error != null)
                {
                    // Display error, normally this would be done through a property
                    MessageBox.Show(error.Message);
                    return;
                }

                List<ProductViewModel> productsForUI = products.ToList();
                productsForUI.Insert(0, new ProductViewModel() { Id = ProductConstants.UsersProductsId, Name = "Your products" });
                this.Products = new ObservableCollection<ProductViewModel>(productsForUI);
                this.CurrentProduct = this.Products[0];
                lock (this.isBusyLock)
                {
                    this.productsLoaded = true;
                    if (this.storesLoaded)
                    {
                        this.IsBusy = false;
                        this.FindProductsCommand.RaiseCanExecuteChanged();
                    }
                }
            });

            inventoryModel.GetStoresForUserAsync((stores, error) =>
            {
                if (error != null)
                {
                    // Display error, normally this would be done through a property
                    MessageBox.Show(error.Message);
                    return;
                }

                List<StoreViewModel> storesForUI = stores.ToList();
                StoreViewModel newStoreViewModel1 = new StoreViewModel() { Id = StoreConstants.UsersStoresId };
                newStoreViewModel1.SetAddress("Your stores", null);
                StoreViewModel newStoreViewModel2 = new StoreViewModel() { Id = StoreConstants.AllStoresId };
                newStoreViewModel2.SetAddress("All stores", null);
                storesForUI.Insert(0, newStoreViewModel1);
                storesForUI.Insert(1, newStoreViewModel2);
                this.Stores = new ObservableCollection<StoreViewModel>(storesForUI);
                this.CurrentStore = this.Stores[0];
                lock (this.isBusyLock)
                {
                    this.storesLoaded = true;
                    if (this.productsLoaded)
                    {
                        this.IsBusy = false;
                        this.FindProductsCommand.RaiseCanExecuteChanged();
                    }
                }
            });
        }
 public InventoryRequestHelper(StoreViewModel storeViewModel, ProductViewModel productViewModel)
 {
     // TODO: Complete member initialization
     this.storeViewModel = storeViewModel;
     this.productViewModel = productViewModel;
 }
 /// <summary>
 /// Initializes a new instance of the UserStoreViewModel class.
 /// </summary>
 public UserStoreViewModel(StoreViewModel store)
 {
     this.Store = store;
 }
        /// <summary>
        /// Initializes a new instance of the ManageStoresViewModel class.
        /// </summary>
        /// <param name="storeModel"></param>
        public ManageStoresViewModel(IStoreModel storeModel)
        {
            this.storeModel = storeModel;

            #if DEBUG
            if (IsInDesignMode)
            {
                //this.UserStores = new ObservableCollection<StoreViewModel>() {
                //    new StoreViewModel(new Store() { ID = 123, City = "Toronto", StreetAddress = "123 Fake St.", Latitude = 43.0M, Longitude = -79.0M }),
                //    new StoreViewModel(new Store() { ID = 124, City = "Oakville", StreetAddress = "2280 River Oaks", Latitude = 43.5M, Longitude = -79.1M })
                //};

                //for (int i = 0; i < 20; i++)
                //{
                //    this.UserStores.Add(new StoreViewModel(new Store() { ID = i, City = "Toronto", StreetAddress = i + " Some Street", Latitude = 43M + i / 10, Longitude = -79M - i / 10 }));
                //}

                StoreViewModel newStoreViewModel1 = new StoreViewModel()
                {
                    Id = 123,
                    Latitude = 43.0M,
                    Longitude = -79.0M
                };

                newStoreViewModel1.SetAddress("123 Fake St.", "Toronto");

                StoreViewModel newStoreViewModel2 = new StoreViewModel()
                {
                    Id = 124,
                    Latitude = 43.5M,
                    Longitude = -79.1M
                };

                newStoreViewModel2.SetAddress("2280 River Oaks", "Oakville");

                this.SearchResults = new ObservableCollection<UserStoreViewModel>()
                {
                    new UserStoreViewModel(newStoreViewModel1)
                    {
                        UsedByUser = true,
                        Index = 1
                    },

                    new UserStoreViewModel(newStoreViewModel2)
                    {
                        UsedByUser = true,
                        Index = 2
                    }
                };

                for (int i = 0; i < 20; i++)
                {
                    StoreViewModel newStoreViewModel = new StoreViewModel()
                    {
                        Id = i,
                        Latitude = 43.0M + i / 10,
                        Longitude = -79.0M - i / 10
                    };

                    newStoreViewModel.SetAddress(i + " Fake St.", "City " + i);
                    this.SearchResults.Add(new UserStoreViewModel(newStoreViewModel)
                    {
                        UsedByUser = i % 2 == 0,
                        Index = i + 3
                    });
                }
            }
            #endif

            this.AddStoreCommand = new RelayCommand<UserStoreViewModel>((store) => this.AddStore(store));
            this.RemoveStoreCommand = new RelayCommand<StoreViewModel>((store) => this.RemoveStore(store));
            this.FindStoresCommand = new RelayCommand<string>((cityName) => this.FindStores(cityName));
            this.FindStoresByPostalCodeCommand = new RelayCommand(() => this.FindStoresByPostalCode());
            this.FindStoresByPersonalLocationCommand = new RelayCommand<PersonalLocationViewModel>((personalLocation) => this.FindStoresByPersonalLocation(personalLocation));
            this.SearchRadiusItems = new List<int>() { 5, 10, 15, 20, 2000 };
            this.SearchPersonalLocationRadius = this.SearchRadiusItems[0];
            this.SearchRadius = this.SearchRadiusItems[0];

            if (!IsInDesignMode)
            {
                this.SearchResults = new ObservableCollection<UserStoreViewModel>();
                this.PersonalLocations = new ObservableCollection<PersonalLocationViewModel>();
                this.UserStores = new ObservableCollection<StoreViewModel>();
                this.Refresh();
            }
        }
        private void RemoveStore(StoreViewModel store)
        {
            this.storeModel.DeleteStoreForCurrentUserAsync(store, (error) =>
            {
                if (error != null)
                {
                    // Display error, normally this would be done through a property
                    MessageBox.Show(error.Message);
                    return;
                }

                this.UserStores.Remove(store);
                foreach (UserStoreViewModel userStore in this.SearchResults)
                {
                    if (userStore.Store.Id == store.Id)
                    {
                        userStore.UsedByUser = false;
                    }
                }
                //MessageBox.Show("Success");
            });
        }