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"); }
public void It_Should_Be_Able_To_Search_Movies() { // arrange Mock <MoviesContext> mockContext = new Mock <MoviesContext>(); var movie = new Movie { Title = movieTitle }; mockContext.Setup(context => context.SearchMovie(movieTitle)).Returns(new List <Movie> { movie }); var repo = new MovieRepository(mockContext.Object); // act var testMovie = new Movie { Title = movieTitle }; repo.AddMovie(testMovie); int expectedCount = 1; // act IEnumerable <Movie> result = repo.SearchMovies(movieTitle); // assert Assert.AreEqual(expectedCount, result.Count()); Assert.AreEqual(movieTitle, result.ToList()[0].Title); }
public void AddOrUpdate(MovieDTO movie) { var movy = new Movy() { Id = movie.Id != Guid.Empty ? movie.Id : Guid.NewGuid(), Rating = movie.Rating, AverageScore = movie.AverageScore, Length = movie.Length, ReleaseDate = movie.ReleaseDate, Title = movie.Title, }; if (!string.IsNullOrEmpty(movie.CategoryName)) { var categoryRepo = new CategoryRepository(); var existingCategory = categoryRepo.GetCategory(movie.CategoryName); if (existingCategory != null) { movy.CategoryId = existingCategory.Id; } } if (movie.Id != Guid.Empty) { //updates movie _movieRepo.UpdateMovie(movy); } else { //adds new movie _movieRepo.AddMovie(movy); } }
public void AddorUpdate(MovieDTO movie) { var movy = new Movie { Id = movie.Id != Guid.Empty ? movie.Id: Guid.NewGuid(), //inline if Title = movie.Title, AverageScore = movie.AverageScore, Length = movie.Length, Rating = movie.Rating, ReleaseDate = movie.ReleaseDate }; if (!string.IsNullOrEmpty(movie.CategoryName)) { var categoryRepo = new CategoryRepository(); var existingCategory = categoryRepo.GetCategorybyName(movie.CategoryName); if (existingCategory != null) { movy.CategoryId = existingCategory.Id; } } if (movie.Id != Guid.Empty)//movie exists => update { _repo.updateMovie(movy); } else//movie doesn't exist => add { _repo.AddMovie(movy); } }
public void AddOrUpdate(MovieDTO movie) { var movy = new Movy { Id = movie.Id != Guid.Empty ? movie.Id: Guid.NewGuid(), //inline if Title = movie.Title, AverageScore = movie.AverageScore, Length = movie.Length, Rating = movie.Rating, ReleaseDate = movie.ReleaseDate, }; //category is a bit tricky //if we have something in our MovieDTO model ( movie ), then we need to search for the category with that name and get its Id in order to assign it to our movie //so let's define a search by name in category if (!string.IsNullOrEmpty(movie.CategoryName)) { var categoryRepo = new CategoryRepository(); var existingCategory = categoryRepo.GetCategoryByName(movie.CategoryName); if (existingCategory != null) { movy.CategoryId = existingCategory.Id; } } if (movie.Id != Guid.Empty) //movie exists => update { _repo.UpdateMovie(movy); } else //movie doesn't exist => add { _repo.AddMovie(movy); } }
public IActionResult Create(Movie m) { if (ModelState.IsValid) { MovieRepository.AddMovie(m); return(RedirectToAction("index")); } return(View(m)); }
public async Task <IHttpActionResult> Post([FromBody] Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _movie.AddMovie(movie); return(CreatedAtRoute("DefaultApi", new { id = movie.Id }, movie)); }
public async void MovieRepository_Create_NullUser_Failure() { // Arrange Movie _movie = null; //Act _mockContext.Setup((p => p.MoviesCollectionName)).Returns("movies"); _mockContext.Setup((p => p.ConnectionString)).Returns("mongodb://localhost:27017"); _mockContext.Setup((p => p.DatabaseName)).Returns("MovieCatalog"); var movieRepository = new MovieRepository(_mockContext.Object); // Assert await Assert.ThrowsAsync <ArgumentNullException>(() => movieRepository.AddMovie(_movie)); }
static void Main(string[] args) { // get the configuration from file var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); // now i can access the connection string like this // this will be null if there isn't an appsettings with this connection string Console.WriteLine(configuration.GetConnectionString("MoviesDB")); // ORM: object-relational mapper // our ORM in .NET is: Entity Framework // we will use database-first approach to EF Console.WriteLine("Hello World!"); // provide the connection string to the dbcontext var optionsBuilder = new DbContextOptionsBuilder <MoviesDBContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("MoviesDB")); var repo = new MovieRepository(new MoviesDBContext(optionsBuilder.Options)); var movies = repo.GetMoviesWithGenres(); foreach (var item in movies) { Console.WriteLine($"Name {item.Name}," + $" genre {item.Genre.Name}"); } //edit a movie var aMovie = movies.First(); aMovie.Name = "A New Hope"; repo.Edit(aMovie); repo.AddMovie("Die Hard", DateTime.Now, "action"); repo.DeleteById(aMovie.Id); repo.SaveChanges(); movies = repo.GetMoviesWithGenres(); Console.WriteLine(); foreach (var item in movies) { Console.WriteLine($"Name {item.Name}," + $" genre {item.Genre.Name}"); } }
protected void ButtonSave_Click(object sender, EventArgs e) { ViewMovie newMovie = new ViewMovie(); newMovie.MovieName = TextBoxMovieName.Value; newMovie.DirectorName = DropDownListDirectorName.SelectedItem.Text; newMovie.GenreName = DropDownListGenre.SelectedItem.Text; newMovie.Description = TextBoxDescription.Value; newMovie.ReleaseDate = int.Parse(TextBoxReleaseDate.Value); newMovie.Score = decimal.Parse(TextBoxScore.Value); newMovie.TotalScore = newMovie.Score; newMovie.ScoreCounter = 1; MovieRepository.AddMovie(newMovie); Response.Redirect("ListOfMovies.aspx"); }
public void It_Should_Be_Able_To_Add_Movies() { // arrange var testMovie = new Movie { Title = movieTitle }; Mock <MoviesContext> mockContext = new Mock <MoviesContext>(); mockContext.Setup(ctx => ctx.AddMovie(testMovie)).Returns(testMovie); var repo = new MovieRepository(mockContext.Object); // act var result = repo.AddMovie(testMovie); // assert mockContext.Verify(m => m.AddMovie(testMovie), Times.Once()); Assert.AreEqual(testMovie, result); }
public IActionResult Post([FromBody] Movie movie) { try { if (movie != null) { repository.AddMovie(movie); return(Created(Url.Link("GetMovies", new { }), movie)); } else { return(NotFound("No Customer info retrieved...")); } } catch (Exception e) { return(BadRequest($"O oh, something ({e.Message}) went wrong")); } }
public void AddOrUpdate(MovieDTO movie) { var movy = new Movy { id = movie.Id != Guid.Empty ? movie.Id : Guid.NewGuid(), //checking if passed movie object ID already exists, if not then we create a new ID. Title = movie.Title, ReleaseDate = movie.ReleaseDate, AverageScore = movie.AverageScore, Length = movie.Length, Rating = movie.Rating, }; //category needs to be set differently. If we have something in our MovieDTO model (movie), we need to search category table for the name and get the ID of the category in order to assign it to the object. if (!string.IsNullOrEmpty(movie.CategoryName)) { var categoryRepo = new CategoryRepository(); var existingCategory = categoryRepo.GetCategoryByName(movie.CategoryName); if (existingCategory != null) { movy.CategoryID = existingCategory.id; } } if (movie.Id != Guid.Empty) { //movie exists => update _repo.UpdateMovie(movy); } else { //movie doesn't exist => add _repo.AddMovie(movy); } }
public Movie AddMovie(AddMovieCommand movieToAdd) { return(_repo.AddMovie(movieToAdd)); }
public static Movie Create(MovieRepository movieRepository, Movie movie) { return(movieRepository.AddMovie(movie)); }
public void CreateMovie(Movie movie) { movieRepository.AddMovie(movie); }
public async Task <ActionResult> PostMovie(Movie movie) { await _repository.AddMovie(movie.Title); return(CreatedAtAction(nameof(GetMovie), new { Title = movie.Title }, movie)); }