private async void DeleteItemAsync_Offline(object sender, EventArgs e)
        {
            var userWantToDeleteProduct = await DisplayAlert("Delete product?", "Deletion of this product will be permanent", "Yes", "No");

            if (!userWantToDeleteProduct)
            {
                return;
            }

            OfflineRequestModel request = new OfflineRequestModel()
            {
                requestURL  = App.apiPath + App.productsApiPath + "/" + viewModel.Item.Id,
                data        = viewModel.Item,
                requestType = HttpMethod.Delete,
                useAuth     = true,
                changeType  = OfflineChangeType.Delete,
                commentary  = "Delete product: " + viewModel.Item.ManufacturerName + " " + viewModel.Item.ModelName
            };

            App.offlineSync.AddToSynchronizeList(request);

            MessagingCenter.Send(this, "DeleteItem", viewModel.Item);

            //App.Current.MainPage = new MainPage();
            await Navigation.PopAsync();
        }
        private void ChangeQuantity_Offline(object sender, EventArgs e)
        {
            int quantityChange;

            if (!int.TryParse(entry_QuantityChange.Text, out quantityChange))
            {
                label_InfoForUser.Text      = "Quantity change must have only number.";
                label_InfoForUser.TextColor = Color.Red;
                return;
            }

            OfflineRequestModel request = new OfflineRequestModel()
            {
                requestURL  = App.apiPath + App.productsApiPath + "/" + viewModel.Item.Id + "?quantityChange=" + entry_QuantityChange.Text,
                data        = viewModel.Item,
                requestType = HttpMethod.Put,
                useAuth     = true,
                changeType  = OfflineChangeType.ChangeQuantity,
                commentary  = "Change quantity of product: " + viewModel.Item.ManufacturerName + " " + viewModel.Item.ModelName + " by: " + entry_QuantityChange.Text
            };

            App.offlineSync.AddToSynchronizeList(request);

            viewModel.Item.Quantity += Int32.Parse(entry_QuantityChange.Text);
            MessagingCenter.Send(this, "ChangeItem", viewModel.Item);

            UpdatePageDetails();
            label_InfoForUser.Text      = "Quantity change succeded.";
            label_InfoForUser.TextColor = Color.Green;
            //App.Current.MainPage = new MainPage();
        }
Example #3
0
        async void Save_Clicked_Offline(object sender, EventArgs e)
        {
            Item.Id = Guid.NewGuid().GetHashCode();
            OfflineRequestModel request = new OfflineRequestModel()
            {
                requestURL  = App.apiPath + App.productsApiPath + App.countryContextPathSuffix,
                data        = Item,
                requestType = HttpMethod.Post,
                useAuth     = true,
                changeType  = OfflineChangeType.Create,
                commentary  = "Add new product: " + Item.ManufacturerName + " " + Item.ModelName
            };

            App.offlineSync.AddToSynchronizeList(request);

            MessagingCenter.Send(this, "AddItem", Item);
            await Navigation.PopModalAsync();
        }
        private void UpdateDetails_Offline(object sender, EventArgs e)
        {
            OfflineRequestModel request = new OfflineRequestModel()
            {
                requestURL  = App.apiPath + App.productsApiPath + App.countryContextPathSuffix,
                data        = viewModel.Item,
                requestType = HttpMethod.Put,
                useAuth     = true,
                changeType  = OfflineChangeType.Update,
                commentary  = "Update details of product: " + viewModel.Item.ManufacturerName + " " + viewModel.Item.ModelName
            };

            App.offlineSync.AddToSynchronizeList(request);

            MessagingCenter.Send(this, "ChangeItem", viewModel.Item);

            UpdatePageDetails();
            ChangeDetailsEditMode(sender, e);
            label_InfoForUser.Text      = "Product details update succeded.";
            label_InfoForUser.TextColor = Color.Green;
            //App.Current.MainPage = new MainPage();
        }
 public void AddToSynchronizeList(OfflineRequestModel request)
 {
     OfflineRequests.Add(request);
 }