public async Task <bool> Post(CalculationModel data) { bool success = false; var uri = new Uri("http://104.199.155.15/api/v2/db/_table/calculationHistory?api_key=be8387a7b036ea65deb04d1a20d85e619b7e1634aa55b1cf6cc3988f130a2e81&session_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIsInVzZXJfaWQiOjIsImVtYWlsIjoicHVibGljQHB1YmxpYy5jb20iLCJmb3JldmVyIjp0cnVlLCJpc3MiOiJodHRwOlwvXC8xMDQuMTk5LjE1NS4xNVwvYXBpXC92MlwvdXNlclwvc2Vzc2lvbiIsImlhdCI6MTQ3MDM4MzczMCwiZXhwIjoxNTAxOTE5NzMwLCJuYmYiOjE0NzAzODM3MzAsImp0aSI6ImFlZWQ3YWRhYmI4N2I0ODBhNmIyYWRlYWM0YzQzZTU0In0.J35hKt384v25G3ylb547w0OAlJ4yYGWRxhknwm5sYhg"); var json = "{ \"resource\": [{\"datenow\": \"" + data.datenow + "\", \"datesave\":\"" + data.datesave + "\", \"expense\":\"" + data.expense + "\", \"money\":\"" + data.money + "\", \"saveMoney\":\"" + data.saveMoney + "\", \"username\":\"" + data.username + "\"} ] }"; //var json = "{ \"resource\": [{\"username\": \"kemalanjing\", \"password\":\"totski\", \"email\":\"[email protected]\"} ] }"; var client = new HttpClient(); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { success = true; } return(success); }
async void OnSubmitButtonClicked(object sender, EventArgs e) { try { if (entryCashToSave.Text == "") { entryCashToSave.Text = "0"; } if (entryExpense.Text == "") { entryExpense.Text = "0"; } if (entryAvailableCash.Text == "") { entryAvailableCash.Text = "0"; } var duit = new CalculationModel { saveMoney = double.Parse(entryCashToSave.Text), money = double.Parse(entryAvailableCash.Text), datesave = datePicker.Date, datenow = DateTime.Now, expense = double.Parse(entryExpense.Text), username = App.Username }; if (duit.money < duit.saveMoney) { await DisplayAlert("Alert", "The ammount of cash to be saved cannot be more than available cash", "OK"); } var toCalculate = new Result(duit); bool success = await new CalculationService().Post(duit); await Navigation.PushAsync(toCalculate); }catch (ArgumentNullException) { await DisplayAlert("Alert", "One or more entry is INVALID", "OK"); } }
public Result(CalculationModel data) { var day = (data.datesave - data.datenow.AddDays(-1)).Days; InitializeComponent(); var labelDays = new Label { Text = "Days until Next Salary", TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var days = new Label { Text = day.ToString(), TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var labelSpent = new Label { Text = "Daily Spend", TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var spent = new Label { Text = ((data.money - data.saveMoney - data.expense) / day).ToString(), TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var labelSave = new Label { Text = "You Save", TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var save = new Label { Text = data.saveMoney.ToString(), TextColor = Color.FromHex("#85817E"), FontSize = 20 }; var doneButton = new Button { Text = "DONE", TextColor = Color.FromHex("#FFFFFF"), FontSize = 30, WidthRequest = 300, HeightRequest = 70, Margin = new Thickness(0, 20, 0, 0), BackgroundColor = Color.FromHex("#3FA9F5") }; doneButton.Clicked += toMenu; content.Children.Add(labelDays); content.Children.Add(days); content.Children.Add(labelSpent); content.Children.Add(spent); content.Children.Add(labelSave); content.Children.Add(save); content.Children.Add(doneButton); }