public async Task <IActionResult> Put([FromRoute] int movieId, [FromBody] MovieTable movieTable) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (movieId != movieTable.MovieId) { return(BadRequest()); } _context.Entry(movieTable).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieTableExists(movieId)) { return(NotFound()); } else { throw; } } return(Ok(movieTable)); }
public ActionResult Index() { MovieTable dbMovies = new MovieTable(); dbMovies.All(); return(View(dbMovies)); }
public async static void AddMovieDataAsync(MovieDataModel movie, MovieTable table) { string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "moviesdatabase.db"); using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}")) { db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; insertCommand.CommandText = string.Format("INSERT OR REPLACE INTO {0} VALUES (@Title,@Year,@Rated,@Released,@Runtime,@Genre,@Director,@Actors,@Plot,@Language,@Country,@IMDb,@ImageUrl,@Type,@ID);", table.ToString()); insertCommand.Parameters.AddWithValue("@Title", movie.Title); insertCommand.Parameters.AddWithValue("@Year", movie.Year); insertCommand.Parameters.AddWithValue("@Rated", movie.Rated); insertCommand.Parameters.AddWithValue("@Released", movie.Released); insertCommand.Parameters.AddWithValue("@Runtime", movie.Runtime); insertCommand.Parameters.AddWithValue("@Genre", movie.Genre); insertCommand.Parameters.AddWithValue("@Director", movie.Director); insertCommand.Parameters.AddWithValue("@Actors", movie.Actors); insertCommand.Parameters.AddWithValue("@Plot", movie.Plot); insertCommand.Parameters.AddWithValue("@Language", movie.Language); insertCommand.Parameters.AddWithValue("@Country", movie.Country); insertCommand.Parameters.AddWithValue("@IMDb", movie.ImdbRating); insertCommand.Parameters.AddWithValue("@ImageUrl", movie.Poster); insertCommand.Parameters.AddWithValue("@Type", movie.Type); insertCommand.Parameters.AddWithValue("@ID", movie.imdbID); await Task.Run(() => insertCommand.ExecuteReader()); db.Close(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { movrepo = new MovieRepository(); movie = new MovieTable(); movie.MovieName = TextBox11.Text; movie.LanguageID = Convert.ToByte(DropDownList6.SelectedValue); movie.GenreID = Convert.ToByte(DropDownList7.SelectedValue); movie.QualityID = Convert.ToByte(DropDownList8.SelectedValue); movie.ReleaseDate = Convert.ToDateTime(TextBox12.Text); movie.Availability = Convert.ToByte(TextBox13.Text); movie.Discontinue = Convert.ToBoolean(TextBox3.Text); movie.DateOfAddition = Convert.ToDateTime(TextBox4.Text); movie.Price = Convert.ToDecimal(TextBox5.Text); movie.Fine = Convert.ToByte(TextBox6.Text); movie.Producer = TextBox7.Text; movie.Director = TextBox8.Text; movie.Cast = TextBox9.Text; movie.Certificate = DropDownList4.SelectedValue; movie.Rating = Convert.ToByte(TextBox9.Text); movrepo.AddMovie(movie); Response.Redirect("SucessMovieAdd.aspx"); }
private void MovieDetail_Load(object sender, EventArgs e) { RatingTable.DeleteByUser(UserInfo.TEST_USER_ID); PreviousButton.Enabled = false; index = 0; movies = MovieTable.Select(); SetDataForMovie(); }
private void button1_Click(object sender, EventArgs e) { RatingTable.AddRating(movies[index].Id, UserInfo.TEST_USER_ID, Convert.ToDecimal(RatingButton.Text), CommentTextBox.Text); setMyRatingLabel(movies[index].Id); movies[index].EnabledRating = false; EnableOrDisableAddButton(); loadCommentsForMovie(movies[index].Id); AvgRatingLabel.Text = MovieTable.SelectAvgRatingForMovie(movies[index].Id).ToString("0.##"); }
private void button1_Click(object sender, EventArgs e) { NumberOfActorsView.Items.Clear(); Collection <Movie> movies = MovieTable.Select(); foreach (Movie movie in movies) { string[] row = { movie.Id.ToString(), movie.Title, movie.Year.ToString(), movie.Premiere.ToString(), MovieTable.Select_Actor_Number(movie.Id).ToString() }; var listViewItem = new ListViewItem(row); NumberOfActorsView.Items.Add(listViewItem); } }
public async Task <IActionResult> Post([FromBody] MovieTable movieTable) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.MovieTable.Add(movieTable); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { id = movieTable.MovieId }, movieTable)); }
public bool AddNewMovie(MovieTable movie) { try { _db.Add(movie); _db.SaveChanges(); return(true); } catch (DbException e) { return(false); } }
public IHttpActionResult GetByID(int ID) { MovieTable movie = movieService.GetByID(ID); if (movie != null) { return(Ok(new MovieDto { MovieName = movie.MovieName, MovieID = movie.MovieID })); } else { return(BadRequest()); } }
public bool updateMovie(MovieTable movie) { try { var dbmovie = _db.MovieTable.Where(m => m.MovieId == movie.MovieId).FirstOrDefault(); dbmovie.MovieName = movie.MovieName; dbmovie.Genre = movie.Genre; dbmovie.Stock = movie.Stock; dbmovie.Language = movie.Language; _db.SaveChanges(); return(true); } catch (DbException e) { return(false); } }
public async static void DeleteMovieAsync(MovieDataModel movie, MovieTable table) { string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "moviesdatabase.db"); using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}")) { db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; insertCommand.CommandText = string.Format("DELETE from {0} WHERE \"Title\" = @Title AND " + "\"Runtime\" = @Runtime AND \"Director\" = @Director", table); insertCommand.Parameters.AddWithValue("@Title", movie.Title); insertCommand.Parameters.AddWithValue("@Runtime", movie.Runtime); insertCommand.Parameters.AddWithValue("@Director", movie.Director); await Task.Run(() => insertCommand.ExecuteReader()); db.Close(); } }
public static List <MovieDataModel> GetMovieData(MovieTable movieTable) { List <MovieDataModel> entries = new List <MovieDataModel>(); string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "moviesdatabase.db"); using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}")) { db.Open(); SqliteCommand selectCommand = new SqliteCommand (string.Format("SELECT * from {0} ORDER BY \"Title\"", movieTable), db); SqliteDataReader query = selectCommand.ExecuteReader(); MovieDataModel movie; while (query.Read()) { movie = new MovieDataModel { Title = query.GetString(0), Year = query.GetString(1), Rated = query.GetString(2), Released = query.GetString(3), Runtime = query.GetString(4), Genre = query.GetString(5), Director = query.GetString(6), Actors = query.GetString(7), Plot = query.GetString(8), Language = query.GetString(9), Country = query.GetString(10), ImdbRating = query.GetString(11), Poster = query.GetString(12), Type = query.GetString(13), imdbID = query.GetString(14) }; entries.Add(movie); } db.Close(); } return(entries); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string uid = Request.QueryString["uid"]; mr = new MovieRepository(); MovieTable lst = mr.GetMovieForID(Convert.ToInt64(uid)); if ((lst.Availability > 0) & (uid != "0")) { btnRent.Visible = true; } else { btnRent.Visible = false; } DetailsView1.DataSource = lst; DetailsView1.DataBind(); } }
public static void DeleteAllDataFromDatabase() { Collection <RatingHistory> ratingHistories1 = RatingHistoryTable.Select(); foreach (RatingHistory ratingHist in ratingHistories1) { RatingHistoryTable.Delete(ratingHist.Id); } Collection <Rating> ratings1 = RatingTable.Select(); foreach (Rating rate in ratings1) { RatingTable.Delete(rate.Movie_id, rate.User_id); } Collection <UserInfo> users1 = UserTable.Select(); foreach (UserInfo user in users1) { UserTable.Delete(user.Id); } Collection <MovieGenre> movieGenres1 = MovieGenreTable.Select(); foreach (MovieGenre movieGen in movieGenres1) { MovieGenreTable.Delete(movieGen.Movie_id, movieGen.Genre_id); } Collection <Genre> genres1 = GenreTable.Select(); foreach (Genre gen in genres1) { GenreTable.Delete(gen.Id); } Collection <MovieActor> movieActors1 = MovieActorTable.Select(); foreach (MovieActor movieAct in movieActors1) { MovieActorTable.Delete(movieAct.Actor_id, movieAct.Movie_id); } Collection <Actor> actors1 = ActorTable.Select(); foreach (Actor act in actors1) { ActorTable.Delete(act.Id); } Collection <Movie> movies1 = MovieTable.Select(); foreach (Movie mov in movies1) { MovieTable.Delete(mov.Id); } Collection <Director> dirs = DirectorTable.Select(); foreach (Director dir in dirs) { DirectorTable.Delete(dir.Id); } }
public static void TryAllOperationsOfModel() { Database db = new Database(); db.Connect(); Console.WriteLine(" Delete all data from database "); Console.WriteLine("------------------------------------------------------------------"); DeleteAllDataFromDatabase(); Console.WriteLine("\n\n User "); Console.WriteLine("------------------------------------------------------------------"); UserInfo userInfo = new UserInfo(); userInfo.Id = 1; userInfo.Nickname = "sob28"; userInfo.Firstname = "Tonda"; userInfo.Lastname = "Sobota"; userInfo.Email = "*****@*****.**"; userInfo.Points = 42; userInfo.Rank = "Pokročilý"; userInfo.Sex = null; userInfo.Country = null; userInfo.Shortinfo = null; UserTable.Insert(userInfo, db); userInfo.Lastname = "Nedela"; UserTable.Update(userInfo, db); UserTable.UserValuation(); // 5.7 Ocenění uživatelů UserTable.RecalculatePoints(); // 5.8 Přepočet získaných bodů Collection <UserInfo> users = UserTable.Select(); foreach (UserInfo user in users) { Console.WriteLine(UserTable.Select(user.Id, db).ToString()); } foreach (UserInfo user in UserTable.SelectUsersWithNumberOfRates(0)) //5.6 Pocet ohodnocených filmu větší než parametr { Console.WriteLine("User ID: " + user.Id + ", Number of rates: " + user.NumberOfRates); } Console.WriteLine("\n\n Director "); Console.WriteLine("------------------------------------------------------------------"); Director director = new Director(); director.Id = 1; director.Firstname = "Jakub"; director.Lastname = "Novák"; director.Nationality = "CZ"; director.Birthplace = "Brno"; director.Height = 1.5m; DirectorTable.Insert(director, db); director.Lastname = "Holý"; DirectorTable.Update(director, db); Collection <Director> directors = DirectorTable.Select(); foreach (Director dir in directors) { Console.WriteLine(DirectorTable.Select(dir.Id, db).ToString()); } Console.WriteLine("\n\n Movie "); Console.WriteLine("------------------------------------------------------------------"); Movie movie = new Movie(); movie.Id = 1; movie.Title = "Zmizení"; movie.Year = 2016; movie.Time = 215; movie.Language = "*****@*****.**"; movie.Description = "Velice dobrý film"; movie.Country = "USA"; movie.Award = true; movie.Premiere = new DateTime(2017, 05, 06); movie.Director_id = director.Id; MovieTable.Insert(movie, db); movie.Year = 2018; MovieTable.Update(movie, db); Collection <Movie> movies = MovieTable.Select(); foreach (Movie mov in movies) { Console.WriteLine(MovieTable.Select(mov.Id, db).ToString()); Console.WriteLine("Actor number: " + MovieTable.Select_Actor_Number(mov.Id)); //1.6 Výpis filmů a k nim počet obsazených herců } Console.WriteLine("\n\n Genre "); Console.WriteLine("------------------------------------------------------------------"); Genre genre = new Genre(); genre.Id = 1; genre.Name = "Thriller"; genre.Description = "Mrazivý žánr"; GenreTable.Insert(genre, db); genre.Name = "Horror"; GenreTable.Update(genre, db); Collection <Genre> genres = GenreTable.Select(); foreach (Genre gen in genres) { Console.WriteLine(GenreTable.Select(gen.Id, db).ToString()); } Console.WriteLine("\n\n Actor "); Console.WriteLine("------------------------------------------------------------------"); Actor actor = new Actor(); actor.Id = 1; actor.Firstname = "Čeněk"; actor.Lastname = "Volant"; actor.Nationality = "CZ"; actor.Birthplace = "Ostrava"; actor.Height = 1.5m; ActorTable.Insert(actor, db); actor.Firstname = "Jozef"; ActorTable.Update(actor, db); Collection <Actor> actors = ActorTable.Select(); foreach (Actor act in actors) { Console.WriteLine(ActorTable.Select(act.Id, db).ToString()); } Console.WriteLine("\n\n Rating "); Console.WriteLine("------------------------------------------------------------------"); Rating rating = new Rating(); rating.Movie_id = 1; rating.User_id = 1; rating.Rate = 8.5m; rating.Dateofadd = new DateTime(2018, 05, 08); rating.Comment = "Nic moc film"; RatingTable.Insert(rating, db); rating.Dateofadd = new DateTime(2018, 05, 09); RatingTable.Update(rating, db); RatingTable.AddRating(2, 2, rating.Rate, rating.Comment); // 6.5 Přidání hodnocení Collection <Rating> ratings = RatingTable.Select(); foreach (Rating rate in ratings) { Console.WriteLine(RatingTable.SelectMovieID(rate.Movie_id, db).ToString()); } Console.WriteLine("\n\n Rating History "); Console.WriteLine("------------------------------------------------------------------"); RatingHistory ratingHistory = new RatingHistory(); ratingHistory.Id = 1; ratingHistory.Rate = 9.5m; ratingHistory.Dateofchange = new DateTime(2018, 04, 30); ratingHistory.Comment = "Uleželo se mi to v hlavě"; ratingHistory.Rating_movie_id = 1; ratingHistory.Rating_userinfo_id = 1; RatingHistoryTable.Insert(ratingHistory, db); ratingHistory.Rate = 9m; RatingHistoryTable.Update(ratingHistory, db); Collection <RatingHistory> ratingHistories = RatingHistoryTable.Select(); foreach (RatingHistory ratingHist in ratingHistories) { Console.WriteLine(RatingHistoryTable.Select(ratingHist.Id, db).ToString()); } Console.WriteLine("\n\n Movie Genre "); Console.WriteLine("------------------------------------------------------------------"); MovieGenre movieGenre = new MovieGenre(); movieGenre.Movie_id = 1; movieGenre.Genre_id = 1; movieGenre.dateOfAdd = new DateTime(2016, 03, 22); MovieGenreTable.Insert(movieGenre, db); movieGenre.dateOfAdd = new DateTime(2016, 03, 25); MovieGenreTable.Update(movieGenre, db); Collection <MovieGenre> movieGenres = MovieGenreTable.Select(); foreach (MovieGenre movieGen in movieGenres) { Console.WriteLine(MovieGenreTable.SelectMovieId(movieGen.Movie_id, db).ToString()); } Console.WriteLine("\n\n Movie Actor "); Console.WriteLine("------------------------------------------------------------------"); MovieActor movieActor = new MovieActor(); movieActor.Movie_id = 1; movieActor.Actor_id = 1; movieActor.Role = "Hlavní hrdina"; movieActor.Fee = 22000; MovieActorTable.Insert(movieActor, db); movieActor.Fee = 25000; MovieActorTable.Update(movieActor, db); Collection <MovieActor> movieActors = MovieActorTable.Select(); foreach (MovieActor movieAct in movieActors) { Console.WriteLine(MovieActorTable.SelectMovieId(movieAct.Movie_id, db).ToString()); } Console.WriteLine("\n\n"); db.Close(); }
public IHttpActionResult Create(MovieTable movie) { movieService.Create(movie); return(Ok()); }
public IHttpActionResult Put(int key, [FromBody] MovieTable movie) { movieService.Update(movie, key); return(Ok()); }
public void Post([FromBody] MovieTable movie) { _service.AddNewMovie(movie); }
public void Put([FromBody] MovieTable value) { _service.updateMovie(value); }