public ActionResult Index() { var movies = _database.GetAll(); return(View(movies.Select(m => m.ToModel()))); }
public ActionResult List() { var movies = _database.GetAll(); IEnumerable <Movie> sortMovies = from movie in movies orderby movie.Title ascending select movie; return(View(sortMovies.Select(p => p.ToModel()))); }
public ActionResult Edit(int id) { var movie = _database.GetAll().FirstOrDefault(p => p.Id == id); if (movie == null) { return(HttpNotFound()); } return(View(movie.ToModel())); }
private int RefreshUI() { //.ToArray -> extension method // Allows us to call a method like an instance method on a type that does not actually implement it // Adding functionality to type // 1. Open type and add new instance method - only works if you own the type // 2. Inherit from type - if base type allows inheritance and you are OK using the derived type // 3. Extension method - works with any type var movies = _movies.GetAll() .OrderBy(x => x.Name).ThenBy(x => x.ReleaseYear) .Select(x => x) //Transform .ToArray(); // Calling an extension method // 1. Just like an instance method var items = movies.ToArray(); _lstMovies.DataSource = items; // _lstMovies.DataSource = null; // _lstMovies.DataSource = _movies.GetAll(); //_lstMovies.DisplayMember = nameof(Movie.Name); //"Name" return(items.Length); }
//public static MemoryMovieDatabase database = _movie.GetAll(); //IMovieDatabase _movie2 = _movies.GetAll(); //bits from trying to get a dynamic error message to check for duplicate Title names.. // public void Ref2() { // _m = _movie2.GetAll(); RefreshUI(); // MainForm.RefreshUI(); IEnumerable <Movie> m = _movie2.GetAll(); // return _movie2.GetAll(); }
/// <summary>Get a movie by title.</summary> /// <param name="source">The source.</param> /// <param name="title">The movie title.</param> /// <returns>The movie, if found.</returns> public static Movie GetByTitle(this IMovieDatabase source, string title) { foreach (var item in source.GetAll()) { if (String.Compare(item.Title, title, true) == 0) { return(item); } } ; return(null); }
private int RefreshUI() { //.ToArray -> Extension methods // Allows us to call a method like an instnace method on a type thaty does not actually implement i t // Adding functinalty to a type // 1. Open type and ad new instance method - only works if you own the type // 2. Inherit from type - if abse typw allows inheritance and you are OK using the derived type // 3. Extension method - works with any type System.Collections.Generic.IEnumerable <Movie> movies = _movies.GetAll(); // Calling extension Method // 1. Just like an instance method var items = _movies.GetAll() .OrderBy(x => x.Name).ThenBy(x => x.ReleaseYear) .Select(x => x) // Transform .ToArray(); _lstMovies.DataSource = items; //_lstMovies.DataSource = null; //_lstMovies.DataSource = _movies.GetAll(); //_lstMovies.DisplayMember = nameof(Movie.Name); return(items.Length); }
private void RefreshMovies() { //OrderBy //var movies = _database.GetAll(); var movies = from m in _database.GetAll() orderby m.Name select m; _listMovies.Items.Clear(); //TODO: Hard Way //foreach (var movie in movies) //_listMovies.Items.Add(movie); _listMovies.Items.AddRange(movies.ToArray()); }
private IMovieDatabase _database; // = new SqlMovieDatabase(); private void RefreshMovies() { //OrderBy //var movies = _database.GetAll(); //LINQ syntax var movies = from m in _database.GetAll() orderby m.Name select m; _listMovies.Items.Clear(); // call clear //foreach (var movie in movies) // _listMovies.Items.Add(movie); _listMovies.Items.AddRange(movies.ToArray()); //Addrange method require array }
private void RefreshList() { _bsMovies.DataSource = _database.GetAll().ToList(); }
public ActionResult List() { var movies = _database.GetAll(); return(View(movies.Select(p => p.ToModel()))); }