Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. private void smth()
  2. {
  3. using (MoviesDBEntities context = new MoviesDBEntities())
  4. {
  5. Movie movie = new Movie
  6. {
  7. Title = "hlen",
  8. Descr = "HUI",
  9. Rating = 5,
  10. Stars = "Ya",
  11. Director = "Pidoras s gori"
  12. };
  13. context.Movies.Add(movie);
  14. context.SaveChanges();
  15. }
  16. }
  17.  
  18. private void AddEntity()
  19. {
  20.  
  21. string apiKey = "e5df3688";
  22. string baseUrl = $"http://www.omdbapi.com/?apikey={apiKey}";
  23.  
  24. string name = Title.Text.ToLower();
  25.  
  26. var sb = new StringBuilder(baseUrl);
  27. sb.Append($"&t={name}");
  28. var request = WebRequest.Create(sb.ToString());
  29. request.Timeout = 1000;
  30. request.Method = "GET";
  31. request.ContentType = "application/json";
  32.  
  33. string result = string.Empty;
  34.  
  35. try
  36. {
  37. using (var response = request.GetResponse())
  38. {
  39. using (var stream = response.GetResponseStream())
  40. {
  41. using (var reader = new StreamReader(stream, Encoding.UTF8))
  42. {
  43. result = reader.ReadToEnd();
  44. }
  45. }
  46. }
  47. }
  48. catch (WebException e)
  49. {
  50. MessageBox.Show(e.ToString());
  51. }
  52. catch (Exception e)
  53. {
  54. MessageBox.Show(e.ToString());
  55. }
  56.  
  57. MessageBox.Show(result);
  58.  
  59. dynamic json = JObject.Parse(result);
  60. string title = json.Plot;
  61.  
  62. var option = MessageBox.Show(title, "Add this title to library", MessageBoxButton.YesNo);
  63.  
  64. if (option == MessageBoxResult.Yes)
  65. {
  66.  
  67. }
  68. }
  69.  
  70. private void Button_Click(object sender, RoutedEventArgs e)
  71. {
  72. smth();
  73. AddEntity();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement