internal Form RenderMainView() { InitSearchView(); catalogView = new CatalogView(moviesGridViewModel, new DirectorsAutocompleteSource(directorRepository), new ActorsAutocompleteSource(actorRepository)); catalogView.RefillDatabase += (async() => { await actorRepository.DropAll(); await directorRepository.DropAll(); await movieRepository.DropAll(); await DefaultDataHelper.FillRepositories(movieRepository, directorRepository, actorRepository); GetMovies(); }); catalogView.SaveMovie += SaveMovie; catalogView.DeleteFilm += DeleteMovie; catalogView.EditFilm += (List <Movie> selected) => { if (selected.Count > 0) { var movie = selected[0]; editMovieViewModel = new EditMovieViewModel(); catalogView.ShowMovieEditForm(editMovieViewModel); editMovieViewModel.MovieId = movie.MovieId; editMovieViewModel.Name = movie.Name; editMovieViewModel.Year = movie.Year; editMovieViewModel.Country = movie.Country; editMovieViewModel.Image = movie.Image; editMovieViewModel.Actors = new List <Actor>(movie.Actors); editMovieViewModel.Director = movie.Director; } }; catalogView.AddMovieActor += (async(name) => { var query = actorRepository.GetAll().Where(actor => actor.Name == name); var foundActor = (await actorRepository.ToListAsync(query)).FirstOrDefault(); if (foundActor != null) { editMovieViewModel.Actors.Add(foundActor); } else { var newActor = new Actor() { Name = name }; await actorRepository.Save(newActor); editMovieViewModel.Actors.Add(newActor); } }); catalogView.FindFilm += (() => { if (searchView.IsDisposed) { InitSearchView(); } searchView.Show(); searchView.Activate(); searchView.Left = catalogView.Left + catalogView.Width / 2 - searchView.Width / 2; catalogView.FindMovieMenuItem.Checked = true; catalogView.ExitMenuItem.Enabled = false; }); catalogView.GoBack += (() => { GetMovies(); catalogView.ShowMovieGrid(); }); catalogView.AboutOpen += (() => { var aboutView = new AboutView(); aboutView.ShowDialog(); }); catalogView.DeleteActor += ((position) => { editMovieViewModel.ActorsRemoveAt(position); }); getMovies.OnStarted += (() => { catalogView.SetEnabledState(false); catalogView.SetGridStatus(false); catalogView.SetGridTitle(Properties.Resources.GridTitleLoading); }); GetMovies(); return(catalogView); }