public ActionResult Edit(int?id = null) { var edit = _clubService.Get(id); var editVm = Mapper.Map <ClubEditModel>(edit); return(View(editVm)); }
public async Task SaveAndUpdateClub() { var stadiumsList = new List <Stadium> { new Stadium { Id = 1, Name = "Old Trafford", Capacity = 76000 } }; var countriesList = new List <Country> { new Country { Id = 1, Name = "England", Code = "EN" } }; var clubsList = new List <Club>(); var mockStadiumRepo = new Mock <IRepository <Stadium> >(); mockStadiumRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => stadiumsList.FirstOrDefault(c => c.Id == id)); var mockCountryRepo = new Mock <IRepository <Country> >(); mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id)); var mockClubRepo = new Mock <IRepository <Club> >(); mockClubRepo.Setup(r => r.All()).Returns(clubsList.AsQueryable()); mockClubRepo.Setup(r => r.AddAsync(It.IsAny <Club>())).Callback <Club>(club => clubsList.Add(new Club { Id = 1, Name = club.Name, Country = club.Country, HomeStadium = club.HomeStadium })); var clubService = new ClubService(mockClubRepo.Object, mockCountryRepo.Object, mockStadiumRepo.Object); var clubViewModel = new ClubViewModel { Name = "Manchester United", CountryId = 1, HomeStadiumId = 1 }; await clubService.CreateAsync(clubViewModel); var updatedViewModel = new ClubViewModel { Id = 1, Name = "Newcastle United", CountryId = 1, HomeStadiumId = 1 }; await clubService.UpdateAsync(updatedViewModel); var savedClub = clubService.Get(1); Assert.Equal(1, savedClub.Id); Assert.Equal("Newcastle United", savedClub.Name); }
public async Task SaveAndLoadClub() { var stadiumsList = new List <Stadium> { new Stadium { Id = 1, Name = "Old Trafford", Capacity = 76000 } }; var countriesList = new List <Country> { new Country { Id = 1, Name = "England", Code = "EN" } }; var clubsList = new List <Club>(); var mockStadiumRepo = new Mock <IRepository <Stadium> >(); mockStadiumRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => stadiumsList.FirstOrDefault(c => c.Id == id)); var mockCountryRepo = new Mock <IRepository <Country> >(); mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id)); var mockClubRepo = new Mock <IRepository <Club> >(); mockClubRepo.Setup(r => r.All()).Returns(clubsList.AsQueryable()); mockClubRepo.Setup(r => r.AddAsync(It.IsAny <Club>())).Callback <Club>(club => clubsList.Add(club)); mockClubRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => clubsList.FirstOrDefault(c => c.Id == id)); var clubService = new ClubService(mockClubRepo.Object, mockCountryRepo.Object, mockStadiumRepo.Object); var clubViewModel = new ClubViewModel { Name = "Manchester United", CountryId = 1, HomeStadiumId = 1, FoundedOn = DateTime.Now, CountryName = "England", HomeStadiumName = "Old Trafford" }; await clubService.CreateAsync(clubViewModel); var savedClub = clubService.Get(10, false); var lastSavedClub = clubService.GetAll().LastOrDefault(); Assert.Null(savedClub); Assert.Equal("Manchester United", lastSavedClub.Name); Assert.Equal("England", clubViewModel.CountryName); Assert.Equal("Old Trafford", clubViewModel.HomeStadiumName); Assert.NotNull(lastSavedClub.Country); Assert.NotNull(lastSavedClub.HomeStadium); }
public async Task <ActionResult> Select(int?id) { if (id == null) { return(NotFound()); } Club club = await _clubService.Get(Convert.ToInt32(id)); Seizoen seizoen = _seizoenService.GetByDatum(DateTime.Now); AbonnementCartVM item = new AbonnementCartVM { Club_ID = club.ClubId, Naam = club.Naam, Startdatum = seizoen.Startdatum, Einddatum = seizoen.Einddatum, Prijs = club.Stadion.Basisprijs * 8, DateCreated = DateTime.Now }; ShoppingCartVM shopping; if (HttpContext.Session.GetObject <ShoppingCartVM>("ShoppingCart") != null) { shopping = HttpContext.Session.GetObject <ShoppingCartVM>("ShoppingCart"); if (shopping.AbonnementCart == null) { shopping.AbonnementCart = new List <AbonnementCartVM>(); } } else { shopping = new ShoppingCartVM(); shopping.AbonnementCart = new List <AbonnementCartVM>(); } shopping.AbonnementCart.Add(item); HttpContext.Session.SetObject("ShoppingCart", shopping); return(RedirectToAction("Index", "ShoppingCart")); }
public ActionResult <List <Club> > Get() => _clubService.Get();