public IHttpActionResult Post([FromBody] Models.Movie movie) { try { if (movie == null) { return(BadRequest("Movie cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var movieRepository = new Models.MovieRepository(); var newMovie = movieRepository.Save(movie); if (newMovie == null) { return(Conflict()); } return(Created <Movie>(Request.RequestUri + newMovie.MovieId.ToString(), newMovie)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public ActionResult Edit(Models.Movie mv) { var movie = Client_to_DAL(mv); db.EditMovie(movie); return(RedirectToAction("Index")); }
public ActionResult Delete(Models.Movie mv) { var result = Client_to_DAL(mv); db.DeleteMovie(result); return(RedirectToAction("Index")); }
public ActionResult Index() { SqlConnection sqlConnection1 = new SqlConnection("Data Source=10.139.31.219;Initial Catalog=Northwind;User ID=sa;Password=1234"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "getListeFilms"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection1; sqlConnection1.Open(); reader = cmd.ExecuteReader(); List <Models.Movie> result = new List <Models.Movie>(); while (reader.Read()) { Models.Movie item = new Models.Movie() { Title = reader["title"].ToString(), Genre = reader["genre"].ToString(), year = Int32.Parse(reader["year"].ToString()) }; result.Add(item); } sqlConnection1.Close(); return(View(result)); }
public IActionResult SaveMovie(Models.Movie movie) { if (movie.Id > 0) { var data = _context.Movies.Where(r => r.Id.Equals(movie.Id)).FirstOrDefault(); if (data == null) { throw new Exception("movie not found"); } data.Description = movie.Description; } else { _context.Movies.Add(new Data.Entities.Movie() { Description = movie.Description, Title = movie.Title }); } _context.SaveChanges(); return(RedirectToAction("Index", "Movies", null)); }
public async Task <IActionResult> PutMovie(int id, Models.Movie movie) { if (id != movie.Id) { return(BadRequest()); } _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int Add(Models.Movie movieModel) { if (movieModel.Format == null) { throw new ArgumentNullException("Format", "The Format property must not be null."); } if (movieModel.Director == null) { throw new ArgumentNullException("Director", "The Director property must not be null."); } Data.Movie newRow = new Data.Movie(); newRow.Cost = movieModel.Cost; newRow.Description = movieModel.Description; newRow.Title = movieModel.Title; newRow.ImagePath = movieModel.ImagePath; Data.Rating existingRatings = db.Ratings.SingleOrDefault(x => x.Id == movieModel.Rating.Id); newRow.Rating = existingRatings ?? throw new ArgumentException("The associated rating cannot be found."); Data.Director existingDirectors = db.Directors.SingleOrDefault(x => x.Id == movieModel.Director.Id); newRow.Director = existingDirectors ?? throw new ArgumentException("The associated Director cannot be found."); Data.Format existingFormats = db.Formats.SingleOrDefault(x => x.Id == movieModel.Format.Id); newRow.Format = existingFormats ?? throw new ArgumentException("The associated format cannot be found."); db.Movies.Add(newRow); db.SaveChanges(); return(newRow.Id); }
// GET: Movies public ActionResult Random() { var Movie = new Models.Movie { Name = "Shrek!" }; var Customers = new List <Customer> { new Customer { Name = "Customer1" }, new Customer { Name = "Customer2" } }; var viewModel = new RandomMovieViewModel { Customer = Customers, Movie = Movie }; return(View(viewModel)); // return View(movie); // return RedirectToAction("Index", "Home", new { page = 1, sortBy = "name" }); }
public async Task <ActionResult <Models.Movie> > PostMovie(Models.Movie movie) { _context.Movie.Add(movie); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMovie", new { id = movie.Id }, movie)); }
public static List <Models.Movie> SearchMovie(string title) { try { SearchContainer <SearchMovie> results = APIConfiguration.ConnectAPI().SearchMovie("star wars"); List <Models.Movie> mlist = new List <Models.Movie>(); if (!String.IsNullOrEmpty(title)) { results = APIConfiguration.ConnectAPI().SearchMovie(title); } foreach (SearchMovie result in results.Results) { TMDbLib.Objects.Movies.Movie trial = APIConfiguration.ConnectAPI().GetMovie(result.Id, MovieMethods.Videos); Models.Movie movie = new Models.Movie() { MovieID = result.Id, Poster = ConfigurationManager.AppSettings["PosterPath"] + result.PosterPath, Summary = result.Overview, Title = result.Title, URL = trial.Videos.Results.Count > 0 ? ConfigurationManager.AppSettings["YouTubePath"] + trial.Videos.Results[0].Key : ConfigurationManager.AppSettings["YouTubePath"] }; mlist.Add(movie); } return(mlist); } catch (Exception ex) { logger.Error(ex); throw; } }
public async Task <MovieResponse> UpdateAsync(int id, Models.Movie movie) { var existingMovie = await _moviesRepository.FindByIdAsync(id); if (existingMovie == null) { return(new MovieResponse("Movie not found.")); } existingMovie.Name = movie.Name; existingMovie.Code = movie.Code; existingMovie.Slug = movie.Slug; existingMovie.GenreId = movie.GenreId; try { _moviesRepository.Update(existingMovie); await _unitOfWork.CompleteAsync(); return(new MovieResponse(existingMovie)); } catch (Exception ex) { var message = $"An error occurred when updating the movie: {ex.Message}"; _logger.LogError(message); return(new MovieResponse(message)); } }
public ActionResult Save(Models.Movie movie) { if (!ModelState.IsValid) { var viewModel = new ViewModels.MovieFormViewModel(movie) { Genres = _context.Genres.ToList() }; return(View("MovieForm", viewModel)); } if (movie.Id == 0) { _context.Movies.Add(movie); } else { var movieInDb = _context.Movies.Single(c => c.Id == movie.Id); //Mapper.Map(movie,movieInDb); movieInDb.Name = movie.Name; movieInDb.NumberInStock = movie.NumberInStock; movieInDb.GenreId = movie.GenreId; movieInDb.ReleaseDate = movie.ReleaseDate; } _context.SaveChanges(); return(RedirectToAction("Index", "Movies")); }
// GET: Movies/Random public ActionResult Random() { var movie = new Models.Movie() { Name = "Rush Hour" }; //return View(movie); //return Content("Hello Diyi"); //return HttpNotFound(); //return new EmptyResult(); var customers = new List <Customer> { new Customer { Name = "Diyohan" }, new Customer { Name = "Melanie" } }; var RandomMovieModel = new ViewModels.RandomMovieView { Movie = movie, Customer = customers }; return(View(RandomMovieModel)); }
public Models.Movie Update(Models.Movie movieModel) { if (movieModel.Format == null) { throw new ArgumentNullException("Format", "The Format property must not be null."); } if (movieModel.Director == null) { throw new ArgumentNullException("Director", "The Director property must not be null."); } var existing = db.Movies.SingleOrDefault(x => x.Id == movieModel.Id); if (existing == null) { return(null); } existing.Cost = movieModel.Cost; existing.Description = movieModel.Description; existing.Title = movieModel.Title; existing.ImagePath = movieModel.ImagePath; Data.Director existingDirectors = db.Directors.SingleOrDefault(x => x.Id == movieModel.Director.Id); existing.Director = existingDirectors ?? throw new ArgumentException("The associated Director cannot be found."); Data.Format existingFormats = db.Formats.SingleOrDefault(x => x.Id == movieModel.Format.Id); existing.Format = existingFormats ?? throw new ArgumentException("The associated format cannot be found."); Data.Rating existingRatings = db.Ratings.SingleOrDefault(x => x.Id == movieModel.Rating.Id); existing.Rating = existingRatings ?? throw new ArgumentException("The associated Rating cannot be found."); db.SaveChanges(); return(movieModel); }
public ActionResult Delete(int id, FormCollection collection) { Models.Movie mm = m.Movies.Where(x => x.Id == id).First(); m.Movies.Remove(mm); m.SaveChanges(); return(RedirectToAction("Index")); }
internal List <Movie> GetListeMovie() { SqlConnection sqlConnection = new SqlConnection("Data Source=(LocalDB)\\MSSQLlocalDB;Initial Catalog=MovieDB;Integrated Security=True;Pooling=False"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "GetListeFilms"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = sqlConnection; sqlConnection.Open(); reader = cmd.ExecuteReader(); List <Models.Movie> result = new List <Models.Movie>(); while (reader.Read()) { Models.Movie item = new Models.Movie() { Id = (int)reader["id"], Title = reader["title"].ToString(), Genre = reader["genre"].ToString(), Year = (int)reader["year"], }; result.Add(item); } return(result); }
public MovieFormViewModel(Models.Movie movie) { Id = movie.Id; Name = movie.Name; ReleaseDate = movie.ReleaseDate; NumberInStock = movie.NumberInStock; GenreId = movie.GenreId; }
public int Create(Movie movie) { var dbItem = new Models.Movie(); Map(movie, dbItem); db.Movies.Add(dbItem); db.SaveChanges(); return dbItem.ID; }
public Movie Create(Movie movie) { var dbItem = new Models.Movie(); Map(movie, dbItem); db.Movies.Add(dbItem); db.SaveChanges(); return MapAll(new Models.Movie[] { dbItem }.AsQueryable()).Single(); }
// GET: Movies/Random public ActionResult Random() { // ActionResult is base calss for all action results in asp.net vc,return result as per reuest the data get in request // Action Results types var movie = new Models.Movie() { Name = "Life is Horror" }; var customersList = new List <Customer> { new Customer { Name = "Alex Murphy" }, new Customer { Name = "Rebbeca Oven" }, new Customer { Name = "Simon Lance" } }; //movie.Name = "Bad boy"; #region Passing Data to view // Data can be passed using simple view,Viewdata and ViewBag // Viewdata //ViewData["Movie"] = movie; // View Data //ViewBag.Mov = movie; //lViewBag.RandomMovie = movie; // Vidly.Models.Movie as output var randomMovieViewModel = new RandomMovieViewModel { movie = movie, customers = customersList }; return(View(randomMovieViewModel)); //return View(movie); #endregion // return View(movie); #region ActionResult Types // Content Result //return Content("This is content response"); // Not Found Result //return HttpNotFound(); // Empty Result //return new EmptyResult(); // redirect action without params //return RedirectToAction("Index", "Home"); // redirect action with params //return RedirectToAction("Index", "Home", new { page = 1, sortby = "name" }); // Ctrl+Shift+B to build application //return new ViewResult(); #endregion }
public void Post([FromBody] Models.Movie movie) { if (movie.ID == Guid.Empty) { movie.ID = Guid.NewGuid(); } movies.Add(movie); }
public IActionResult Edit([DataSourceRequest] DataSourceRequest request, Models.Movie movie) { if (movie != null && ModelState.IsValid) { _db.Movie.Update(movie); _db.SaveChanges(); } return(Json(new[] { movie }.ToDataSourceResult(request, ModelState))); }
public ActionResult UpdateMovieDetails(Models.Movie record) { DeltaXMapper <Models.Movie, Movie> mapobj = new DeltaXMapper <Models.Movie, Movie>(); DeltaXRepository obj = new DeltaXRepository(); var ActorsIdArray = record.ActorList.Split(','); var mov = obj.UpdateMovie(mapobj.Translate(record), ActorsIdArray); return(RedirectToAction("GetAllMovieDetails")); }
// PUT: api/Movies/5 //[HttpPut, Route("{id}")] public IHttpActionResult Put(int id, [FromBody] Models.Movie model) { if (ModelState.IsValid) { _db.Entry(AutoMapper.Mapper.Map <Trailer_NET_Library.Entities.Movie>(model)).State = EntityState.Modified; return(Ok()); } return(BadRequest(ModelState)); }
public ActionResult Delete([DataSourceRequest] DataSourceRequest request, Models.Movie movie) { if (movie != null) { _db.Remove(movie); _db.SaveChanges(); } return(Json(new[] { movie }.ToDataSourceResult(request, ModelState))); }
public IActionResult Index() { Models.Movie movie = new Models.Movie() { Title = "The Godfather", ReleaseDate = new DateTime(1972, 3, 24) }; return(View(movie)); }
public void Post([FromBody] Models.Movie duckbill) { if (duckbill.ID == Guid.Empty) { duckbill.ID = Guid.NewGuid(); } movies.Add(duckbill); }
// GET: movies/random public ActionResult Random() { var movie = new Models.Movie() { Name = "Shrek!" }; return(View(movie)); }
public static Movie ToServiceType(this Models.Movie movie) { return(new Movie { Title = movie.Title, Description = movie.Description, Year = movie.Year }); }
public ActionResult Create([Bind(Exclude = "id")] Models.Movie newmovie) { if (!ModelState.IsValid) { return(View()); } m.Movies.Add(newmovie); m.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Index() { // return Content("Hello, MVC World!"); Models.Movie movie = new Models.Movie() { Title = "The Godfather", ReleaseDate = new DateTime(1972, 3, 24) }; return(View(movie)); }
// GET: /<controller>/ public IActionResult Index() { Models.Movie movie = new Models.Movie() { Title = "El Padrino", ReleaseDate = new DateTime(1972, 3, 24) }; return(View(movie)); //return Content("Hello MVC World 2.1 ...usando Controllers!"); }