Ejemplo n.º 1
0
        public static async Task <int> GetRatingByListingAndUser(int listingId, int userId)
        {
            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}/Rating/GetRatingByListingAndUser/{listingId}/{userId}");

            return(JsonConvert.DeserializeObject <int>(response));
        }
Ejemplo n.º 2
0
        //        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<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 <List <Model.Listing> > GetListings()
        {
            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}/Listings/GetListings");

            return(JsonConvert.DeserializeObject <List <Model.Listing> >(response));
        }
Ejemplo n.º 3
0
        public static async Task <bool> IsOnWishlist(int listingId)
        {
            await TokenValidator.CheckTokenValidity();

            int wishlistId = Preferences.Get("wishlistId", 0);
            var httpClient = new HttpClient();

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

            return(JsonConvert.DeserializeObject <bool>(response));
        }
Ejemplo n.º 4
0
        public static async Task <User> GetUserDetails()
        {
            await TokenValidator.CheckTokenValidity();

            var userId = Preferences.Get("userId", 0);

            var httpClient = new HttpClient();

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

            return(JsonConvert.DeserializeObject <User>(response));
        }
Ejemplo n.º 5
0
        public static async Task <bool> UpdateListing(int listingId, Model.Requests.ListingUpdateRequest request)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(request);
            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.PutAsync($"{_apiUrl}/Listing/{listingId}", content);

            return(true);
        }
Ejemplo n.º 6
0
        public static async Task <ListingResponse> InsertListing(Model.Requests.ListingInsertRequest request)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(request);
            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}/Listing", content);

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

            return(JsonConvert.DeserializeObject <ListingResponse>(jsonResult));
        }
Ejemplo n.º 7
0
        public static async Task <bool> RemoveWishlistListing(int listingId)
        {
            await TokenValidator.CheckTokenValidity();

            var wishlistId = Preferences.Get("wishlistId", 0);
            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("access_token", string.Empty));
            var response = await httpClient.DeleteAsync($"{_apiUrl}/Wishlist/{wishlistId }/{listingId}");

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        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}/User/ChangeProfilePicture", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 9
0
        public static async Task <Rating> SetRating(int listingId, int ratingValue)
        {
            var rating = new Model.Rating
            {
                ListingId   = listingId,
                UserId      = Preferences.Get("userId", 0),
                RatingValue = ratingValue
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(rating);
            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}/Rating", content).Result.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <Rating>(response));
        }
Ejemplo n.º 10
0
        public static async Task <Model.WishlistListing> SaveWishlistListing(int listingId)
        {
            await TokenValidator.CheckTokenValidity();

            var wishlistInsertRequest = new WishlistListingInsertRequest
            {
                ListingId  = listingId,
                WishlistId = Preferences.Get("wishlistId", 0),
                DateAdded  = DateTime.Now
            };

            var httpClient = new HttpClient();

            var json     = JsonConvert.SerializeObject(wishlistInsertRequest);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await httpClient.PostAsync($"{_apiUrl}/Wishlist", content);

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

            return(JsonConvert.DeserializeObject <Model.WishlistListing>(jsonResult));
        }
Ejemplo n.º 11
0
        public static async Task <bool> AddListingImage(int listingId, byte[] imageArray)
        {
            var listingImage = new ListingImageModel
            {
                ListingId = listingId,
                Image     = imageArray
            };

            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(listingImage);
            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}/ListingImage", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        public static async Task <bool> ChangePassword(string oldPassword, string newPassword, string passwordConfirmation)
        {
            var changePasswordModel = new Model.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}/User/ChangePassword", content);

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