public static async Task <bool> AddMovie(MediaFile mediaFile, Movie movie) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var content = new MultipartFormDataContent { { new StringContent(movie.Name), "Name" }, { new StringContent(movie.Description), "Description" }, { new StringContent(movie.Language), "Language" }, { new StringContent(movie.Duration), "Duration" }, { new StringContent(movie.PlayingDate), "PlayingDate" }, { new StringContent(movie.PlayingTime), "PlayingTime" }, { new StringContent(movie.TicketPrice.ToString()), "TicketPrice" }, { new StringContent(movie.Rating.ToString()), "Rating" }, { new StringContent(movie.Genre), "Genre" }, { new StringContent(movie.TrailorUrl), "TrailorUrl" }, }; content.Add(new StreamContent(new MemoryStream(movie.ImageArray)), "Image", mediaFile.Path); var response = await httpClient.PostAsync(AppSettings.ApiUrl + "api/movies", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <List <Movie> > GetAllMovies(int pageNumber, int pageSize) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + String.Format("api/movies/AllMovies?pageNumber={0}&pageSize={1}", pageNumber, pageSize)); return(JsonConvert.DeserializeObject <List <Movie> >(response)); }
public static async Task <MovieDetail> GetMovieDetail(int movieId) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/movies/MovieDetail/" + movieId); return(JsonConvert.DeserializeObject <MovieDetail>(response)); }
public static async Task <VehicleDetail> GetVehicleDetail(int id) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync($"http://cvehicle.azurewebsites.net/api/Vehicles/VehicleDetails?id={id}"); return(JsonConvert.DeserializeObject <VehicleDetail>(response)); }
public static async Task <List <ProductByCategory> > GetProductByCategory(int categoryId) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/Products/ProductsByCategory/" + categoryId); return(JsonConvert.DeserializeObject <List <ProductByCategory> >(response)); }
public static async Task <UserImageModel> GetUserProfileImage() { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync("http://cvehicle.azurewebsites.net/api/accounts/UserProfileImage"); return(JsonConvert.DeserializeObject <UserImageModel>(response)); }
public static async Task <List <MarqueeBanner> > GetMarqueeBanners() { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/MarqueeBanners"); return(JsonConvert.DeserializeObject <List <MarqueeBanner> >(response)); }
public static async Task <TotalCartItem> GetTotalCartItems(int userId) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/ShoppingCartItems/TotalItems/" + userId); return(JsonConvert.DeserializeObject <TotalCartItem>(response)); }
public static async Task <List <MasterData> > GetDetectDatas(Guid detectId) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync("https://weleaderapi.azurewebsites.net/api/MedicalDetect/p/r2/FFA95EB0-2B8A-47B1-AC10-BBEC1710D10D"); return(JsonConvert.DeserializeObject <List <MasterData> >(response)); }
public static async Task <List <MyAd> > GetMyAds() { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.GetStringAsync("https://cvehicles.azurewebsites.net/api/Vehicles/MyAds"); return(JsonConvert.DeserializeObject <List <MyAd> >(response)); }
public static async Task <OrderResponse> PlaceOrder(Order order) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); var json = JsonConvert.SerializeObject(order); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.PostAsync(AppSettings.ApiUrl + "api/Orders", content); var jsonResult = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <OrderResponse>(jsonResult)); }
public static async Task <bool> ClearShoppingCart(int userId) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.DeleteAsync(AppSettings.ApiUrl + "api/ShoppingCartItems/" + userId); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <VehicleResponse> AddVehicle(Vehicle vehicle) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); var json = JsonConvert.SerializeObject(vehicle); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.PostAsync("https://cvehicles.azurewebsites.net/api/Vehicles", content); var jsonResult = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <VehicleResponse>(jsonResult)); }
public static async Task <bool> EditPhoneNumber(string phoneNumber) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); var content = new StringContent($"Number={phoneNumber}", Encoding.UTF8, "application/x-www-form-urlencoded"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.PostAsync("https://cvehicles.azurewebsites.net/api/accounts/EditPhoneNumber", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <bool> AddItemsInCart(AddToCart addToCart) { await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); var json = JsonConvert.SerializeObject(addToCart); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.PostAsync(AppSettings.ApiUrl + "api/ShoppingCartItems", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <bool> EditUserProfile(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("accessToken", string.Empty)); var response = await httpClient.PostAsync("https://cvehicles.azurewebsites.net/api/accounts/EditUserProfile", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <bool> ChangePassword(string oldPassword, string newPassword, string confirmPassword) { var changePasswordModel = new ChangePasswordModel() { OldPassword = oldPassword, NewPassword = newPassword, ConfirmPassword = confirmPassword }; 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("accessToken", string.Empty)); var response = await httpClient.PostAsync("https://cvehicles.azurewebsites.net/api/accounts/ChangePassword", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }
public static async Task <bool> AddImage(int vehicleId, byte[] imageArray) { var vehicleImage = new VehicleImage() { VehicleId = vehicleId, ImageArray = imageArray }; await TokenValidator.CheckTokenValidity(); var httpClient = new HttpClient(); var json = JsonConvert.SerializeObject(vehicleImage); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty)); var response = await httpClient.PostAsync("http://cvehicle.azurewebsites.net/api/Images", content); if (!response.IsSuccessStatusCode) { return(false); } return(true); }