protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            this.SetContentView(Resource.Layout.GroceryEdit);

            //Pull out all of the "extras" that were passed in the intent
            _groceryItem = new GroceryItem()
            {
                ObjectId    = Intent.GetStringExtra("objectId"),
                Title       = Intent.GetStringExtra("title"),
                Description = Intent.GetStringExtra("description"),
                Quantity    = Intent.GetIntExtra("quantity", 0)
            };

            //Grab each of the text views, which display the details about the grocery item, and assign them values
            txtTitle      = FindViewById <EditText> (Resource.Id.editText1);
            txtTitle.Text = _groceryItem.Title;

            txtDescription      = FindViewById <EditText> (Resource.Id.editText2);
            txtDescription.Text = _groceryItem.Description;

            //Grab the spinner control, and bind it to the resource array
            Spinner spinner = FindViewById <Spinner> (Resource.Id.spinner1);

            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);

            var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.quantity_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            //Set the selected item - this is easy because we have a 0-based array, which matchs the quantity
            spinner.SetSelection(_groceryItem.Quantity);

            //Finally, wire up the "Save" button
            Button btnEdit = FindViewById <Button> (Resource.Id.btnEdit);

            btnEdit.Click += (object sender, EventArgs e) => {
                //Persist these changes somewhere, and then navigate back to the "Grocery Detail" view
                Toast.MakeText(this, "Saving...", ToastLength.Long).Show();

                _groceryItem.Title       = txtTitle.Text;
                _groceryItem.Description = txtDescription.Text;

                Task.Factory.StartNew(() => {
                    if (!string.IsNullOrEmpty(_groceryItem.ObjectId))
                    {
                        GroceryService.UpdateGroceryItem(_groceryItem);
                    }
                    else
                    {
                        GroceryService.CreateGroceryItem(_groceryItem);
                    }
                }).ContinueWith((prevTask) => {
                    Intent i = new Intent(this, typeof(GroceryList));
                    StartActivity(i);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };
        }
 public AddNewProductsListViewModel(INavigationService navigationService, GroceryService groceryService) : base(navigationService)
 {
     Title = "Create new List";
     this.navigationService = navigationService;
     this.groceryService    = groceryService;
     SaveListCommand        = new Command(async() => await SaveList());
 }
        //initiate private service
        private GroceryService CreateGroceryService()
        {
            Guid           userId         = Guid.Parse(User.Identity.GetUserId());
            GroceryService groceryService = new GroceryService(userId);

            return(groceryService);
        }
Esempio n. 4
0
        // public Map Map { get; private set; }

        public AddNewProductViewModel(INavigationService navigationService, GroceryService groceryService, IMessage message) : base(navigationService)
        {
            Title = "Add new Product";
            this.navigationService = navigationService;
            this.groceryService    = groceryService;
            this.message           = message;
        }
Esempio n. 5
0
        public ShowProductsListViewModel(INavigationService navigationService, GroceryService groceryService, ProximityService proximityService, IMessage message) : base(navigationService)
        {
            Title = "Your shopping lists";
            this.navigationService = navigationService;
            this.groceryService    = groceryService;
            this.proximityService  = proximityService;
            this.message           = message;

            Lists = new ObservableCollection <ProductsList>();


            LoadListsCommand = new AsyncCommand(LoadLists);


            if (CrossGeolocator.Current.IsListening)
            {
                CrossGeolocator.Current.StopListeningAsync();
                Debug.WriteLine("Stop listening async for location.");
            }
            //ListenerSettings listenerSettings = new ListenerSettings { AllowBackgroundUpdates = true };

            // Task.Run(() => StartListentinLocationAsync());

            //CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
            //CrossGeolocator.Current.PositionError += Current_PositionError;
        }
        private async void saveRecord()
        {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            //Assign user set values back to object, and persist back to cloud
            detailItem.Title       = txtName.Text;
            detailItem.Description = txtDescription.Text;
            detailItem.Quantity    = int.Parse(txtQuantity.Text);

            _hud.Show(animated: true);

            if (!string.IsNullOrEmpty(detailItem.id))
            {
                await GroceryService.UpdateGroceryItemAsync(detailItem);
            }
            else
            {
                await GroceryService.CreateGroceryItemAsync(detailItem);
            }

            _hud.Hide(animated: true, delay: 5);

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;

            NavigationController.PopViewControllerAnimated(true);
        }
Esempio n. 7
0
 public MainPageViewModel(INavigationService navigationService, GroceryService groceryService)
     : base(navigationService)
 {
     Title = "Main Page";
     this.GroceryService = groceryService;
     //Debug.WriteLine(GroceryService.GetServiceNameAsync());
     DelegateCommand = new DelegateCommand(OnLaunch);
 }
        public async Task <IHttpActionResult> GetGroceryListById([FromUri] int id)
        {
            GroceryService service = CreateGroceryService();

            IEnumerable <GroceryListItem> groceryList = await service.GetGroceryListById(id);

            return(Ok(groceryList));
        }
Esempio n. 9
0
        public async void RefreshData()
        {
            _groceries = await GroceryService.GetGroceriesAsync();

            if (_groceries != null)
            {
                _groceryList.Adapter = new GroceryListAdapter(this, _groceries);
            }
        }
        public async Task <IHttpActionResult> GetAllGroceryLists()
        {
            //instantiate a service
            GroceryService service = CreateGroceryService();

            //return the values as an ienumerable
            IEnumerable <GroceryListItem> groceries = await service.GetGroceryLists();

            return(Ok(groceries));
        }
        public async Task <IHttpActionResult> DeleteGroceryList(int id)
        {
            GroceryService service = CreateGroceryService();

            if (await service.DeleteGroceryListById(id) == false)
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public async Task <IHttpActionResult> UpdateGroceryList([FromUri] int id, [FromBody] GroceryEdit model)
        {
            GroceryService service = CreateGroceryService();

            if (await service.UpdateGroceryListById(id, model) == false)
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        private async void refreshData()
        {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            _groceries = await GroceryService.GetGroceriesAsync();

            TableView.Source = dataSource = new DataSource(this, _groceries);
            TableView.ReloadData();

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
        }
        public ShowProductsViewModel(INavigationService navigationService, GroceryService groceryService, IPageDialogService dialogService, IMessage message) : base(navigationService)
        {
            this.navigationService = navigationService;
            this.groceryService    = groceryService;
            this.dialogService     = dialogService;
            this.message           = message;
            ProductList            = new ObservableCollection <Product>();
            LoadProductsCommand    = new DelegateCommand(LoadProducts);


            // LoadProductsCommand.Execute(null);
        }
Esempio n. 15
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            this.SetContentView(Resource.Layout.GroceryList);

            ListView groceryList = FindViewById <ListView> (Resource.Id.listView1);

            groceryList.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => {
                var t = _groceries[e.Position];

                Intent i = new Intent(this, typeof(GroceryDetailActivity));

                i.PutExtra("objectId", t.ObjectId);
                i.PutExtra("title", t.Title);
                i.PutExtra("description", t.Description);
                i.PutExtra("quantity", t.Quantity);

                StartActivity(i);
            };

            groceryList.ItemLongClick += (object sender, AdapterView.ItemLongClickEventArgs e) => {
                var t = _groceries[e.Position];

                Toast.MakeText(this, "You long pressed on " + t.Title, ToastLength.Long).Show();
            };

            Button addButton = FindViewById <Button> (Resource.Id.button1);

            addButton.Click += (object sender, EventArgs e) => {
                Intent i = new Intent(this, typeof(GroceryEditActivity));
                StartActivity(i);
            };

            Toast.MakeText(this, "Retrieving grocery list...", ToastLength.Long).Show();

            //Use the Task Parallel Library (TPL) to start a new thread to retreive a list of groceries from the server
            Task.Factory.StartNew(() => {
                _groceries = GroceryService.GetGroceries();
            }).ContinueWith((prevTask) => {
                //Check the response to see if there were any errors on the background task
                if (prevTask.Exception != null)
                {
                    Toast.MakeText(this, "Error retrieving results from server...", ToastLength.Long).Show();
                }
                else
                {
                    groceryList.Adapter = new GroceryListAdapter(this, _groceries);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            ConfigureView();

            txtDescription.EditingDidEnd += HandleEditingDidEnd;
            txtDescription.Delegate       = new CatchEnterDelegate();

            txtQuantity.EditingDidEnd += HandleEditingDidEnd;
            txtQuantity.Delegate       = new CatchEnterDelegate();

            txtName.EditingDidEnd += HandleEditingDidEnd;
            txtName.Delegate       = new CatchEnterDelegate();

            _hud = new MTMBProgressHUD(View)
            {
                LabelText = "Saving...",
                RemoveFromSuperViewOnHide = true
            };

            View.AddSubview(_hud);

            btnSave.TouchUpInside += (object sender, EventArgs e) => {
                //Assign user set values back to object, and persist back to cloud
                detailItem.Title       = txtName.Text;
                detailItem.Description = txtDescription.Text;
                detailItem.Quantity    = int.Parse(txtQuantity.Text);

                _hud.Show(animated: true);

                //Use Task Parallel Library (TPL) to show a status message while the data is saving
                Task.Factory.StartNew(() => {
                    if (!string.IsNullOrEmpty(detailItem.ObjectId))
                    {
                        GroceryService.UpdateGroceryItem(detailItem);
                    }
                    else
                    {
                        GroceryService.CreateGroceryItem(detailItem);
                    }

                    System.Threading.Thread.Sleep(new TimeSpan(0, 0, 5));
                }).ContinueWith((prevTask) => {
                    _hud.Hide(animated: true, delay: 5);
                    NavigationController.PopViewControllerAnimated(true);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };
        }
        public async Task <IHttpActionResult> CreateGroceryList(GroceryCreate grocery)
        {
            //check if model is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //instantiate the service
            GroceryService service = CreateGroceryService();

            if (await service.CreateGroceryList(grocery) == false)
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Esempio n. 18
0
            public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
            {
                if (editingStyle == UITableViewCellEditingStyle.Delete)
                {
                    // Delete the row from the data source.
                    controller.TableView.BeginUpdates();

                    var groceryItem = objects [indexPath.Row];
                    objects.RemoveAt(indexPath.Row);
                    GroceryService.DeleteGroceryItem(groceryItem);
                    controller.TableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);

                    controller.TableView.EndUpdates();
                }
                else if (editingStyle == UITableViewCellEditingStyle.Insert)
                {
                    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
                }
            }
Esempio n. 19
0
        private void refreshData()
        {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            //Use the Task Parallel Library (TPL) to start a new thread to retreive a list of groceries from the server
            Task.Factory.StartNew(() => {
                _groceries = GroceryService.GetGroceries();
            }).ContinueWith((prevTask) => {
                InvokeOnMainThread(() => {
                    //Check the response to see if there were any errors on the background task
                    if (prevTask.Exception != null)
                    {
                        //Toast.MakeText (this, "Error retrieving results from server...", ToastLength.Long).Show ();
                    }
                    else
                    {
                        TableView.Source = dataSource = new DataSource(this, _groceries);
                        TableView.ReloadData();
                        UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                    }
                });
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Esempio n. 20
0
 public GroceryList()
 {
     service = new GroceryService();
     InitializeComponent();
     LoadGroceryList();
 }
Esempio n. 21
0
 public void Setup()
 {
     _baseRepository = Mock.Of <IBaseRepository <Grocery> >();
     _unitOfWork     = Mock.Of <IUnitOfWork>();
     _sut            = new GroceryService(_baseRepository, _unitOfWork);
 }