Esempio n. 1
0
        //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);
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
                    }
                }
            }
        }
Esempio n. 4
0
 private void onDelete(HttpResponseBundle _response)
 {
     if (_response.getHttpResponseMessage().Content != null)
     {
         getView().callMethod("setDelete", _response.getHttpResponseMessage().ToString());
     }
 }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 10
0
 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);
     }
 }
Esempio n. 12
0
 private void setUser(HttpResponseBundle _response)
 {
     if (_response.getHttpResponseMessage().Content != null)
     {
         string status = _response.getHttpResponseMessage().ReasonPhrase;
         getView().callMethod("setUser", _response.getParsedObject <ItemUser>().user);
     }
 }
Esempio n. 13
0
 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);
     }
 }
Esempio n. 15
0
 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");
     }
 }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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");
        }
Esempio n. 19
0
        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");
            }
        }
Esempio n. 20
0
 private void setViewSuccessFetchPolyMaster(HttpResponseBundle _response)
 {
     Console.WriteLine("success: " + _response.getHttpResponseMessage()
                       .Content.ReadAsStringAsync().Result);
     //PolyMaster polyMaster = _response.getParsedObject<RootSinglePolyMaster>().data;
     //getView().callMethod("setPolyMasterData", polyMaster);
 }
Esempio n. 21
0
 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);
     }
 }
Esempio n. 23
0
 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);
     }
 }
Esempio n. 25
0
 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);
        }
Esempio n. 27
0
 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);
     }
 }
Esempio n. 29
0
        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");
        }