Ejemplo n.º 1
0
        async void onDeleteTapped(object sender, EventArgs args)
        {
            var            tenderSelected = ((TappedEventArgs)args).Parameter;
            tenderBookmark tenderBookmark = (tenderBookmark)tenderSelected;
            tenderItem     tender         = new tenderItem();

            tender.Reference = tenderBookmark.tenderReferenceNumber;
            List <tenderBookmark> tempBookmarkList = (List <tenderBookmark>)listView.ItemsSource;

            var answer = await DisplayAlert("Remove bookmark", "Are you sure you want to remove bookmark '" + tender.Reference + "'?", "YES", "NO");

            if (answer)
            {
                //remove bookmark from listview
                foreach (var bookmarkItem in tempBookmarkList.ToList())
                {
                    if (bookmarkItem == tenderBookmark)
                    {
                        int index = tempBookmarkList.IndexOf(bookmarkItem);
                        tempBookmarkList.Remove(bookmarkItem);
                    }
                }

                //Refresh listview
                listView.ItemsSource = tempBookmarkList.ToList();

                //Display error message when there are no bookmark
                if (tempBookmarkList.Count <= 0)
                {
                    errorMsg.Text      = "No bookmark found.";
                    errorMsg.IsVisible = true;
                    upBtn.IsVisible    = false;
                }

                //Remove bookmark from database
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                var httpResult = httpTask.ToString();
                Console.WriteLine(httpResult);
                int count = 0;

                while (count < 3 && httpResult != "Success")
                {
                    Console.WriteLine("Looping for failure delete");
                    httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                    httpResult = httpTask.ToString();
                    count++;
                }
            }
        }
Ejemplo n.º 2
0
        /*void OnCartTapped(object sender, EventArgs args)
         * {
         *  var tenderSelected = ((TappedEventArgs)args).Parameter;
         *  tenderItem tender = (tenderItem)tenderSelected;
         *
         *  DisplayAlert("Success", tender.AddToCartQuantity + " Item " + tender.Reference + " has been successfully added to cart ", "OK");
         * }*/

        async void OnBookmarkTapped(object sender, EventArgs eventArgs)
        {
            //check if user is logged in
            if (userSession.userLoginCookie == "")
            {
                DisplayAlert("Login required", "Please login first to bookmark this item.", "OK");
            }
            else
            {
                var        tenderSelected = ((TappedEventArgs)eventArgs).Parameter;
                tenderItem tender         = (tenderItem)tenderSelected;
                //var image = sender as Image;
                Console.WriteLine("Image now is: " + ((Image)sender).Source.ToString());

                if (((Image)sender).Source.ToString() == "File: bookmarkfilled.png")
                {
                    ((Image)sender).Source = "bookmark.png";
                    DisplayAlert("Cancel bookmark", "Tender '" + tender.Reference + "' has been removed from bookmark!", "OK");

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                    var httpResult = httpTask.ToString();
                    Console.WriteLine(httpResult);
                    int count = 0;

                    while (count < 3 && httpResult != "Success")
                    {
                        Console.WriteLine("Looping for failure delete");
                        httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "delete"));

                        httpResult = httpTask.ToString();
                        count++;
                    }
                }
                else
                {
                    ((Image)sender).Source = "bookmarkfilled.png";
                    DisplayAlert("Add bookmark", "Tender '" + tender.Reference + "' has been successfully added to bookmark!", "OK");

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "add"));

                    var httpResult = httpTask.ToString();
                    Console.WriteLine(httpResult);
                    int count = 0;

                    while (count < 3 && httpResult != "Success")
                    {
                        Console.WriteLine("Looping for failure add");
                        httpTask = await Task.Run <string>(() => HttpRequestHandler.PostManageTenderBookmark(userSession.username, tender, "add"));

                        httpResult = httpTask.ToString();
                        count++;
                    }
                }
            }


            //Display tender list with or without bookmark

            //send request to database everyone user tap on bookmark
        }