private void BtnUpdate_Click(object sender, RoutedEventArgs e) { var oExp = new Expense(); var exp_rowlist = (Expense)dgExpense.SelectedItem; if (exp_rowlist == null) { MessageBox.Show("No Expense has been selected to updated..", "Failed to update", MessageBoxButton.OK, MessageBoxImage.Asterisk); } else { if (MessageBox.Show("Are you sure want to update this expense", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { oExp.ExpenseTitle = txtExpTitle.Text.Trim(); oExp.ExpensesAmount = Convert.ToDouble(txtAmt.Text); oExp.ExpenseDate = Convert.ToDateTime(dtExp.Text); oExp.Signature = txtSing.Text; oExp.CategoryId = (int)cbCategory.SelectedValue; oExp.CurrencyId = (int)cbCurrency.SelectedValue; if (!string.IsNullOrEmpty(txtDetails.Text)) { oExp.ExpenseDetail = txtDetails.Text; } var uriExpense = _uriExpense + "/" + exp_rowlist.Id; var updateExpTask = Task.Run(() => ApiCaller.Put <Expense>(uriExpense, oExp)); updateExpTask.Wait(); //var expense = newExpTask.Result; // Expense Binding var expense = updateExpTask.IsCompleted; if (expense) { oExp.Id = exp_rowlist.Id; _expList[(_expList.FindIndex(s => s.Id == exp_rowlist.Id))] = oExp; LoadDataIntoControls(); } ClearValue(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}"); lblInfo.Text = ex.Message; } } } }
private void LoadDataFromApi() { try { Task <List <Category> > catTask = Task.Run(() => ApiCaller.Get <List <Category> >(_uriExpCategory)); catTask.Wait(); _catList = catTask.Result; Task <List <Currency> > curTask = Task.Run(() => ApiCaller.Get <List <Currency> >(_uriExpCurrency)); curTask.Wait(); _curList = curTask.Result; Task <List <Expense> > expTask = Task.Run(() => ApiCaller.Get <List <Expense> >(_uriExpenses)); expTask.Wait(); _expList = expTask.Result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}"); lblInfo.Text = ex.Message; } }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { var exp_rowlist = (Expense)dgExpense.SelectedItem; if (exp_rowlist == null) { MessageBox.Show("No Expense has been selected to remove..", "Failed to remove", MessageBoxButton.OK, MessageBoxImage.Asterisk); } else { if (MessageBox.Show("Are you sure want to remove this item", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { var uriExpense = _uriExpense + "/" + exp_rowlist.Id; var delExpTask = Task.Run(() => ApiCaller.Delete(uriExpense)); delExpTask.Wait(); //var expense = newExpTask.Result; // Expense Binding var expense = delExpTask.IsCompleted; if (expense) { _expList.RemoveAt(_expList.FindIndex(s => s.Id == exp_rowlist.Id)); LoadDataIntoControls(); } ClearValue(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}"); lblInfo.Text = ex.Message; } } } }
private void BtnNew_Click(object sender, RoutedEventArgs e) { var oExp = new Expense(); try { oExp.ExpenseTitle = txtExpTitle.Text.Trim(); oExp.ExpensesAmount = Convert.ToDouble(txtAmt.Text); oExp.ExpenseDate = Convert.ToDateTime(dtExp.Text); oExp.Signature = txtSing.Text; oExp.CategoryId = (int)cbCategory.SelectedValue; oExp.CurrencyId = (int)cbCurrency.SelectedValue; if (!string.IsNullOrEmpty(txtDetails.Text)) { oExp.ExpenseDetail = txtDetails.Text; } // Expense Binding var newExpTask = Task.Run(() => ApiCaller.Post <Expense>(_uriExpense, oExp)); newExpTask.Wait(); var expenseId = int.Parse(newExpTask.Result.ToString().Split('/').Last()); var expense = newExpTask.IsCompleted; if (expense) { oExp.Id = expenseId; _expList.Add(oExp); LoadDataIntoControls(); } ClearValue(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error: {ex.Message}"); lblInfo.Text = ex.Message; } }