Example #1
0
        public async void editData(TextBox id_transaksi, TextBox alamat_pembeli, TextBox namaPembeli, TextBox totalHarga)
        {
            ApiClient client  = UtilProvider.getSession().getClient();
            var       request = new ApiRequestBuilder();

            MessageBox.Show(id.ToString());

            String URL = "transaction/" + id;

            var req = request
                      .buildHttpRequest()
                      .setEndpoint(URL)
                      .addParameters("price", totalHarga.Text)
                      .addParameters("amount", transaction.getAmount().ToString())
                      .setRequestMethod(HttpMethod.Put);

            client.setAuthorizationToken(UtilProvider.getSession().getUser().getData().getToken());
            var response = await client.sendRequest(request.getApiRequestBundle());

            Console.WriteLine(response.getHttpResponseMessage().ToString());

            if (response.getHttpResponseMessage().ReasonPhrase.Equals("Created"))
            {
                MessageBox.Show("Edited");
                UserCredential userCredential = response.getParsedObject <UserCredential>();
            }
            else
            {
                MessageBox.Show(response.getHttpResponseMessage().ReasonPhrase);
            }
        }
Example #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);
            }
        }
        public async void editSparepart(MyList <MyFile> files, ObjectSparepart sparepart, int sparepartId, String token)
        {
            var client  = new ApiClient(ApiConstant.BASE_URL);
            var request = new ApiRequestBuilder();

            var formContent = new MultipartFormDataContent();

            formContent.Add(new StringContent(sparepart.name), "name");
            formContent.Add(new StringContent(sparepart.price.ToString()), "price");
            formContent.Add(new StringContent(sparepart.stock.ToString()), "stock");
            formContent.Add(new StringContent("PUT"), "_method");
            if (files.Count > 0)
            {
                formContent.Add(new StreamContent(new MemoryStream(files[0].byteArray)), "picture", files[0].fullFileName);
            }

            var multiPartRequest = request
                                   .buildMultipartRequest(new MultiPartContent(formContent))
                                   .setEndpoint("api/sparepart/" + sparepartId)
                                   .setRequestMethod(HttpMethod.Post);

            client.setAuthorizationToken(token);
            client.setOnSuccessRequest(setStatus);
            var response = await client.sendRequest(request.getApiRequestBundle());

            if (response.getHttpResponseMessage().ReasonPhrase.ToString().Equals("Internal Server Error"))
            {
                getView().callMethod("setFailStatus", "Failed to edit spareparts");
            }
        }
        public async void getRevenue(String _status, String token)
        {
            var client  = new ApiClient(ApiConstant.BASE_URL);
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .addParameters("status", _status)
                      .setEndpoint("api/revenue/count")
                      .setRequestMethod(HttpMethod.Post);

            client.setAuthorizationToken(token);
            if (_status.Equals("paid"))
            {
                client.setOnSuccessRequest(setRevenue);
            }
            else if (_status.Equals("unpaid"))
            {
                client.setOnSuccessRequest(setUnpaidRevenue);
            }
            else if (_status.Equals("pending"))
            {
                client.setOnSuccessRequest(setPendingRevenue);
            }

            var response = await client.sendRequest(request.getApiRequestBundle());

            if (response.getHttpResponseMessage().ReasonPhrase.ToString().Equals("Internal Server Error"))
            {
                getView().callMethod("setFailStatus", "Failed to load statistics");
            }
        }
        public async void execute()
        {
            var    client  = new ApiClient.ApiClient("http://127.0.0.1:8000/");
            var    request = new ApiRequestBuilder();
            string token;

            var req = request
                      .buildHttpRequest()
                      .addParameters("email", "*****@*****.**")
                      .addParameters("password", "password")
                      .setEndpoint("api/login/")
                      .setRequestMethod(HttpMethod.Post);
            var response = await client.sendRequest(request.getApiRequestBundle());

            token = response.getJObject()["access_token"].ToString();

            client.setAuthorizationToken(token);
            MyList <MyFile> files   = new OpenFile().openFile(false);
            MyList <string> fileKey = new MyList <string>()
            {
                "file"
            };

            var formContent = new MultipartFormDataContent();

            formContent.Add(new StringContent("restapis.png"), "title");                                                 //parameters request, "value","key"
            formContent.Add(new StreamContent(new MemoryStream(files[0].byteArray)), fileKey[0], files[0].fullFileName); //file yang diupload

            req = new ApiRequestBuilder().buildMultipartRequest(new MultiPartContent(formContent))
                  .setRequestMethod(HttpMethod.Post)
                  .setEndpoint("api/store-file");
            response = await client.sendRequest(req.getApiRequestBundle());

            Console.WriteLine(response.getHttpResponseMessage().ToString());
        }
        public async void create(
            string _name,
            string _description,
            string _address,
            string _contact,
            String _latitude,
            String _longitude,
            String _id,
            string _token,
            MyFile newImage
            )
        {
            MyList <string> fileKey = new MyList <string>()
            {
                "image"
            };
            MyList <MyFile> file = new MyList <MyFile>()
            {
                newImage
            };

            this.token = _token;



            var client = new ApiClient("http://api.dolankuy.me/api/");

            var req = new ApiRequestBuilder()
                      .buildHttpRequest()
                      .addParameters("category_id", _id)
                      .addParameters("name", _name)
                      .addParameters("address", _address)
                      .addParameters("description", _description)
                      .addParameters("contact", _contact)
                      .addParameters("latitude", _latitude)
                      .addParameters("longitude", _longitude)
                      .setRequestMethod(HttpMethod.Post)
                      .setEndpoint("locations/create");

            client.setAuthorizationToken(_token);
            if (newImage == null)
            {
                client.setOnSuccessRequest(setViewRegisterStatus);
            }
            var response = await client.sendRequest(req.getApiRequestBundle());


            if (newImage != null)
            {
                MultiPartContent multiPartContent1 = new MultiPartContent(file, fileKey);
                var req2 = new ApiRequestBuilder()
                           .buildMultipartRequest(multiPartContent1)
                           .setRequestMethod(HttpMethod.Post)
                           .setEndpoint("locations/update/" + response.getJObject()["id"].ToString());
                client.setAuthorizationToken(_token);
                client.setOnSuccessRequest(setViewRegisterStatus);
                var response2 = await client.sendRequest(req2.getApiRequestBundle());
            }
        }
        public async void updateUser(int userId, string name, string email, string currentPassword,
                                     string newPassword, string currentImagePath,
                                     MyFile newImageFile)
        {
            string             newImagePath;
            JObject            userDataJson = new JObject();
            JObject            userJson     = new JObject();
            ApiClient          client       = ApiUtil.Instance.vClient;
            ApiRequestBuilder  requestBuilder;
            ApiRequestBundle   requestBundle;
            HttpResponseBundle response = null;

            getView().callMethod("startLoading");
            if (currentPassword != null && newPassword != null)
            {
                bool validatePasswordSuccess = await validatePassword(currentPassword);

                if (!validatePasswordSuccess)
                {
                    getView().callMethod("endLoading");
                    return;
                }
                userDataJson.Add("password", newPassword);
            }

            newImagePath = await postUserImage(newImageFile);

            userDataJson.Add("name", name);
            userDataJson.Add("email", email);
            userDataJson.Add("role", "owner");
            userDataJson.Add("image", newImagePath == null ? currentImagePath : newImagePath);
            userJson.Add("user", userDataJson);

            requestBuilder = new ApiRequestBuilder()
                             .buildHttpRequest()
                             .setRequestMethod(HttpMethod.Put)
                             .setEndpoint("users/" + userId.ToString())
                             .addJSON <JObject>(userJson);
            requestBundle = requestBuilder.getApiRequestBundle();

            client.setAuthorizationToken(StorageUtil.Instance.token);
            client.setOnSuccessRequest(onSuccessUpdateUser);
            client.setOnFailedRequest(onFailedUpdateUser);

            try
            {
                response = await client.sendRequest(requestBundle);

                if (response.getHttpResponseMessage().IsSuccessStatusCode)
                {
                    setUserInLocalStorage(userId);
                }
            }
            catch (Exception e)
            {
                getView().callMethod("endLoading");
                getView().callMethod("showErrorMessage", "Failed updating profile. " + e.Message);
            }
        }
        private async Task <bool> validatePassword(string currentPassword)
        {
            bool               passwordValid = false;
            string             currentEmail  = StorageUtil.Instance.user.email;
            ApiClient          client        = ApiUtil.Instance.vClient;
            JObject            userDataJson  = new JObject();
            JObject            userJson      = new JObject();
            ApiRequestBuilder  requestBuilder;
            ApiRequestBundle   requestBundle;
            HttpResponseBundle responseBundle = null;

            userDataJson.Add("email", currentEmail);
            userDataJson.Add("password", currentPassword);
            userJson.Add("user", userDataJson);

            requestBuilder = new ApiRequestBuilder()
                             .buildHttpRequest()
                             .setRequestMethod(HttpMethod.Post)
                             .addJSON <JObject>(userJson)
                             .setEndpoint("login");
            requestBundle = requestBuilder.getApiRequestBundle();
            client.setOnSuccessRequest(null);
            client.setOnFailedRequest(null);

            try
            {
                responseBundle = await client.sendRequest(requestBundle);
            }
            catch (Exception e)
            {
                getView().callMethod("showErrorMessage",
                                     "Failed to validate current password. " + e.Message);
            }

            if (responseBundle != null)
            {
                HttpResponseMessage responseMessage = responseBundle.getHttpResponseMessage();

                if (responseMessage.IsSuccessStatusCode)
                {
                    passwordValid = true;
                }
                else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
                {
                    getView().callMethod("showErrorMessage", "Current password is invalid.");
                }
                else
                {
                    string reasonPhrase = "Reason Phrase: " + responseMessage.ReasonPhrase;

                    getView().callMethod("showErrorMessage",
                                         "Failed to validate current password. " + reasonPhrase);
                }
            }

            return(passwordValid);
        }
        public async void LoadReservationPage(int currentPage)
        {
            var client  = new ApiClient(API.URL);
            var request = new ApiRequestBuilder();
            var req     = request
                          .buildHttpRequest()
                          .setEndpoint(API.reservationPage.Replace("{number}", currentPage.ToString()))
                          .setRequestMethod(HttpMethod.Get);

            client.setAuthorizationToken(File.ReadAllText("jwt.txt"));
            client.setOnSuccessRequest(CallbackSuccess);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void deleteProcess(HealthAgency healthAgency)
        {
            ApiClient client  = ApiAntrianSehat.getInstance().GetApiClient();
            var       request = new ApiRequestBuilder();

            var req = request.buildHttpRequest()
                      .setEndpoint("health-agency/" + healthAgency.id)
                      .setRequestMethod(HttpMethod.Delete);

            client.setOnSuccessRequest(setViewSuccessDelete);
            client.setOnFailedRequest(setViewErrorDelete);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #11
0
        public async void fetchDataHealthAgency()
        {
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("health-agency/all")
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setViewSuccessFetchHealthAgency);
            client.setOnFailedRequest(setViewErrorFetchHealthAgency);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #12
0
        public async void getLocation()
        {
            var client  = new ApiClient("http://api.dolankuy.me/");
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("api/acomodation")
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setItem);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void getCategory()
        {
            var client  = new ApiClient("http://127.0.0.1:8000/");
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("api/category")
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setItem);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void deleteProcess(PolyMaster polyMaster)
        {
            ApiClient client  = ApiAntrianSehat.getInstance().GetApiClient();
            var       request = new ApiRequestBuilder();

            var req = request.buildHttpRequest()
                      .setEndpoint("poly-master/" + polyMaster.id)
                      .setRequestMethod(HttpMethod.Delete);

            client.setOnSuccessRequest(setViewSuccessDelete);
            client.setOnFailedRequest(setViewErrorDelete);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void SearchReservation(string assetName)
        {
            var client  = new ApiClient(API.URL);
            var request = new ApiRequestBuilder();
            var req     = request
                          .buildHttpRequest()
                          .setEndpoint(API.reservationAsset.Replace("{name}", assetName))
                          .setRequestMethod(HttpMethod.Get);

            client.setAuthorizationToken(File.ReadAllText("jwt.txt"));
            client.setOnSuccessRequest(CallbackSuccess);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #16
0
        public async void updatePolyMaster(int id, String name)
        {
            var request = new ApiRequestBuilder();
            var req     = request.buildHttpRequest()
                          .addParameters("_method", "PUT")
                          .addParameters("name", name)
                          .setEndpoint("poly-master/" + id.ToString())
                          .setRequestMethod(HttpMethod.Post);

            client.setOnSuccessRequest(setSuccessStorePolyMaster);
            client.setOnFailedRequest(setErrorStorePolyMaster);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void fetchDataPolyMaster()
        {
            client = ApiAntrianSehat.getInstance().GetApiClient();
            var request = new ApiRequestBuilder();

            var req = request.buildHttpRequest()
                      .setEndpoint("poly-master/")
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setViewSuccessFetch);
            client.setOnFailedRequest(setViewFailedFetch);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void fetchDataUser()
        {
            ApiClient client  = ApiAntrianSehat.getInstance().GetApiClient();
            var       request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("user/role-admin")
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setViewSuccessFetch);
            client.setOnFailedRequest(setViewErrorFetch);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #19
0
        /*
         * //revisi backend
         * public async void getCategory()
         * {
         *  var client = new ApiClient("http://127.0.0.1:8000/");
         *  var request = new ApiRequestBuilder();
         *
         *  var req = request
         *      .buildHttpRequest()
         *      .setEndpoint("api/category")
         *      .setRequestMethod(HttpMethod.Get);
         *  client.setOnSuccessRequest(setItem);
         *  var response = await client.sendRequest(request.getApiRequestBundle());
         * }*/

        //Update
        public async void putCategory(String _categoryName, int _categoryId)
        {
            var client  = new ApiClient("http://127.0.0.1:8000/");
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .addParameters("name", _categoryName)
                      .setEndpoint("api/category/update/" + _categoryId)
                      .setRequestMethod(HttpMethod.Put);

            client.setOnSuccessRequest(setItem);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #20
0
        public async void logout()
        {
            var client  = ApiUtil.Instance.vClient;
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("/logout?Authorization=Bearer" + token)
                      .setRequestMethod(HttpMethod.Get);

            client.setAuthorizationToken(token);
            client.setOnSuccessRequest(navigateViewLogout);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #21
0
        public async void deleteAkomodasi(String id, String token)
        {
            var client  = new ApiClient("http://api.dolankuy.me/");
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("api/locations/delete/" + id)
                      .setRequestMethod(HttpMethod.Delete);

            client.setAuthorizationToken(token);
            client.setOnSuccessRequest(onDelete);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void fetchDataPolyclinic()
        {
            ApiClient client  = ApiAntrianSehat.getInstance().GetApiClient();
            var       request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("schedule/of-ha/" + Application.Current.Resources["ha_id"])
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setViewSuccessFetch);
            client.setOnFailedRequest(setViewErrorFetch);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void fetchHAData(int idHA)
        {
            client = ApiAntrianSehat.getInstance().GetApiClient();
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("health-agency/" + idHA.ToString())
                      .setRequestMethod(HttpMethod.Get);

            client.setOnSuccessRequest(setViewSuccessFetchHA);
            client.setOnFailedRequest(setViewErrorFetchHA);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void generateData(DataGrid data_grid_transaction)
        {
            if (UtilProvider.getDataTransaction() != null)
            {
                List <DataTransaction> data        = UtilProvider.getDataTransaction().getData();
                List <HistoryData>     dataHistory = new List <HistoryData>();

                for (int i = 0; i < data.Count(); i++)
                {
                    String   po_number = data.ElementAt(i).getPoNumber();
                    DateTime date      = data.ElementAt(i).getCreatedAt();
                    Double   amount    = data.ElementAt(i).getAmount().GetValueOrDefault();

                    ApiClient client  = UtilProvider.getSession().getClient();
                    var       request = new ApiRequestBuilder();

                    String URL = "user/id/" + data.ElementAt(i).getCustomerId().ToString();

                    var req = request
                              .buildHttpRequest()
                              .setEndpoint(URL)
                              .setRequestMethod(HttpMethod.Get);
                    client.setAuthorizationToken(UtilProvider.getSession().getUser().getData().getToken());
                    var response = await client.sendRequest(request.getApiRequestBundle());

                    String name;
                    String phone;

                    if (response.getHttpResponseMessage().ReasonPhrase.Equals("OK"))
                    {
                        UserCredential userCredential = response.getParsedObject <UserCredential>();
                        name  = userCredential.getData().getFullName();
                        phone = userCredential.getData().getPhone();
                    }
                    else
                    {
                        //MessageBox.Show(response.getHttpResponseMessage().ReasonPhrase);
                        phone = name = "unknown";
                    }

                    dataHistory.Add(new HistoryData(po_number, date, name, phone, amount));
                }

                data_grid_transaction.ItemsSource = dataHistory;
            }
            else
            {
                MessageBox.Show("Your Outlet never Have any Transaction History");
            }
        }
Example #25
0
        public async void OnLogout()
        {
            ApiClient client  = UtilProvider.getSession().getClient();
            var       request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("logout")
                      .setRequestMethod(HttpMethod.Get);

            client.setAuthorizationToken(UtilProvider.getSession().getUser().getData().getToken());

            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void showSparepart(int sparepartId, String token)
        {
            var client  = new ApiClient(ApiConstant.BASE_URL);
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("api/sparepart/" + sparepartId + "/")
                      .setRequestMethod(HttpMethod.Get);

            client.setAuthorizationToken(token);
            client.setOnSuccessRequest(setSparepart);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
        public async void postCategory(string _name)
        {
            var client  = new ApiClient("http://127.0.0.1:8000/");
            var request = new ApiRequestBuilder();

            //string token = "";
            var req = request
                      .buildHttpRequest()
                      .addParameters("name", _name)
                      .setEndpoint("api/category/create")
                      .setRequestMethod(HttpMethod.Post);

            client.setOnSuccessRequest(setViewCategoryStatus);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #28
0
        public async void logout(string _token)
        {
            var client  = new ApiClient("http://api.dolankuy.me/");
            var request = new ApiRequestBuilder();

            this.token = _token;
            var req = request
                      .buildHttpRequest()
                      .setEndpoint("api/logout")
                      .setRequestMethod(HttpMethod.Post);

            client.setAuthorizationToken(_token);
            client.setOnSuccessRequest(setViewStatus);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }
Example #29
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");
            }
        }
Example #30
0
        public async void getUser(String filter)
        {
            var client  = ApiUtil.Instance.vClient;
            var request = new ApiRequestBuilder();

            var req = request
                      .buildHttpRequest()
                      .setEndpoint("/users" + filter)
                      .setRequestMethod(HttpMethod.Get);
            String token = StorageUtil.Instance.token;

            //Console.WriteLine(req.getApiRequestBundle().ToString());
            client.setAuthorizationToken(token);
            client.setOnSuccessRequest(setUser);
            var response = await client.sendRequest(request.getApiRequestBundle());
        }