예제 #1
0
        public IActionResult CountryList(string id = "All")
        {
            var sports = context.Sports
                         .OrderBy(s => s.SportID).ToList();

            var games = context.Games
                        .OrderBy(g => g.GameID).ToList();

            List <Country> countries;

            if (id == "All")
            {
                countries = context.Countries
                            .OrderBy(c => c.CountryID).ToList();
            }
            else
            {
                countries = context.Countries
                            .Where(c => c.Sport.SportName == id)
                            .OrderBy(c => c.CountryID).ToList();
            }

            var model = new CountryListViewModel
            {
                Sports          = sports,
                Games           = games,
                Countries       = countries,
                SelectedCountry = id
            };

            return(View(model));
        }
예제 #2
0
        public void Index_Contains_All_Countries()
        {
            // Arrange - create the mock repository
            Mock <IItemRepository> mock = new Mock <IItemRepository>();

            mock.Setup(m => m.Countries).Returns(new Country[]
            {
                new Country {
                    CountryID = 1, Name = "P1"
                },
                new Country {
                    CountryID = 2, Name = "P2"
                },
                new Country {
                    CountryID = 3, Name = "P3"
                },
            }.AsQueryable <Country>());

            // Arrange - create a controller
            CountryController target = new CountryController(mock.Object);

            // Action
            CountryListViewModel result = target.List(1).ViewData.Model as CountryListViewModel;

            //Country[] result = GetViewModel<CountryListViewModel>(target.List())?.ToArray();

            // Assert
            Assert.Equal(3, result.Countries.Count());
            Assert.Equal("P1", result.Countries[0].Name);
            Assert.Equal("P2", result.Countries[1].Name);
            Assert.Equal("P3", result.Countries[2].Name);
        }
예제 #3
0
        public IActionResult Index(CountryListViewModel model)
        {
            model.Games      = context.Games.ToList();
            model.Categories = context.Categories.ToList();
            string activeGame = model.ActiveGame;
            string activeCat  = model.ActiveCat;

            IQueryable <Country> query = context.Countries;

            if (activeGame != "all")
            {
                query = query.Where(
                    c => c.Game.GameID.ToLower() == activeGame.ToLower()
                    );
            }

            if (activeCat != "all")
            {
                query = query.Where(
                    c => c.Category.CategoryID.ToLower() == activeCat.ToLower()
                    );
            }

            model.Countries = query.ToList();
            return(View(model));
        }
예제 #4
0
 public CountryListView(IRepositoryFactory factory)
 {
     InitializeComponent();
     _factory    = factory;
     Model       = new CountryListViewModel(factory);
     DataContext = Model;
 }
예제 #5
0
 private void InitializeModels()
 {
     FilmModel     = new FilmListViewModel(this);
     PersonModel   = new PersonListViewModel(this);
     CountryModel  = new CountryListViewModel(this);
     LocationModel = new LocationListViewModel(this);
 }
예제 #6
0
        public ActionResult Details(CountryListViewModel model, string command)
        {
            model.Country = model.Countries.FirstOrDefault(i => i.CountryID == command);

            TempData["ActiveSport"] = model.ActiveSport;
            TempData["ActiveGame"]  = model.ActiveGame;
            return(RedirectToAction("Details", new { ID = model.Country.CountryID }));
        }
예제 #7
0
 public CountryView(CountryListViewModel model)
 {
     InitializeComponent();
     Model       = model;
     Country     = Model.CurrentCountry;
     DataContext = Country;
     nameTextBox.Focus();
 }
예제 #8
0
 public CountryController(IViewService viewService, IEntityService entityService, CountryListViewModel countryListViewModel, CountryViewModel countryViewModel)
 {
     _viewService          = viewService;
     _entityService        = entityService;
     _countryListViewModel = countryListViewModel;
     _countryViewModel     = countryViewModel;
     _addNewCommand        = new DelegateCommand(AddNewCountry_OnExecute, AddNewCountry_OnCanExecute);
     _removeCommand        = new DelegateCommand(RemoveCountry_OnExecute, RemoveCountry_OnCanExecute);
 }
