//method yg dijalankan saat request success harus memiliki parameter bertipe HttpResponseBundle private void setViewSuccessLogin(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { Application.Current.Resources["email"] = _response.getJObject()["user"]["email"]; Application.Current.Resources["ha_id"] = _response.getJObject()["user"]["health_agency_id"]; String role = _response.getJObject()["user"]["role"].ToString(); String saveStr = _response.getJObject()["user"]["email"] + "," + _response.getJObject()["access_token"].ToString() + "," + _response.getJObject()["user"]["role"] + "," + _response.getJObject()["user"]["health_agency_id"]; TextOperation.writeToFile("../../assets/user.txt", saveStr); client.setAuthorizationToken(_response.getJObject()["access_token"].ToString()); string status = _response.getHttpResponseMessage().ReasonPhrase; if (role == "Admin" || role == "Super Admin") { getView().callMethod("setLoginSuccess", status, role); } else { getView().callMethod("restrictNoAuthentication", status); } } }
public async void deleteStaff(int staffId) { ApiClient client = ApiUtil.Instance.vClient; ApiRequestBuilder requestBuilder = new ApiRequestBuilder() .buildHttpRequest() .setRequestMethod(HttpMethod.Delete) .setEndpoint("users/" + staffId.ToString()); ApiRequestBundle requestBundle = requestBuilder.getApiRequestBundle(); HttpResponseBundle response = null; getView().callMethod("startLoading"); client.setAuthorizationToken(StorageUtil.Instance.token); client.setOnSuccessRequest(onSuccessDeleteStaff); client.setOnFailedRequest(onFailedDeleteStaff); try { response = await client.sendRequest(requestBundle); if (response.getHttpResponseMessage().Content != null) { Trace.WriteLine("deleteStaff Response: \n" + await response.getHttpResponseMessage().Content.ReadAsStringAsync()); } } catch (Exception e) { getView().callMethod("endLoading"); getView().callMethod("showErrorMessage", "Failed to delete staff. " + e.Message); } }
private async void setAddUserStatus(HttpResponseBundle _response) { getView().callMethod("endLoading"); if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; string response = await _response.getHttpResponseMessage().Content.ReadAsStringAsync(); getView().callMethod("setAddUserStatus", status); Trace.WriteLine(response); if (_response.getHttpResponseMessage().IsSuccessStatusCode) { JObject userDataJson = null; if (_response.getJObject() != null) { userDataJson = (JObject)_response.getJObject()["data"]; } if (userDataJson != null) { int staffId = (int)userDataJson["id"]; getView().callMethod("navigateToStaffPage", staffId); } } } }
private void onDelete(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("setDelete", _response.getHttpResponseMessage().ToString()); } }
private void setStatus(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setStatus", _response.getJObject()["message"].ToString()); } }
private void setSparepart(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setItem", _response.getParsedObject <ItemSparepart>().spareparts); } }
private void setViewStatus(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setEditStatus", this.token); } }
private void setPendingRevenue(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setPendingRevenue", _response.getParsedObject <RevenueCount>().count); } }
private void setViewRegisterStatus(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setRegisterStatus", status); } }
private void viewShowListMahasiswa(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("showListMahasiswa", _response.getParsedObject <APIResponse <List <DepartmentSummaryModel> > >().Data); } }
public void ViewShowListStudent(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("ShowListStudent", _response.getParsedObject <APIResponse <List <DepartmentSummaryModel> > >().Data); } }
private void setUser(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setUser", _response.getParsedObject <ItemUser>().user); } }
private void setItem(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setBooking", _response.getParsedObject <Bookings>().booking); } }
private void setBookingsCanceled(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { string status = _response.getHttpResponseMessage().ReasonPhrase; getView().callMethod("setCanceled", _response.getParsedObject <BookingCount>().count); } }
public void navigateViewLogout(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { String status = _response.getHttpResponseMessage().ReasonPhrase; StorageUtil.Instance.user = null; StorageUtil.Instance.company = null; StorageUtil.Instance.token = null; getView().callMethod("navigateToLogin"); } }
private void onFailedDeleteStaff(HttpResponseBundle _response) { string reasonPhrase = ""; if (_response.getHttpResponseMessage().Content != null) { reasonPhrase = "Reason Phrase: " + _response.getHttpResponseMessage().ReasonPhrase; } getView().callMethod("endLoading"); getView().callMethod("showErrorMessage", "Failed to delete staff. " + reasonPhrase); }
private void onSuccessUpdateStaff(HttpResponseBundle _response) { string reasonPhrase = ""; if (_response.getHttpResponseMessage().Content != null) { reasonPhrase = "Reason Phrase: " + _response.getHttpResponseMessage().ReasonPhrase; } getView().callMethod("endLoading"); getView().callMethod("showSuccessMessage", "Staff updated successfully. " + reasonPhrase); }
private void onFailedGetStaff(HttpResponseBundle _response) { string reasonPhrase = ""; if (_response.getHttpResponseMessage().Content != null) { reasonPhrase = "Reason Phrase: " + _response.getHttpResponseMessage().ReasonPhrase; } getView().callMethod("endLoading"); getView().callMethod("showErrorMessage", "Error initializing staff data. " + reasonPhrase); getView().callMethod("navigateToStaffListPage"); }
public async void updateStaff(int staffId, string name, string email, string role, string image) { JObject userValue = new JObject(); JObject user = new JObject(); ApiClient client = ApiUtil.Instance.vClient; ApiRequestBuilder requestBuilder; ApiRequestBundle requestBundle; HttpResponseBundle response = null; getView().callMethod("startLoading"); userValue.Add("name", name); userValue.Add("email", email); userValue.Add("role", role); userValue.Add("image", image); user.Add("user", userValue); requestBuilder = new ApiRequestBuilder() .buildHttpRequest() .setRequestMethod(HttpMethod.Put) .setEndpoint("users/" + staffId.ToString()) .addJSON <JObject>(user); requestBundle = requestBuilder.getApiRequestBundle(); client.setAuthorizationToken(StorageUtil.Instance.token); client.setOnSuccessRequest(onSuccessUpdateStaff); client.setOnFailedRequest(onFailedUpdateStaff); try { response = await client.sendRequest(requestBundle); if (response.getHttpResponseMessage().IsSuccessStatusCode&& response.getHttpResponseMessage().Content != null) { Trace.WriteLine("updateStaff Response : \n" + await response.getHttpResponseMessage().Content.ReadAsStringAsync()); getStaff(staffId); } } catch (Exception e) { getView().callMethod("endLoading"); getView().callMethod("showErrorMessage", "Failed updating staff. " + e.Message); getView().callMethod("changeToShowStaffPage"); } }
private void setViewSuccessFetchPolyMaster(HttpResponseBundle _response) { Console.WriteLine("success: " + _response.getHttpResponseMessage() .Content.ReadAsStringAsync().Result); //PolyMaster polyMaster = _response.getParsedObject<RootSinglePolyMaster>().data; //getView().callMethod("setPolyMasterData", polyMaster); }
private void setItem(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("setLocation", _response.getParsedObject <RootAkomodasi>().acomodation); } }
private void viewShowListSubjectofDepartment(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("showListSubjectofDepartment", _response.getParsedObject <APIResponse <List <SubjectModel> > >().Data); } }
private void setPickup(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("setPickup", _response.getParsedObject <Pickups>().pickups); } }
private void setItem(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("setCategory", _response.getParsedObject <RootCategory>().category); } }
private void setUserToken(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("saveToken", _response.getJObject()["token"].ToString()); } }
private void setErrorStorePolyMaster(HttpResponseBundle _response) { string message = _response.getHttpResponseMessage().Content.ReadAsStringAsync().Result; Console.WriteLine("error: " + _response.getJObject()); getView().callMethod("setErrorStore", message); }
private void viewListMahasiswaController(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("showListMahasiswa", _response.getParsedObject <APIResponse <List <StudentModel> > >().Data); } }
private void setItem(HttpResponseBundle _response) { if (_response.getHttpResponseMessage().Content != null) { getView().callMethod("setService", _response.getParsedObject <Services>().services); } }
private void onSuccessGetStaff(HttpResponseBundle _response) { getView().callMethod("endLoading"); if (_response.getHttpResponseMessage().Content != null) { JObject responseJSON = _response.getJObject(); JObject userDataJSON = (JObject)responseJSON["data"]; User staff = new User() { id = (int)userDataJSON["id"], company_id = (int)userDataJSON["company_id"], name = (string)userDataJSON["name"], email = (string)userDataJSON["email"], image = (string)userDataJSON["image"], role = (string)userDataJSON["role"] }; getView().callMethod("initStaff", staff); getView().callMethod("changeToShowStaffPage"); } else { getView().callMethod("showErrorMessage", "Error initializing staff data."); getView().callMethod("navigateToStaffListPage"); } }
private async void setUserInLocalStorage(int userId) { HttpResponseBundle response = await getUser(userId); if (response != null && response.getHttpResponseMessage().IsSuccessStatusCode) { JObject userDataJson = (JObject)response.getJObject()["data"]; StorageUtil.Instance.user = new User() { id = (int)userDataJson["id"], company_id = (int)userDataJson["company_id"], name = (string)userDataJson["name"], email = (string)userDataJson["email"], role = (string)userDataJson["role"], image = (string)userDataJson["image"] }; } else { getView().callMethod("showErrorMessage", "Failed getting updated user data."); } getView().callMethod("navigateToProfilePage"); }