Esempio n. 1
0
        //POST: Ebay/OrderApiInitiateGuestCheckoutSession/{data}
        public ActionResult OrderApiInitiateGuestCheckoutSession(EbayOrderApiInitiateGuestCheckoutSessionModel data)
        {
            SelectCustomerModel customerData = new SelectCustomerModel()
            {
                Email = data.email
            };

            CustomerResultModel customerResult = customerTable.SelectRecord(customerData);

            if (customerResult.CustomerUUID == null)
            {
                return(Json(new { result = "Fail", reason = "Invalid User" }));
            }

            AddressResultModel addressData = addressTable.SelectRecord(new SelectAddressModel()
            {
                CustomerUUID = customerResult.CustomerUUID
            });

            CheckoutSessionResponse response = OrderAPI.InitiateGuestCheckoutSession(data.orderId, customerResult, addressData);

            InsertCustomerOrderModel customerOrder = new InsertCustomerOrderModel()
            {
                CustomerUUID      = customerResult.CustomerUUID,
                CheckoutSessionID = response.checkoutSessionId,
                ExpirationDate    = response.expirationDate,
                ImageURL          = data.imageUrl,
                PurchasePrice     = response.pricingSummary.total.value,
                Title             = response.lineItems[0].title
            };

            NonQueryResultModel orderResult = customerOrderTable.InsertRecord(customerOrder);

            return(Json(response));
        }
Esempio n. 2
0
        public ActionResult DailyPurchase()
        {
            List <CustomerResultModel> customerList = customerTable.SelectAllRecords();

            foreach (CustomerResultModel customer in customerList)
            {
                //Get customer's query prefrences
                QueryResultModel queryPref = queryTable.SelectRecord(new SelectQueryModel()
                {
                    CustomerUUID = customer.CustomerUUID
                });

                //Ask Ebay for items.
                SearchPagedCollection itemCollection = BrowseAPI.ItemSummarySearch(queryPref.CategoryID, queryPref.PriceLimit);

                try
                {
                    //There were no items found for this query
                    if (itemCollection.itemSummaries.Length == 0)
                    {
                        continue;
                    }

                    //Get customer's address data
                    AddressResultModel customerAddress = addressTable.SelectRecord(new SelectAddressModel()
                    {
                        CustomerUUID = customer.CustomerUUID
                    });

                    //Initiate order with a randomly chosen index from itemCollection's itemSummaries
                    Random rand      = new Random();
                    int    itemIndex = rand.Next(itemCollection.itemSummaries.Length);

                    CheckoutSessionResponse response = OrderAPI.InitiateGuestCheckoutSession(itemCollection.itemSummaries[itemIndex].itemId, customer, customerAddress);

                    InsertCustomerOrderModel customerOrder = new InsertCustomerOrderModel()
                    {
                        CustomerUUID      = customer.CustomerUUID,
                        CheckoutSessionID = response.checkoutSessionId,
                        ExpirationDate    = response.expirationDate,
                        ImageURL          = itemCollection.itemSummaries[itemIndex].image.imageUrl,
                        PurchasePrice     = response.pricingSummary.total.value,
                        Title             = response.lineItems[0].title
                    };

                    NonQueryResultModel orderResult = customerOrderTable.InsertRecord(customerOrder);
                }
                catch (Exception e)
                {
                }
            }

            return(Json(new { result = "Daily Purchases Complete" }));
        }