//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)); }
public ActionResult SetSettings(QuerySetSettingsModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); UpdateQueryModel queryData = new UpdateQueryModel() { CustomerUUID = customerResult.CustomerUUID, Category = data.category, CategoryID = data.categoryId, Frequency = data.frequencyOptions.label, PriceLimit = data.price }; NonQueryResultModel updateResult = queryTable.UpdateRecord(queryData); if (updateResult.Success) { return(Json(new { result = "Success" })); } else { return(Json(new { result = "Fail" })); } }
public static int UpdateAccessToken() { DateTime updateTime = DateTime.Now; IDictionary <string, object> tokenResponse = RequestApplicationAccessToken(); UpdateAccessTokenModel accessToken = new UpdateAccessTokenModel() { AccessToken = tokenResponse["access_token"].ToString(), ExpiresIn = (int)tokenResponse["expires_in"], RefreshToken = tokenResponse["refresh_token"].ToString(), DateCreated = updateTime, UseType = "ApplicationAccessToken", TokenType = (string)tokenResponse["token_type"] }; NonQueryResultModel tokenResult = accessTokenTable.UpdateRecord(accessToken); if (tokenResult.Success) { return(1); } else { return(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" })); }
public ActionResult ChangePassword(PreferenceChangePasswordModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Invalid Customer" })); } bool verifyPassword = Password.VerifyHash(data.oldPassword, customerResult.Hash); if (!verifyPassword) { return(Json(new { result = "Fail", reason = "Invalid Password" })); } //Generate Password's Salt and Hash byte[] salt = Password.ComputeSaltBytes(); string hashString = Password.ComputeHash(data.newPassword, salt); string saltString = Convert.ToBase64String(salt); customerResult.Hash = hashString; customerResult.Salt = saltString; UpdateCustomerModel customerUpdate = new UpdateCustomerModel() { CustomerUUID = customerResult.CustomerUUID, Email = customerResult.Email, FirstName = customerResult.FirstName, LastName = customerResult.LastName, Hash = customerResult.Hash, Salt = customerResult.Salt, Phone = customerResult.Phone }; NonQueryResultModel updateResult = customerTable.UpdateRecord(customerUpdate); if (updateResult.Success) { return(Json(new { result = "Success" })); } else { return(Json(new { result = "Fail", reason = "Password was not updated" })); } }
public void UpdateQueryRecord() { QueryTable table = QueryTable.Instance(new QueryDataAccess()); NonQueryResultModel expectedResult = new NonQueryResultModel() { Success = true }; NonQueryResultModel result = table.UpdateRecord(new UpdateQueryModel() { CustomerUUID = "CustUUID01" }); Assert.AreEqual(expectedResult.Success, result.Success); }
public void DeleteQueryRecordNonExistent() { QueryTable table = QueryTable.Instance(new QueryDataAccess()); NonQueryResultModel expectedResult = new NonQueryResultModel() { Success = false }; NonQueryResultModel result = table.DeleteRecord(new DeleteQueryModel() { CustomerUUID = "NonExistentID" }); Assert.AreEqual(expectedResult.Success, result.Success); }
protected NonQueryResultModel PrepareNonQueryResult(int result, int expectedResult = 1) { bool succeeded = false; if (result == expectedResult) { succeeded = true; } NonQueryResultModel payload = new NonQueryResultModel() { Success = succeeded }; return(payload); }
public ActionResult UpdateAddress(PreferenceAddressModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Invalid Customer" })); } UpdateAddressModel customerAddress = new UpdateAddressModel() { CustomerUUID = customerResult.CustomerUUID, BillingAddress = data.streetName, BillingAddress2 = data.streetName2, BillingCity = data.city, BillingState = data.state, BillingZip = data.postalCode, ShippingAddress = data.streetName, ShippingAddress2 = data.streetName2, ShippingCity = data.city, ShippingState = data.state, ShippingZip = data.postalCode }; NonQueryResultModel updateResult = addressTable.UpdateRecord(customerAddress); if (updateResult.Success) { return(Json(new { result = "Success" })); } else { return(Json(new { result = "Fail", reason = "Database Update Failed" })); } }
public ActionResult Register(LoginRegisterModel id) { //Check if we already have a user registered with the same email address if (customerTable.SelectRecord(new SelectCustomerModel() { Email = id.email }).CustomerUUID != null) { return(Json(new { result = "Fail", reason = "Email address is already registered" })); } //Generate Password's Salt and Hash byte[] salt = Password.ComputeSaltBytes(); string hashString = Password.ComputeHash(id.password, salt); string saltString = Convert.ToBase64String(salt); //Insert into Customer table InsertCustomerModel newCustomer = new InsertCustomerModel() { FirstName = id.firstName, LastName = id.lastName, Phone = id.phone, Email = id.email, Hash = hashString, Salt = saltString }; CustomerResultModel customerResult = customerTable.InsertRecord(newCustomer); //If it didn't insert, then we won't get a UUID back if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Insert into the database was not successful" })); } //Insert customer's address into the address table InsertAddressModel customerAddress = new InsertAddressModel() { CustomerUUID = customerResult.CustomerUUID, BillingAddress = id.address, BillingAddress2 = id.address2, BillingCity = id.city, BillingState = id.state, BillingZip = Int32.Parse(id.postalCode), ShippingAddress = id.address, ShippingAddress2 = id.address2, ShippingCity = id.city, ShippingState = id.state, ShippingZip = Int32.Parse(id.postalCode) }; NonQueryResultModel addressResult = addressTable.InsertRecord(customerAddress); //We have the option to 'do something' if the insert fails //Insert into Query table InsertQueryModel customerQuery = new InsertQueryModel() { CustomerUUID = customerResult.CustomerUUID, Category = "", CategoryID = "", Frequency = "", PriceLimit = "" }; NonQueryResultModel queryResult = queryTable.InsertRecord(customerQuery); //If this fails, we have the option of doing something //Aaaand we're done. return(Json(new { result = "Success" })); }