private async Task AddNecessaryPersonsAsync(List <Person> persons) { foreach (var person in persons) { var personEntity = await context.MoviePersons.FirstOrDefaultAsync(x => x.FullName == person.Name); if (personEntity == null) { var entity = mapper.Map <Person, MoviePerson>(person); if (person.Place_of_birth != null) { entity.CountryId = context.Countries.First(x => x.Name == ParseCountryName(person.Place_of_birth)).Id; } var gender = context.Genders.FirstOrDefault(x => x.Id == person.Gender); if (gender != null) { entity.GenderId = gender.Id; } await context.MoviePersons.AddAsync(entity); context.SaveChanges(); } } }
//RATE MOVIE public bool RateMovie(int userid, int thisRating, string titleid) { using var ctx = new ImdbContext(); var query = ctx.rating.Where(x => x.User_Id == userid && x.Title_Id == titleid).ToList(); //if rating is between 1 and 10... in the gui have drop down. if (thisRating >= 1 && thisRating <= 10) { //if haven't been rated before by user then set new rating if (query.Count == 0) { //Add to users rating list ctx.rating .Add(new Rating { User_Id = userid, Title_Id = titleid, Rating_ = thisRating }); //if this movie haven't been voted before, add to DB if (ctx.title_rating.FirstOrDefault(x => x.Title_Id == titleid) == null) { ctx.title_rating.Add(new Title_Rating { Title_Id = titleid }); } var thisMovie = ctx.title_rating.FirstOrDefault(x => x.Title_Id == titleid); var thisMovieVotes = thisMovie.Num_Votes; var thisMovieRating = thisMovie.Average_Rating; var calcNewRating = (thisMovieVotes * thisMovieRating + thisRating) / (thisMovieVotes + 1); ctx.title_rating.Update(thisMovie).Entity.Average_Rating = calcNewRating; ctx.title_rating.Update(thisMovie).Entity.Num_Votes = (thisMovieVotes + 1); ctx.SaveChanges(); return(true); } //If user HAS ALREADY voted on this movie before. else { //Update users rating list var updateRatingList = ctx.rating.FirstOrDefault(x => x.Title_Id == titleid && x.User_Id == userid); var prevRating = updateRatingList.Rating_; var thisMovie = ctx.title_rating.FirstOrDefault(x => x.Title_Id == titleid); var thisMovieVotes = thisMovie.Num_Votes; var thisMovieRating = thisMovie.Average_Rating; var calcNewRating = (((thisMovieRating * thisMovieVotes) - prevRating) + thisRating) / thisMovieVotes; ctx.title_rating.Update(thisMovie).Entity.Average_Rating = calcNewRating; ctx.rating.Update(updateRatingList).Entity.Rating_ = thisRating; ctx.SaveChanges(); return(true); } } return(false); }
public ActionResult Create([Bind(Include = "Id,PersonId")] Actor actor) { if (ModelState.IsValid) { db.Actors.Add(actor); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PersonId = new SelectList(db.People, "Id", "Name", actor.PersonId); return(View(actor)); }
internal void AddMovie() { var db = new ImdbContext(); db.Database.EnsureCreated(); Console.WriteLine("\r\nNapiš název filmu"); string jmenoFilmu = Console.ReadLine(); if (jmenoFilmu != "") { Console.WriteLine("\r\nHodnocení filmu 0-100b"); string ratingMovie = Console.ReadLine(); int result; if (int.TryParse(ratingMovie, out result) || ratingMovie == "") { if (Int32.Parse(ratingMovie) >= 0 && Int32.Parse(ratingMovie) <= 100 || ratingMovie == "") { Console.WriteLine("\r\nPopis filmu"); string descriptionMovie = Console.ReadLine(); Console.WriteLine("\r\nOdkaz na film"); string urlMovie = Console.ReadLine(); db.Movies.Add(new Movie() { Name = jmenoFilmu, Description = descriptionMovie, Rating = Int32.Parse(ratingMovie), Link = urlMovie, }); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\r\nGratuluji přidal jsi film jménem: " + jmenoFilmu); Console.ResetColor(); db.SaveChanges(); } else { Console.WriteLine("Jejda chyba, zkus to znovu."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } } else { Console.WriteLine("Jejda chyba, zkus to znovu."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } } else { Console.WriteLine("Jejda chyba, zkus to znovu."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
internal void AddActor() { var db = new ImdbContext(); db.Database.EnsureCreated(); Console.WriteLine("\r\nNapiš jméno Herce"); string jmenoHerce = Console.ReadLine(); if (jmenoHerce != "") { db.Actors.Add(new Actor() { Name = jmenoHerce }); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\r\nÚspěšně byl přidát herec/čka: " + jmenoHerce); Console.ResetColor(); db.SaveChanges(); } else { Console.WriteLine("\r\nJejda chyba, zkus to znovu."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
internal void deleteMovie() { var db = new ImdbContext(); db.Database.EnsureCreated(); foreach (var movie in db.Movies) { Console.WriteLine("ID: " + movie.Id + " " + movie.Name); } Console.WriteLine("Napiš id filmu"); string idMovie = Console.ReadLine(); var movieDb = db.Movies.FirstOrDefault(x => x.Id == int.Parse(idMovie)); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Úspěšně jsi smazal film: " + movieDb.Name); Console.ResetColor(); db.Movies.Remove(movieDb); db.SaveChanges(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); }
internal void changeDescription() { var db = new ImdbContext(); db.Database.EnsureCreated(); foreach (var movie in db.Movies) { Console.WriteLine("ID: " + movie.Id + " " + movie.Name); } Console.WriteLine("\r\nNapiš id filmu u kterého chceš změnit popis"); string idName = Console.ReadLine(); var movieDb = db.Movies.SingleOrDefault(x => x.Id == int.Parse(idName)); Console.WriteLine("Napiš nový popis: "); string newDescription = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Úspěšně jsi změnil popis filmu : " + movieDb.Description + " na " + newDescription); Console.ResetColor(); movieDb.Description = newDescription; db.SaveChanges(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); }
//FOR ABOVE METHOD, MADE BCS OF AN ERROR; /* * The instance of entity type 'Rating' cannot be tracked because another * instance with the key value '{Id: x}' is already being tracked */ public bool DeleteRatingFromDB(int userid, string titleid) { using var ctx = new ImdbContext(); var dbRating = GetMovieRatingFromUser(userid, titleid); ctx.Remove(dbRating); ctx.SaveChanges(); return(true); }
public void Save() { var entry = context.ChangeTracker.Entries(); foreach (var item in entry) { SetParameterValueCallback.Invoke(item.State.ToString()); } context.SaveChanges(); }
//DELETE USER PROFILE //TODO : Slet alle brugerens lister mm. public bool DeleteUser(int id) { using var ctx = new ImdbContext(); var dbUser = GetUser(id); if (dbUser == null) { return(false); } ctx.users.Remove(dbUser); ctx.SaveChanges(); return(true); }
//ADD PERSON BOOKMARK TO LIST public Person_Bookmark NewPersonBookmark(string personid, int listid) { using var ctx = new ImdbContext(); var maxId = ctx.person_bookmarks.Max(x => x.Id); ctx.person_bookmarks .Add(new Person_Bookmark() { List_Id = listid, Person_Id = personid }); ctx.SaveChanges(); return(ctx.person_bookmarks.Find(maxId + 1)); }
//CREATE NEW TITLE BOOKMARK public Title_Bookmark NewTitleBookmark(string titleid, int listid) { using var ctx = new ImdbContext(); var maxId = ctx.title_bookmarks.Max(x => x.Id); ctx.title_bookmarks .Add(new Title_Bookmark() { ListId = listid, TitleId = titleid }); ctx.SaveChanges(); return(ctx.title_bookmarks.Find(maxId + 1)); }
//Returns only the professions of whoever we search public List <Person_Profession> GetProfessionByPersonId2(string id) { using var ctx = new ImdbContext(); var query = ctx.PersonProfessions .Include(c => c.person) .Include(v => v.Profession) .Where(p => p.person.Id == id) .ToList(); ctx.SaveChanges(); return(query.ToList()); }
//DELETE TITLE BOOKMARK public bool deleteTitleBookmark(int id) { using var ctx = new ImdbContext(); var dbBookmark = GetTitleBookmark(id); if (dbBookmark == null) { return(false); } ctx.title_bookmarks.Remove(dbBookmark); ctx.SaveChanges(); return(true); }
// // TITLE BOOKMARKS // //NEW TITLE BOOKMARK LIST public Title_Bookmark_List NewTitleBookmarkList(int userid, string listName) { using var ctx = new ImdbContext(); var maxId = ctx.person_bookmark_list.Max(x => x.Id); var dbUser = GetUser(userid).Id; ctx.title_bookmark_list .Add(new Title_Bookmark_List() { ListName = listName, UserId = dbUser }); ctx.SaveChanges(); return(ctx.title_bookmark_list.Find(maxId + 1)); }
internal void addGenres() { var db = new ImdbContext(); db.Database.EnsureCreated(); foreach (var list in db.Movies) { Console.WriteLine("Id " + list.Id + " " + list.Name); } Console.WriteLine("Vyber si film ke kterému chceš nový žánr"); string movieId = Console.ReadLine(); var movieDb = db.Movies.FirstOrDefault(x => x.Id == int.Parse(movieId)); if (movieDb != null) { Console.WriteLine("Napiš nový žánr"); string genreName = Console.ReadLine(); if (genreName != "") { db.Movies.Include(x => x.MovieGenres).FirstOrDefault(x => x.Id == int.Parse(movieId)).MovieGenres.Add(new MovieGenre() { MovieId = int.Parse(movieId), Gendre = genreName, }); db.SaveChanges(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Gratuluji, přidal jsi zánr :" + genreName + " k filmu : " + movieDb.Name); Console.ResetColor(); } else { Console.WriteLine("Prosím zadej id filmu."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } } else { Console.WriteLine("Omlouváme se, ale tento film neevidujeme."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
internal void removeActor() { var db = new ImdbContext(); db.Database.EnsureCreated(); foreach (var movie in db.Movies) { Console.WriteLine("ID: " + movie.Id + " " + movie.Name); } Console.WriteLine("Napiš id filmu"); string idMovie = Console.ReadLine(); foreach (var actor in db.Actors) { Console.WriteLine("ID: " + actor.Id + " " + actor.Name); } Console.WriteLine("Napiš id herce"); string idActor = Console.ReadLine(); var containtUser = db.ActorMovie.Any(x => x.ActorId == int.Parse(idActor) && x.MovieId == int.Parse(idMovie)); if (containtUser == true) { var movieDb = db.ActorMovie.FirstOrDefault(x => x.ActorId == int.Parse(idActor)); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nÚspěšně jsi odebral herce: " + movieDb.Actor.Name); Console.ResetColor(); var dbRemove = db.ActorMovie.FirstOrDefault(x => x.ActorId == int.Parse(idActor) && x.MovieId == int.Parse(idMovie)); db.ActorMovie.Remove(dbRemove); db.SaveChanges(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nTento film neobsahuje tohoto herce nebo tento herec neexistuje."); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
//UPDATE USER PROFILE public bool UpdateUser(int id, string username, string password, string surname, string lastname, int age, string email) { using var ctx = new ImdbContext(); var getUser = ctx.users.FirstOrDefault(x => x.Username == username); if (id <= 0) { return(false); } //PASSWORD if (_userValidation.VerifyPassword(password, ctx.users.Find(id).Password, ctx.users.Find(id).Salt)) { //USERNAME if (username != null && Regex.IsMatch(username, @"^[a-zA-Z]+$")) { ctx.users.Update(ctx.users.Find(id)).Entity.Username = username; } //SURNAME if (surname != null && Regex.IsMatch(surname, @"^[a-zA-Z]+$")) { ctx.users.Update(ctx.users.Find(id)).Entity.Surname = surname; } //LASTNAME if (lastname != null && Regex.IsMatch(lastname, @"^[a-zA-Z]+$")) { ctx.users.Update(ctx.users.Find(id)).Entity.Last_Name = lastname; } //AGE if (age != 0) { ctx.users.Update(ctx.users.Find(id)).Entity.Age = age; } //EMAIL if (email != null && IsValidEmail(email)) { ctx.users.Update(ctx.users.Find(id)).Entity.Email = email; } ctx.SaveChanges(); return(true); } return(false); }
//DELETE TITLE BOOKMARK LIST public bool deleteTitleBookmarkList(int listid) { using var ctx = new ImdbContext(); var dbList = GetTitleBookmarkLists(listid).FirstOrDefault(); if (dbList == null) { return(false); } deleteTitleBookmarks(listid); ctx.title_bookmark_list.Remove(dbList); ctx.SaveChanges(); return(true); }
//CREATE NEW USER public User CreateUser(string username, string password, string surname, string lastname, int age, string email) { Hashing.HashSalt hashSalt = hashing.PasswordHash(16, password); using var ctx = new ImdbContext(); var maxId = ctx.users.Max(x => x.Id); /*if (!Regex.IsMatch(username, @"^[a-zA-Z]+$") || !Regex.IsMatch(surname, @"^[a-zA-Z]+$") || !Regex.IsMatch(lastname, @"^[a-zA-Z]+$") || !IsValidEmail(email) || * age == 0) return null;*/// TODO: Add username & password check ctx.users.Add(new User { Id = maxId + 1, Username = username, Password = hashSalt.Hash, Salt = hashSalt.Salt, Age = age, Surname = surname, Last_Name = lastname, Email = email }); ctx.SaveChanges(); return(ctx.users.Find(maxId + 1)); }
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, Movie movie) { ImdbContext context = new ImdbContext(); if (ModelState.IsValid) { var currMovie = context.Movies.Find(movie.Id); context.Actors.RemoveRange(currMovie.Actors); context.Writers.RemoveRange(currMovie.Writers); context.Directors.RemoveRange(currMovie.Directors); context.Characters.RemoveRange(currMovie.Characters); context.Movies.Remove(currMovie); context.SaveChanges(); } return(Json(new[] { movie }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet)); }
//[Bind(Include = "Id,Name,Plot,YearOfRelease,Poster")] public ActionResult Create(NewMovieViewModel m) { List <Actor> actors = new List <Actor>(); m.Person = new Person(); for (int i = 0; i < m.ActorsId.Count; i++) { Actor a = db.Actors.Find(m.ActorsId[i]); actors.Add(a); } Movie mov = new Movie(); if (ModelState.IsValid) { mov.Actors = actors; mov.Name = m.Name; mov.Plot = m.Plot; mov.YearOfRelease = m.YearOfRelease; // mov.Poster = m.Poster; mov.ProducerId = m.Producer; if (m.Poster != null && m.Poster.ContentLength > 0) { var uploadDir = "~/Uploads"; var imagePath = Path.Combine(Server.MapPath(uploadDir), m.Poster.FileName); var imageUrl = Path.Combine(uploadDir, m.Poster.FileName); m.Poster.SaveAs(imagePath); mov.Poster = imageUrl; } else if (m.PosterPath != null) { mov.Poster = m.PosterPath; } else { mov.Poster = "N/A"; } db.Movies.Add(mov); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(m)); }
//DELETE TITLE BOOKMARKS FROM LIST (USED IN DELETE OF TITLE LIST) public bool deleteTitleBookmarks(int id) { using var ctx = new ImdbContext(); var dbBookmark = GetTitleBookmarks(id); if (dbBookmark == null) { return(false); } foreach (var x in ctx.title_bookmarks.Where(x => x.ListId == id)) { ctx.title_bookmarks.Remove(x); } ctx.SaveChanges(); return(true); }
public void AddMovieReview(string titleId, int userId, int rating) { var review = _context.MovieReviews.SingleOrDefault(x => x.UserId == userId && x.TitleId == titleId); if (review == null) { review = new MovieReview() { UserId = userId, TitleId = titleId, Rating = rating, RatingDate = new DateTime() }; _context.MovieReviews.Add(review); } else { review.Rating = rating; review.RatingDate = new DateTime(); } _context.SaveChanges(); }
internal void deleteActor() { var db = new ImdbContext(); db.Database.EnsureCreated(); foreach (var actor in db.Actors) { Console.WriteLine("ID: " + actor.Id + " " + actor.Name); } Console.WriteLine("Napiš id herce"); string idActor = Console.ReadLine(); var actorDb = db.Actors.FirstOrDefault(x => x.Id == int.Parse(idActor)); if (actorDb != null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Úspěšně jsi smazal herce: " + actorDb.Name); Console.ResetColor(); db.Actors.Remove(actorDb); db.SaveChanges(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nZkus to znovu a lépe."); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
//DELETE RATING FROM MOVIE public bool DeleteRatingFromUser(int userid, string titleid) { using var ctx = new ImdbContext(); //calc new rating of movie var updateRatingList = ctx.rating.FirstOrDefault(x => x.Title_Id == titleid && x.User_Id == userid); if (updateRatingList == null) { return(false); } { var prevRating = updateRatingList.Rating_; var thisMovie = ctx.title_rating.FirstOrDefault(x => x.Title_Id == titleid); var thisMovieVotes = thisMovie.Num_Votes; var thisMovieRating = thisMovie.Average_Rating; var calcNewRating = ((thisMovieRating * thisMovieVotes) - prevRating) / (thisMovieVotes - 1); ctx.title_rating.Update(thisMovie).Entity.Average_Rating = calcNewRating; ctx.title_rating.Update(thisMovie).Entity.Num_Votes = thisMovieVotes - 1; ctx.SaveChanges(); DeleteRatingFromDB(userid, titleid); return(true); } }
//CHANGE PASSWORD public bool ChangePassword(/*int id,*/ string username, string oldpassword, string newpassword) { using var ctx = new ImdbContext(); var getUser = ctx.users.FirstOrDefault(x => x.Username == username); if (_userValidation.VerifyPassword(oldpassword, getUser.Password, getUser.Salt)) /* * if (_userValidation.VerifyPassword(oldpassword, ctx.users.Find(id).Password, ctx.users.Find(id).Salt) * && ctx.users.Find(id).Username == username)*/ { Hashing.HashSalt hashSalt = hashing.PasswordHash(16, newpassword); //ctx.users.Update(ctx.users.Find(id)).Entity.Password = hashSalt.Hash; //ctx.users.Update(ctx.users.Find(id)).Entity.Salt = hashSalt.Salt; ctx.users.Update(getUser).Entity.Password = hashSalt.Hash; ctx.users.Update(getUser).Entity.Salt = hashSalt.Salt; ctx.SaveChanges(); } else { return(false); } return(true); }
public void Save() { context.SaveChanges(); }
internal void AssignActor() { var db = new ImdbContext(); db.Database.EnsureCreated(); if (db.Movies.ToList().Count != 0 || db.Actors.ToList().Count != 0) { foreach (var actor in db.Actors) { Console.WriteLine("ID: " + actor.Id + " " + actor.Name); } Console.WriteLine("Napiš id herce"); string idActor = Console.ReadLine(); var selectedActor = db.Actors.FirstOrDefault(x => x.Id == int.Parse(idActor)); if (selectedActor != null) { foreach (var movie in db.Movies) { Console.WriteLine("ID: " + movie.Id + " " + movie.Name); } Console.WriteLine("Napiš id filmu"); string idMovie = Console.ReadLine(); var selectedMovie = db.Movies.FirstOrDefault(x => x.Id == int.Parse(idMovie)); var containtUser = db.ActorMovie.Any(x => x.ActorId == int.Parse(idActor) && x.MovieId == int.Parse(idMovie)); if (selectedMovie != null && containtUser == false) { var moviedb = db.Movies.Include(x => x.Actors).FirstOrDefault(x => x.Id == int.Parse(idMovie)); moviedb.Actors.Add(new ActorMovie() { ActorId = int.Parse(idActor) }); db.SaveChanges(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\n\rÚspěšně jsi přiřadil herce: " + selectedActor.Name + " k filmu:" + selectedMovie.Name); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nTakový film neevidujeme nebo uživatel již existuje ve filmu"); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nTakového herce neevidujeme"); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\r\nTabulka s herci nebo filmy jsou prázdné, naplň je prosím."); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }
internal async Task omdb() { //http://www.omdbapi.com/?t=james+bond?&apikey=9553bb93 var apiKey = "?&apikey=9553bb93"; Console.WriteLine("Napiš co potřebuješ načíst za film"); string inputMovie = Console.ReadLine(); string html = string.Empty; string url = @"http://www.omdbapi.com/?t=" + inputMovie + "?&apikey=9553bb93"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } DataOmdb omdb = JsonConvert.DeserializeObject <DataOmdb>(html); if (omdb.Title != null) { string actors = omdb.Actors; Console.WriteLine(omdb.Title); Console.WriteLine(omdb.Plot); Console.WriteLine(omdb.Genre); Console.WriteLine(omdb.imdbRating); Console.WriteLine(omdb.Actors); Console.WriteLine(omdb.Website); Console.WriteLine("\r\nChceš přidat tento film do db? y/N"); string action = Console.ReadLine(); if (action == "y" || action == "Y") { Console.WriteLine(""); var db = new ImdbContext(); db.Database.EnsureCreated(); //pridat film var addMovie = db.Movies.Add(new Movie() { Name = omdb.Title, Description = omdb.Plot, Rating = Int32.Parse(omdb.imdbRating.Replace(".", "")), Link = omdb.Website, }); db.SaveChanges(); //pridat herce String[] pattern = { ", " }; String[] strlist = actors.Split(pattern, actors.Length, StringSplitOptions.RemoveEmptyEntries); string[] a = strlist; foreach (String s in strlist) { var addActor = db.Actors.Add(new Actor() { Name = s }); db.SaveChanges(); //priradit herce db.ActorMovie.Add(new ActorMovie() { ActorId = addActor.Entity.Id, MovieId = addMovie.Entity.Id }); db.SaveChanges(); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Úspěšně jsi přidal film" + omdb.Title + " do databáze."); Console.ResetColor(); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } else if (action == "N" || action == "n") { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("OK, VYBER JINÝ FILM - STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } else { Console.WriteLine("Ano / Ne - to je to tak těžký?"); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER A ZKUS TO ZNOVU"); Console.ResetColor(); } } else { Console.WriteLine("Omlouváme se, ale takový film nenabízíme."); Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("STISKNI ENTER PRO DALŠÍ POUŽÍVÁNÍ PROGRAMU"); Console.ResetColor(); } }