public static async Task <List <Modeli.MojOglas> > GetMojeOglase()
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Vozila/MojiOglasi");

            return(JsonConvert.DeserializeObject <List <Modeli.MojOglas> >(response));
        }
        public static async Task <VoziloDetalji> GetDetaljiVozila(int id)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Vozila/{id}");

            return(JsonConvert.DeserializeObject <VoziloDetalji>(response));
        }
        public static async Task <List <SlikaVozilaModel> > GetSlikeVozila(int voziloId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/SlikeVozila/GetByVozilo/{voziloId}");

            return(JsonConvert.DeserializeObject <List <SlikaVozilaModel> >(response));
        }
        public static async Task <List <Modeli.Grad> > GetGradovePoDrzavi(int drzavaId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Gradovi/GetByDrzava/{drzavaId}");

            return(JsonConvert.DeserializeObject <List <Modeli.Grad> >(response));
        }
        public static async Task <ProfilePictureModel> GetProfilePicture()
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Korisnici/GetProfilePicture");

            return(JsonConvert.DeserializeObject <ProfilePictureModel>(response));
        }
        public static async Task <string> GetPhoneNumber()
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Korisnici/GetPhoneNumber");

            return(response);
        }
        public static async Task <int> GetOcjenaByVoziloAndKorisnik(int voziloId, int korisnikId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.GetStringAsync($"{_apiUrl}/Ocjene/GetOcjenaByVoziloAndKorisnik/{voziloId}/{korisnikId}");

            return(JsonConvert.DeserializeObject <int>(response));
        }
        public static async Task <VoziloResponse> DodajVozilo(Modeli.Vozilo vozilo)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(vozilo);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/Vozila", content);

            var jsonResult = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <VoziloResponse>(jsonResult));
        }
        public static async Task <bool> ChangePhoneNumber(string phoneNumber)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var content    = new StringContent($"PhoneNumber={phoneNumber}", Encoding.UTF8, "application/x-www-form-urlencoded");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/Korisnici/ChangePhoneNumber", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
        public static async Task <bool> ChangeProfilePicture(byte[] imageArray)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(imageArray);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/Korisnici/ChangeProfilePicture", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
        public static async Task <List <VoziloSearch> > PretragaVozila(string search)
        {
            await TokenValidator.CheckTokenValidity();

            if (!string.IsNullOrWhiteSpace(search))
            {
                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
                var response = await httpClient.GetStringAsync($"{_apiUrl}/Vozila/Pretraga/{search}");

                return(JsonConvert.DeserializeObject <List <VoziloSearch> >(response));
            }
            return(new List <VoziloSearch> {
                new VoziloSearch {
                    VoziloId = -1
                }
            });
        }
        public static async Task <OcjenaModel> SetOcjena(int voziloId, int ocjena)
        {
            var ocjenaModel = new Modeli.OcjenaModel
            {
                VoziloId   = voziloId,
                KorisnikId = Preferences.Get("korisnikId", 0),
                DataOcjena = ocjena
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(ocjenaModel);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/Ocjene", content).Result.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <OcjenaModel>(response));
        }
        public static async Task <bool> DodajSlikuVozila(int voziloId, byte[] imageArray)
        {
            var voziloSlika = new SlikaVozilaModel
            {
                VoziloId = voziloId,
                Slika    = imageArray
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(voziloSlika);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/SlikeVozila", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
        public static async Task <bool> ChangePassword(string oldPassword, string newPassword, string passwordConfirmation)
        {
            var changePasswordModel = new Modeli.ChangePasswordModel
            {
                OldPassword          = oldPassword,
                NewPassword          = newPassword,
                PasswordConfirmation = passwordConfirmation
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(changePasswordModel);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.PostAsync($"{_apiUrl}/Korisnici/ChangePassword", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }