예제 #1
0
        private void SearchListings_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var json = GenerateSearchJson(Search_TextBox.Text);
                // Call the API for a list of items
                var     resp    = new RequestSender().SendPost("SearchTransactions", json);
                dynamic desResp = JsonConvert.DeserializeObject(resp);
                desResp = JsonConvert.DeserializeObject(desResp);
                List <SimpleListing> sListings = new List <SimpleListing>();
                foreach (var t in desResp)
                {
                    SimpleListing s = new SimpleListing();
                    s.Author    = t["Author"].ToString();
                    s.Title     = t["Name"].ToString();
                    s.ISBN      = t["ISBN"].ToString();
                    s.Price     = Convert.ToDouble(t["ListPrice"]);
                    s.Quality   = t["Condition"].ToString();
                    s.ListingId = Convert.ToInt32(t["TransactionId"]);

                    sListings.Add(s);
                }
                new Listings().GenerateListingList(sListings, Listings_StackPanel, true);
                // Generate Listing List
            }
            catch (Exception ex)
            {
            }
        }
예제 #2
0
        /// <summary>
        /// Fires when the user is trying to send a new transaction to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SubmitTransaction_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (SessionState.LoggedIn == false)
                {
                    MessageDialog message = new MessageDialog("You are not signed in. Please proceed to the sign in page.");
                    await message.ShowAsync();
                }
                //Build the POST request to the server
                SimpleListing newListing = new SimpleListing();
                newListing.Author      = Author_TextBox.Text;
                newListing.ISBN        = ISBN_TextBox.Text;
                newListing.Price       = Convert.ToInt32(Price_TextBox.Text);
                newListing.Title       = Title_TextBox.Text;
                newListing.Description = Description_TextBox.Text;

                string        json           = new Listings().GenerateRequestJson(newListing);
                dynamic       desResponse    = JsonConvert.DeserializeObject((string)JsonConvert.DeserializeObject(json));
                var           listingId      = desResponse.NewListingId;
                MessageDialog successMessage = new MessageDialog("The transaction has been created.");
                await successMessage.ShowAsync();
            }
            catch (Exception ex)
            {
            }
        }
예제 #3
0
        public HomePage()
        {
            try
            {
                this.InitializeComponent();
                if (SessionState.LoggedIn == true)
                {
                    LoginControls_StackPanel.Visibility = Visibility.Collapsed;
                    // We need to get the data for the user now.
                    var     response = new RequestSender().SendGet(string.Format("GetProfile?Uid={0}", SessionState.LoggedInId));
                    dynamic des      = JsonConvert.DeserializeObject(response);
                    des = JsonConvert.DeserializeObject((string)des);

                    UserInfo_UserName_TextBlock.Text     = "User Name: " + des["Data"]["UserName"].ToString();
                    UserInfo_PhoneNumber_TextBlock.Text  = "Phone Number " + des["Data"]["PhoneNumber"].ToString();
                    UserInfo_EmailAddress_TextBlock.Text = "Email Address: " + des["Data"]["EmailAddress"].ToString();

                    // Next we load the open transactions for the current user
                    var     userTransactionsResponse = (string)JsonConvert.DeserializeObject(new RequestSender().SendGet("GetUserTransactions?UserId=" + SessionState.LoggedInId));
                    dynamic userTDeserialized        = JsonConvert.DeserializeObject(userTransactionsResponse);
                    // Organize
                    List <SimpleListing> simpleList = new List <SimpleListing>();
                    foreach (var item in userTDeserialized.Data.Transactions)
                    {
                        SimpleListing s = new SimpleListing();
                        s.Author    = item.Author;
                        s.ISBN      = item.ISBN;
                        s.ListingId = item.TransactionId;
                        s.Price     = item.ListPrice;
                        s.Title     = item.Name;
                        simpleList.Add(s);
                    }
                    if (simpleList.Count > 0)
                    {
                        new Listings().GenerateListingList(simpleList, UserTransactions_StackPanel, false);
                    }
                    UserInfo_StackPanel.Visibility = Visibility.Visible;
                }
            }
            catch (Exception e)
            {
            }
        }