/* Allows for the user to select a new random * photo and calls the async method. This may * not always produce a new avatar everytime * if i had more time I would have fixed this by * tracking which photo the user has and not * including that in the randomiser */ private void EditPhoto(object sender, RoutedEventArgs e) { SearchData newAcct = new APIClasses.SearchData(); newAcct.index = Int32.Parse(IndexBox.Text); Task search = EditPhotoAsync(sender, e, newAcct); }
/* Allows the user to edit their balance * takes in their new balance and their index */ private void EditBalance(object sender, RoutedEventArgs e) { SearchData newBalance = new APIClasses.SearchData(); newBalance.searchStr = BalanceBox.Text; newBalance.index = Int32.Parse(IndexBox.Text); Task search = EditBalanceAsync(sender, e, newBalance); }
/* Allows the user to change the users first name * Minimal error handling because it can be anything */ private void EditFName(object sender, RoutedEventArgs e) { //do nothing atm SearchData newName = new APIClasses.SearchData(); newName.searchStr = FNameBox.Text; newName.index = Int32.Parse(IndexBox.Text); Task search = EditFNameAsync(sender, e, newName); }
/* Allows the user to change their last name * Little error handling because a name can be anything */ private void EditLName(object sender, RoutedEventArgs e) { SearchData newName = new APIClasses.SearchData(); //Converted to upper because thats how last names are stored in the database newName.searchStr = LNameBox.Text.ToUpper(); newName.index = Int32.Parse(IndexBox.Text); Task search = EditLNameAsync(sender, e, newName); }
/* Allows for the user to enter a new pin * this has no limit on its size to increase * security */ private void EditPin(object sender, RoutedEventArgs e) { //Using the searchdata class to bundle data SearchData newAcct = new APIClasses.SearchData(); newAcct.searchStr = PinBox.Text; newAcct.index = Int32.Parse(IndexBox.Text); Task search = EditPinAsync(sender, e, newAcct); }
/*Asynchronously searching for someone with that last name*/ private async Task SearchNameAsync(object sender, RoutedEventArgs e) { SearchData mySearch = new APIClasses.SearchData(); mySearch.searchStr = SearchBox.Text.ToUpper(); ProgressBar.Visibility = Visibility.Visible; ChangeUIElements(true); await Task.Run(() => { RestRequest request = new RestRequest("api/search"); request.AddJsonBody(mySearch); //Do the request IRestResponse resp = client.Post(request); this.Dispatcher.Invoke(() => { if (resp.IsSuccessful) //IF that name exists in the database { TransitionModel transModel = JsonConvert.DeserializeObject <TransitionModel>(resp.Content); DataIntermed dataIntermed = JsonConvert.DeserializeObject <DataIntermed>(transModel.message); /*Updating the users fields*/ FNameBox.Text = dataIntermed.fName; LNameBox.Text = dataIntermed.lName; BalanceBox.Text = dataIntermed.bal.ToString("C"); //"C" so its in money form AcctNoBox.Text = dataIntermed.acctNo.ToString(); PinBox.Text = dataIntermed.pin.ToString("D4"); IndexBox.Text = dataIntermed.index.ToString(); Bitmap bmp; using (var ms = new MemoryStream(dataIntermed.image)) { bmp = new Bitmap(ms); } //Converting byte array to bitmap -> see below for reference Photo.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); ChangeUIElements(false); ProgressBar.Visibility = Visibility.Hidden; } else //If the response isn't successful { string errmsg = resp.Content; MessageBox.Show(errmsg); AfterError(); } //Return ui back to normal ChangeUIElements(false); ProgressBar.Visibility = Visibility.Hidden; SearchBox.Visibility = Visibility.Visible; }); }); }