private async void  searchbtnclicked(object sender, RoutedEventArgs e)
        {
            String location = ((ComboBoxItem)locationcomboBox.SelectedItem).Content.ToString();
            String category = ((ComboBoxItem)categorycomboBox.SelectedItem).Content.ToString();

            var parameters = new Dictionary<String, String> { {"Location",location}, { "Category",category} };
           // parameters.Add("Location",location);
           // parameters.Add("Category",category);

            try
            {
                restaurants = await restaurantTable.WithParameters(parameters).ToCollectionAsync();
                
            }
            catch (MobileServiceInvalidOperationException ex)
            {
                await new MessageDialog(ex.Message, "Could not connect to server.").ShowAsync();

            }
           
            

            Boolean containsvalue = restaurants.Any<Restaurant>();
            if (!containsvalue)
            {
                await new MessageDialog("No restaurants matching!").ShowAsync();

            }

            ListItems.ItemsSource = restaurants;

           // Restaurant res1 = restaurants.First<Restaurant>();
           // Restaurant res2 = restaurants.Last<Restaurant>();
           // System.Diagnostics.Debug.WriteLine("first element returned:" + res1.Name);
           // System.Diagnostics.Debug.WriteLine("last element returned:" + res2.Name);



        }
Beispiel #2
0
        async void MyItemsSource_CollectionChangedAsync(object sender, NotifyCollectionChangedEventArgs e)
        {
            var x = sender as TrulyObservableCollection <Status>;

            if (x != null && this.ListShowDb.Count == x.Count)
            {
                // i is the index
                foreach (var item in x.Select((value, i) => new { i, value }))
                {
                    // Checking is selection has been made for this products
                    if (item.value.Selected != this.ListShowDb[item.i])
                    {
                        // This excuted when selection of a buyer has been made
                        Console.WriteLine($"Assigned  { item.value.Selected} to buy { item.value.Name}");
                        // Updating the element in the list
                        this.ListShowDb[item.i] = item.value.Selected;

                        IMobileServiceTable <Status>             _status     = App.MobileService.GetTable <Status>();
                        MobileServiceCollection <Status, Status> _statusenum = await _status
                                                                               .Where(u => u.Name != string.Empty)
                                                                               .ToCollectionAsync();

                        if (_statusenum.Any(p => p.Name == item.value.Name))
                        {
                            // Updating the db with the buyer name selected information
                            var modified = _statusenum.SingleOrDefault(p => p.Name == item.value.Name);
                            var cc       = await _status.LookupAsync(modified.Id);

                            await _status.DeleteAsync(cc);

                            cc.Selected = item.value.Selected;
                            await _status.InsertAsync(cc);
                        }
                        else
                        {
                            // Adding information into db with the buyer name selected
                            await App.MobileService.GetTable <Status>().InsertAsync(new Status()
                            {
                                Name = item.value.Name, Selected = item.value.Selected, CreatedAt = null
                            });
                        }
                    }
                    else
                    {
                        // this is executed when shopping was done
                        IMobileServiceTable <Status>             _status     = App.MobileService.GetTable <Status>();
                        MobileServiceCollection <Status, Status> _statusenum = await _status
                                                                               .Where(u => u.Name != string.Empty)
                                                                               .ToCollectionAsync();

                        var excuted = _statusenum.SingleOrDefault(g => g.Name == item.value.Name);

                        if (excuted != null && item.value.Executed != excuted.Executed)
                        {
                            // Changing information about execution
                            Console.WriteLine($" {item.value.Name}  was bought = {item.value.Executed}");
                            var modified = _statusenum.SingleOrDefault(g => g.Name == item.value.Name);
                            await App.MobileService.GetTable <Status>().DeleteAsync(modified);

                            modified.Executed = item.value.Executed;
                            await App.MobileService.GetTable <Status>().InsertAsync(modified);
                        }
                    }
                }
            }
            if (x.Count != this.ListShowDb.Count)
            {
                this.ListShowDb.Clear();
                foreach (var item in x)
                {
                    this.ListShowDb.Add(item.Selected);
                }
            }
        }
Beispiel #3
0
        async void UpdateLists()
        {
            IMobileServiceTable <Item>           _products     = App.MobileService.GetTable <Item>();
            MobileServiceCollection <Item, Item> _productsenum = await _products
                                                                 .Where(i => i.Name != string.Empty)
                                                                 .ToCollectionAsync();

            foreach (var item in _productsenum)
            {
                // Adding products to the list from the db
                if (!this.List.Any(x => x.Name == item.Name))
                {
                    this.List.Add(item);
                }
            }
            // Gettings number of products
            this.NumberofItems.Value = this.List.Count();


            IMobileServiceTable <User>           _users     = App.MobileService.GetTable <User>();
            MobileServiceCollection <User, User> _usersenum = await _users
                                                              .Where(u => u.FirstName != string.Empty)
                                                              .ToCollectionAsync();

            foreach (var user in _usersenum)
            {
                if (!this.UserList.Any(x => x.Id == user.Id))
                {
                    // Adding users to the list from the db
                    this.UserList.Add(user);
                }
            }
            // Gettings number of buyers
            this.NumberofUsers.Value = this.UserList.Count();

            foreach (var item in this.List)
            {
                var Li = new ObservableCollection <User>();
                foreach (var us in this.UserList)
                {
                    // Gettings Buyers list from the db
                    Li.Add(us);
                }
                if (!this.ListShow.Any(x => x.Name == item.Name))
                {
                    IMobileServiceTable <Status>             _status     = App.MobileService.GetTable <Status>();
                    MobileServiceCollection <Status, Status> _statusenum = await _status
                                                                           .Where(u => u.Name != string.Empty)
                                                                           .ToCollectionAsync();

                    if (_statusenum.Any(p => p.Name == item.Name))
                    {
                        // Get selection from the db and show
                        var selecteduser = _statusenum.SingleOrDefault(p => p.Name == item.Name).Selected;
                        this.ListShow.Add(new Status(new ReactiveProperty <User>(this.UserList.SingleOrDefault(g => g.FirstName == selecteduser)), new ReactiveProperty <bool>(_statusenum.SingleOrDefault(p => p.Name == item.Name).Executed))
                        {
                            Name = item.Name, UserList = Li
                        });
                    }
                    else
                    {
                        // Get selection from the db and show
                        this.ListShow.Add(new Status {
                            Name = item.Name, UserList = Li
                        });
                    }
                }
            }
        }
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            String userName = userNameText.Text;
            String password = passwordBox.Password;

            try
            {
                guests = await guestTable.Where(guests => guests.name == userName && guests.password == password).ToCollectionAsync();
            }
            catch (MobileServiceInvalidOperationException ex)
            {
                await new MessageDialog(ex.Message, "Could not connect to server.").ShowAsync();
                System.Diagnostics.Debug.WriteLine("This is user name and password :"******"username"] = userName;
                this.Frame.Navigate(typeof(Home), null);
                var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
                string deviceId = GetDeviceId();
                string uri = channel.Uri;
                System.Diagnostics.Debug.WriteLine("uri is :" + uri);
                try
                {
                    await App.azure_rendezvous_mobile_service_3Client.GetPush().RegisterNativeAsync(channel.Uri);
                    await App.azure_rendezvous_mobile_service_3Client.InvokeApiAsync("modifychanneluri", new JObject(new JProperty("channeluri", uri), new JProperty("username", userName)));
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    System.Diagnostics.Debug.WriteLine("exception is :" + ex.Message);
                }
            }
            else
            {
                MessageDialog msgBox = new MessageDialog("Invalid username or password");
                await msgBox.ShowAsync();
            }

        }