public static string DeleteSavedMovie(int id, int peopleId, int movieId) { Wishlist deletedMovie = new Wishlist(); deletedMovie.Id = id; deletedMovie.Pid = peopleId; deletedMovie.Mid = movieId; string json = JsonConvert.SerializeObject(deletedMovie); // MessageBox.Show($"{json}"); // System.Diagnostics.Debug.WriteLine($"**************** --- {json}"); HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{ApiRoot.Apiroot()}/wishlist/{id}"); req.Method = "DELETE"; req.ContentType = "application/json"; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); }; var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { return(streamReader.ReadToEnd()); } }
public static string AddMovies(string title, string summary, string picture, string genre, double rating) { Movies movie = new Movies(); movie.Title = title; movie.Summary = summary; movie.Picture = picture; movie.Genre = genre; movie.Rating = rating; string json = JsonConvert.SerializeObject(movie); HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{ApiRoot.Apiroot()}/movies"); req.Method = "POST"; req.ContentType = "application/json"; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); }; var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { return(streamReader.ReadToEnd()); } }
public static string AddUsers(string fName, string lName, string password, string email, string uName) { Users user = new Users(); user.Fname = fName; user.Lname = lName; user.Passwrd = password; user.Email = email; user.Uname = uName; string json = JsonConvert.SerializeObject(user); HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{ApiRoot.Apiroot()}/users"); req.Method = "POST"; req.ContentType = "application/json"; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); }; var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { return(streamReader.ReadToEnd()); } }
public static List <Wishlist> RetrieveSavedMoviesFromApi() { using (WebClient wc = new WebClient()) { string json = wc.DownloadString($"{ApiRoot.Apiroot()}/wishlist"); List <Wishlist> wishlist = JsonConvert.DeserializeObject <List <Wishlist> >(json); return(wishlist); } }
public static List <Users> RetrieveUsersFromApi() { using (WebClient wc = new WebClient()) { string json = wc.DownloadString($"{ApiRoot.Apiroot()}/users"); List <Users> users = JsonConvert.DeserializeObject <List <Users> >(json); return(users); } }
public static List <Movies> RetrieveMoviesFromApi() { using (WebClient wc = new WebClient()) { string json = wc.DownloadString($"{ApiRoot.Apiroot()}/movies"); List <Movies> movies = JsonConvert.DeserializeObject <List <Movies> >(json); return(movies); } }
public static string UpdateUsers(int id, string fName, string lName, string password, string email, string uName) { Users user = new Users(); user.Id = id; user.Fname = fName; user.Lname = lName; user.Passwrd = password; user.Email = email; user.Uname = uName; string json = JsonConvert.SerializeObject(user); //MessageBox.Show($"{json}"); //System.Diagnostics.Debug.WriteLine($"**************** --- {json}"); HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{ApiRoot.Apiroot()}/users/{id}"); req.Method = "PUT"; req.ContentType = "application/json"; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); }; var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { return(streamReader.ReadToEnd()); } }