예제 #9
0
        public CountryListViewModel GetCountryListViewModel()
        {
            var all   = _countryRepository.All().ToList();
            var model = new CountryListViewModel
            {
                Countries = all
            };

            return(model);
        }
예제 #10
0
        public UIElement GetDisplayElement()
        {
            CountryListViewModel viewModel = new CountryListViewModel(this, facade);
            CountryListControl   control   = new CountryListControl(viewModel);

            viewModel.CountrySelected      += (s, e) => EditCountry(e.CountryName);
            viewModel.CountryDeleteRequest += (s, e) => Delete(e.CountryName);

            return(control);
        }
예제 #11
0
        public IActionResult Countries(CountryListViewModel model)
        {
            var session = new OSession(HttpContext.Session);

            session.SetActiveGame(model.ActiveGame);
            session.SetActiveSport(model.ActiveSport);

            // if no count value in session, use data in cookie to restore fave teams in session
            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new OCookies(HttpContext.Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(t => t.Game)
                                  .Include(t => t.Sport)
                                  .Where(t => ids.Contains(t.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }


            //Updated to complex model binding

            /*var data = new CountryListViewModel
             * {
             *  ActiveGame= model.ActiveGame,
             *  ActiveSport = model.ActiveSport,
             *  Games = context.Games.ToList(),
             *  Sports = context.Sports.ToList()
             * };*/

            model.Games  = context.Games.ToList();
            model.Sports = context.Sports.ToList();

            IQueryable <Country> query = context.Countries;

            if (model.ActiveGame != "all")
            {
                query = query.Where(
                    t => t.Game.GameID.ToLower() == model.ActiveGame.ToLower());
            }
            if (model.ActiveSport != "all")
            {
                query = query.Where(
                    t => t.Sport.SportID.ToLower() == model.ActiveSport.ToLower());
            }
            model.Countries = query.ToList();

            return(View(model));
        }
예제 #12
0
        public IActionResult Index(CountryListViewModel model)
        {
            var session = new CountrySession(HttpContext.Session);

            session.SetActiveGame(model.ActiveGame);
            session.SetActiveSport(model.ActiveSport);
            session.SetActiveCategory(model.ActiveCategory);

            // if no count value in session, use data in cookie to restore fave Countries in session
            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new CountryCookies(HttpContext.Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> myCountries = new List <Country>();
                if (ids.Length > 0)
                {
                    myCountries = context.Countries.Include(c => c.Game)
                                  .Include(c => c.Sport)
                                  .Include(c => c.Category)
                                  .Where(c => ids.Contains(c.CountryId)).ToList();
                }
                session.SetMyCountries(myCountries);
            }


            model.Games      = context.Games.ToList();
            model.Sports     = context.Sports.ToList();
            model.Categories = context.Categories.ToList();


            IQueryable <Country> query = context.Countries;

            if (model.ActiveGame != "all")
            {
                query = query.Where(
                    c => c.Game.GameId.ToLower() == model.ActiveGame.ToLower());
            }
            if (model.ActiveSport != "all")
            {
                query = query.Where(
                    c => c.Sport.SportId.ToLower() == model.ActiveSport.ToLower());
            }
            if (model.ActiveCategory != "all")
            {
                query = query.Where(
                    c => c.Category.CategoryId.ToLower() == model.ActiveCategory.ToLower());
            }
            model.Countries = query.ToList();

            return(View(model));
        }
예제 #13
0
        public RedirectToActionResult Change(CountryListViewModel model)
        {
            var session = new OSession(HttpContext.Session);

            session.SetName(model.UserName);
            return(RedirectToAction("Countries", "Olympics", new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport()
            }));
        }
        public async Task <IActionResult> GetAllCountriesFromDb()
        {
            var countries = await _countrySearchService.GetAllCountriesFromDb();

            var countryListViewModel = new CountryListViewModel
            {
                Countries = countries
            };

            return(View(countryListViewModel));
        }
예제 #15
0
        public RedirectToActionResult Change(CountryListViewModel model)
        {
            var session = new CountrySession(HttpContext.Session);

            session.SetName(model.UserName);
            return(RedirectToAction("Index", "Home", new
            {
                ActiveGame = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport(),
                ActiveCategory = session.GetActiveCategory()
            }));
        }
예제 #16
0
        public ViewResult Index(CountryListViewModel model)
        {
            model.Sports = context.Sports.ToList();
            model.Games  = context.Games.ToList();

            //New changes-pg.339.  Updates for Chapter 9 for session states
            var session = new OlympicSession(HttpContext.Session);

            session.SetActiveGame(model.ActiveGame);
            session.SetActiveSport(model.ActiveSport);

            int?count = session.GetMyCountryCount();


            if (count == null)
            {
                var      cookies = new OlympicCookies(HttpContext.Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(c => c.Game)
                                  .Include(c => c.Sport)
                                  .Where(c => ids.Contains(c.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }

            //var data = new CountryListViewModel
            //{
            //    ActiveGame = activeGame,
            //    ActiveSport = activeSport,
            //    Games = context.Games.ToList(),
            //    Sports = context.Sports.ToList()
            //};

            IQueryable <Country> query = context.Countries;

            if (model.ActiveGame != "all")
            {
                query = query.Where(
                    c => c.Game.GameID.ToLower() == model.ActiveGame.ToLower());
            }
            if (model.ActiveSport != "all")
            {
                query = query.Where(c =>
                                    c.Sport.SportID.ToLower() == model.ActiveSport.ToLower());
            }
            model.Countries = query.ToList();

            return(View(model));
        }
예제 #17
0
        public ViewResult Index()
        {
            var session = new OlympicsSession(HttpContext.Session);
            var model   = new CountryListViewModel
            {
                ActiveCat  = session.GetActiveCat(),
                ActiveGame = session.GetActiveGame(),
                Countries  = session.GetMyCountries()
            };

            return(View(model));
        }
예제 #18
0
        public IActionResult Index(CountryListViewModel model)
        {
            model.Categories = context.Categories.ToList();
            model.Games      = context.Games.ToList();
            model.Sports     = context.Sports.ToList();

            var session = new OlympicSession(HttpContext.Session);

            session.SetActiveGame(model.ActiveGame);
            session.SetActiveCatg(model.ActiveCatg);
            session.SetActiveSport(model.ActiveSport);

            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new OlympicCookies(Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(t => t.Game)
                                  .Include(t => t.Category)
                                  .Include(t => t.Sport)
                                  .Where(t => ids.Contains(t.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }


            IQueryable <Country> query = context.Countries;

            if (model.ActiveGame != "all")
            {
                query = query.Where(
                    t => t.Game.GameID.ToLower() == model.ActiveGame.ToLower());
            }
            if (model.ActiveCatg != "all")
            {
                query = query.Where(
                    t => t.Category.CategoryID.ToLower() == model.ActiveCatg.ToLower());
            }
            if (model.ActiveSport != "all")
            {
                query = query.Where(
                    t => t.Sport.SportID.ToLower() == model.ActiveSport.ToLower());
            }
            model.Countries = query.ToList();

            return(View(model));
        }
예제 #19
0
        public ViewResult Countries()
        {
            var session = new OSession(HttpContext.Session);
            var model   = new CountryListViewModel
            {
                ActiveGame  = session.GetActiveGame(),
                ActiveSport = session.GetActiveSport(),
                Countries   = session.GetMyCountries(),
                UserName    = session.GetName()
            };

            return(View(model));
        }
예제 #20
0
        public ViewResult Index(CountryListViewModel model)
        {
            List <Country> Countries  = context.Countries.OrderBy(c => c.Name).ToList();
            List <string>  games      = new List <string>();
            List <string>  categories = new List <string>();

            // Make a collection of all games and catgories in use
            foreach (Country country in Countries)
            {
                // Dynamically collect all possible games
                if (!games.Contains(country.Game))
                {
                    games.Add(country.Game);
                }

                // Dynamically collect all possible categories
                if (!categories.Contains(country.Category))
                {
                    categories.Add(country.Category);
                }
            }

            var session = new OlympicSession(HttpContext.Session);

            // If no count in session, get cookie and restore favorite teams in session
            int?count = session.GetMyCountriesCount();

            if (count == null)
            {
                var      cookies = new FavoriteCookies(Request.Cookies);
                string[] ids     = cookies.GetMyFavorites();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    foreach (string id in ids)
                    {
                        mycountries.Add(context.Countries.Where(c => c.Name == id).FirstOrDefault());
                    }
                }
                session.SetMyFavs(mycountries);
            }

            model.Countries      = Countries;
            model.Games          = games;
            model.Categories     = categories;
            model.ActiveGame     = RouteData.Values?["ActiveGame"]?.ToString();
            model.ActiveCategory = RouteData.Values?["ActiveCategory"]?.ToString();

            return(View(model));
        }
예제 #21
0
        public App()
        {
            // All that manual initialization stuff should be done automatically
            var viewModel = new CountryListViewModel();

            viewModel.Initialize(null);

            var list = new CountryListPage();

            list.SetViewModel(viewModel);

            MainPage = new NavigationPage(list);

            // Workaround
            ViewModelBase.Presenter = new FormsPresenter(Current.MainPage.Navigation);
        }
예제 #22
0
        public IActionResult Index(CountryListViewModel model)
        {
            model.Categories = context.Categories.ToList();
            model.Games      = context.Games.ToList();

            var session = new CountrySession(HttpContext.Session);

            session.SetActiveCat(model.ActiveCat);
            session.SetActiveGam(model.ActiveGam);

            // if no count value in session, use data in cookie to restore fave teams in session
            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new CountryCookies(Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(t => t.Category)
                                  .Include(t => t.Game)
                                  .Where(t => ids.Contains(t.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }


            IQueryable <Country> query = context.Countries;

            if (model.ActiveCat != "all")
            {
                query = query.Where(
                    t => t.Category.CategoryID.ToLower() == model.ActiveCat.ToLower());
            }
            if (model.ActiveGam != "all")
            {
                query = query.Where(
                    t => t.Game.GameID.ToLower() == model.ActiveGam.ToLower());
            }
            model.Countries = query.ToList();

            return(View(model));
        }
예제 #23
0
        public void Pagination_Properly_Working_Countries()
        {
            // Arrange - create the mock repository
            Mock <IItemRepository> mock = new Mock <IItemRepository>();

            mock.Setup(m => m.Countries).Returns(new Country[]
            {
                new Country {
                    CountryID = 1, Name = "P1"
                },
                new Country {
                    CountryID = 2, Name = "P2"
                },
                new Country {
                    CountryID = 3, Name = "P3"
                },
                new Country {
                    CountryID = 4, Name = "PX"
                },
                new Country {
                    CountryID = 5, Name = "P4"
                },
                new Country {
                    CountryID = 6, Name = "P5"
                },
            }.AsQueryable <Country>());

            // Arrange - create a controller
            CountryController target = new CountryController(mock.Object);

            // Action
            CountryListViewModel result  = target.List(1).ViewData.Model as CountryListViewModel; //Request a List for the first page
            CountryListViewModel result2 = target.List(2).ViewData.Model as CountryListViewModel; //Request a List for the second page

            // Assert
            Assert.Equal(4, result.Countries.Count());
            Assert.Equal("P1", result.Countries[0].Name);
            Assert.Equal("P2", result.Countries[1].Name);
            Assert.Equal("P3", result.Countries[2].Name);
            Assert.Equal("PX", result.Countries[3].Name);
            Assert.Equal(2, result2.Countries.Count());
            Assert.Equal("P4", result2.Countries[0].Name);
            Assert.Equal("P5", result2.Countries[1].Name);
        }
예제 #24
0
        public ViewResult Index(CountryListViewModel listModel)
        {
            var session = new OlympicsSession(HttpContext.Session);

            session.SetActiveCat(listModel.ActiveCat);
            session.SetActiveGame(listModel.ActiveGame);

            // if no count in session, get cookie and restore fave countries in session
            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new OlympicsCookies(Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(t => t.Category)
                                  .Include(t => t.Game)
                                  .Where(t => ids.Contains(t.CountryID)).ToList();
                }
                session.SetMyCountries(mycountries);
            }

            listModel.Categories = context.Categories.ToList();
            listModel.Games      = context.Games.ToList();

            IQueryable <Country> query = context.Countries;

            if (listModel.ActiveCat != "all")
            {
                query = query.Where(
                    t => t.Category.CategoryID.ToLower() == listModel.ActiveCat.ToLower());
            }
            if (listModel.ActiveGame != "all")
            {
                query = query.Where(
                    t => t.Game.GameID.ToLower() == listModel.ActiveGame.ToLower());
            }
            listModel.Countries = query.ToList();
            return(View(listModel));
        }
예제 #25
0
        public ViewResult Index(string activeGame = "0", string activeCat = "0")
        {
            var session = new CountrySession(HttpContext.Session);

            session.SetActiveGame(activeGame);
            session.SetActiveCat(activeCat);

            int?count = session.GetMyCountryCount();

            if (count == null)
            {
                var      cookies = new CountryCookies(Request.Cookies);
                string[] ids     = cookies.GetMyCountryIds();

                List <Country> mycountries = new List <Country>();
                if (ids.Length > 0)
                {
                    mycountries = context.Countries.Include(t => t.GameType).Include(t => t.Category).Where(t => ids.Contains(t.CountryId)).ToList();
                }
                session.SetMyCountries(mycountries);
            }

            var model = new CountryListViewModel
            {
                ActiveGame = activeGame,
                ActiveCat  = activeCat,
                Games      = context.GameTypes.ToList(),
                Categories = context.Categories.ToList()
            };
            IQueryable <Country> query = context.Countries;

            if (activeGame != "0")
            {
                query = query.Where(t => t.GameType.GameTypeId.ToString() == activeGame);
            }
            if (activeCat != "0")
            {
                query = query.Where(t => t.Category.CategoryId.ToString() == activeCat);
            }
            model.Countries = query.ToList();
            return(View(model));
        }
예제 #26
0
        public ActionResult List(int page     = 1,
                                 int PageSize = 12)
        {
            var countries = countriesService.GetAll();

            var countriesListModel = new CountryListViewModel
            {
                Countries = countries
                            .Skip((page - 1) * PageSize)
                            .Take(PageSize),
                PageViewModel = new PageViewModel
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = countries.Count()
                }
            };

            ViewBag.IsAdmin = HttpContext.User.IsInRole("Administrator");

            return(View(countriesListModel));
        }
예제 #27
0
        public async Task <IActionResult> CountryIndex(string search = "")
        {
            List <CountryListViewModel> model = new List <CountryListViewModel>();
            var dbData = await _unitOfWork.Repository <Country>().GetAllIncludeAsync(x => x.Cities);

            if (!String.IsNullOrEmpty(search))
            {
                dbData = dbData.Where(x => x.Name.ToLower().Contains(search.ToLower())).ToList();
                ViewBag.SearchString = search;
            }

            foreach (var b in dbData)
            {
                CountryListViewModel country = new CountryListViewModel
                {
                    Id          = b.Id,
                    Name        = b.Name,
                    TotalCities = b.Cities.Count
                };
                model.Add(country);
            }

            return(View(model));
        }
예제 #28
0
        public ViewResult Index(string activeGame = "all", string activeSport = "all")
        {
            var data = new CountryListViewModel
            {
                ActiveGame  = activeGame,
                ActiveSport = activeSport,
                Games       = context.Games.ToList(),
                Sports      = context.Sports.ToList()
            };

            IQueryable <Country> query = context.Countries;

            if (activeGame != "all")
            {
                query = query.Where(t => t.Game.GameID.ToLower() == activeGame.ToLower());
            }
            if (activeSport != "all")
            {
                query = query.Where(t => t.Sport.SportID.ToLower() == activeSport.ToLower());
            }

            data.Countries = query.ToList();
            return(View(data));
        }
예제 #29
0
 public CountryListControl(CountryListViewModel viewModel)
 {
     InitializeComponent();
     this.DataContext = viewModel;
 }