Esempio n. 1
0
        public string GenerateRequestJson(SimpleListing listingDetails)
        {
            try
            {
                Dictionary <string, dynamic> jsonDictionary = new Dictionary <string, dynamic>();
                jsonDictionary.Add("UserId", SessionState.LoggedInId);
                jsonDictionary.Add("Name", listingDetails.Title);
                jsonDictionary.Add("ISBN", listingDetails.ISBN);
                jsonDictionary.Add("Images", listingDetails.Images);
                jsonDictionary.Add("Author", listingDetails.Author);
                jsonDictionary.Add("Publisher", listingDetails.Publisher);
                jsonDictionary.Add("ListPrice", listingDetails.Price);
                jsonDictionary.Add("Negotiable", listingDetails.Negotiable);
                jsonDictionary.Add("Description", listingDetails.Description);


                var json = JsonConvert.SerializeObject(jsonDictionary);

                // Send this to the server
                dynamic response = new RequestSender().SendPost("NewListing", json);


                return(response);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Esempio n. 2
0
        private Grid GenerateListing(SimpleListing sl, StackPanel panel, bool IncludeButton)
        {
            Grid             listingGrid = new Grid();
            ColumnDefinition c1          = new ColumnDefinition();
            ColumnDefinition c2          = new ColumnDefinition();
            ColumnDefinition c3          = new ColumnDefinition();
            ColumnDefinition c4          = new ColumnDefinition();

            c1.Width = new Windows.UI.Xaml.GridLength(2, Windows.UI.Xaml.GridUnitType.Star);
            c2.Width = new Windows.UI.Xaml.GridLength(4, Windows.UI.Xaml.GridUnitType.Star);
            c3.Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star);
            c4.Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star);
            listingGrid.ColumnDefinitions.Add(c1); // Left column has the author details
            listingGrid.ColumnDefinitions.Add(c2); // Center grid has title of the book
            listingGrid.ColumnDefinitions.Add(c3); // Right Column has the price
            listingGrid.ColumnDefinitions.Add(c4);

            TextBlock title = new TextBlock();

            title.Text = sl.Title;

            TextBlock auth = new TextBlock();

            auth.Text = "Written by: " + sl.Author;

            TextBlock isbn = new TextBlock();

            isbn.Text = "ISBN: " + sl.ISBN;

            TextBlock price = new TextBlock();

            price.Text = "$" + sl.Price.ToString();

            TextBlock quality = new TextBlock();

            quality.Text = "Quality: " + sl.Quality;

            StackPanel col1Sp = new StackPanel();

            col1Sp.Children.Add(auth);
            col1Sp.Children.Add(quality);

            StackPanel col2Sp = new StackPanel();

            col2Sp.Children.Add(title);
            col2Sp.Children.Add(isbn);


            TextBox BidBox = new TextBox();

            BidBox.Visibility      = Visibility.Collapsed;
            BidBox.PlaceholderText = "Bid";

            StackPanel buyStack = new StackPanel();

            buyStack.Orientation = Orientation.Horizontal;


            if (IncludeButton == true)
            {
                // Create buy button unique to that entry
                Button buyButton = new Button();
                buyButton.Content = "Place Bid";
                buyButton.Tag     = new Dictionary <string, dynamic>()
                {
                    { "TransactionId", sl.ListingId },
                    { "BidBox", BidBox }
                };
                buyButton.Click += BuyButton_Click;
                buyStack.Children.Add(buyButton);
            }
            else
            {
                // Create buy button unique to that entry
                Button checkBids = new Button();
                checkBids.Content = "Check Bids";
                checkBids.Tag     = new Dictionary <string, dynamic>()
                {
                    { "TransactionId", sl.ListingId }
                };
                checkBids.Click += CheckBids_Click;;
                buyStack.Children.Add(checkBids);
            }

            buyStack.Children.Add(BidBox);

            // Add the stackpanels to the grid
            Grid.SetColumn(col1Sp, 0);
            Grid.SetColumn(col2Sp, 1);
            Grid.SetColumn(price, 2);
            Grid.SetColumn(buyStack, 3);

            listingGrid.Children.Add(col1Sp);
            listingGrid.Children.Add(col2Sp);
            listingGrid.Children.Add(price);
            listingGrid.Children.Add(buyStack);

            return(listingGrid);
        }