Example #1
0
        public ActionResult Create(TeamBindingModel bind)
        {
            if (ModelState.IsValid)
            {
                var team    = Mapper.Map <TeamBindingModel, Team>(bind);
                var country = this.db.Countries.Find(bind.CountryId);
                team.Country = country;
                var city = this.db.Cities.Find(bind.CityId);
                team.City = city;
                db.Teams.Add(team);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var availableCountries      = this.db.Countries.ToList();
            var availableCountriesModel =
                Mapper.Map <IEnumerable <Country>, IEnumerable <CountryBindingModel> >(availableCountries);
            var availableCities      = this.db.Cities.ToList();
            var availableCitiesModel =
                Mapper.Map <IEnumerable <City>, IEnumerable <CityBindingModel> >(availableCities);
            var model = new TeamBindingModel
            {
                AvailableCountries = availableCountriesModel,
                AvailableCities    = availableCitiesModel
            };

            return(View(model));
        }
Example #2
0
        public ActionResult Edit(PlayerBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var player = this.db.Players.Find(model.Id);
                player = Mapper.Map <PlayerBindingModel, Player>(model);
                this.db.Players.AddOrUpdate(a => a.Id, player);
                this.db.SaveChanges();

                player = this.db.Players.Find(model.Id);

                var country = this.db.Countries.Find(model.CountryId);
                player.Country = country;
                this.db.Entry(player.Country).State = EntityState.Modified;

                var city = this.db.Cities.Find(model.CityId);
                player.City = city;
                this.db.Entry(player.City).State = EntityState.Modified;

                var team = this.db.Teams.Find(model.TeamId);
                player.Team = team;
                this.db.Entry(player.Team).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
 public ActionResult Edit([Bind(Include = "Id, Name, Email, PasswordHash, PhoneNumber, DateAdded, UserName")] EditUserBindingModel bind)
 {
     if (ModelState.IsValid)
     {
         var registeredUser = Mapper.Map <EditUserBindingModel, RegisteredUser>(bind);
         db.Entry(registeredUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bind));
 }
Example #4
0
 private void CreateNoVenue(ESportsEventsContext context)
 {
     context.Venues.Add(new Venue()
     {
         Name = "No venue", Country = context.Countries.FirstOrDefault(c => c.Name == "No country"), City = context.Cities.FirstOrDefault(c => c.Name == "No city")
     });
     context.SaveChanges();
 }
Example #5
0
 private void CreateNoTeam(ESportsEventsContext context)
 {
     context.Teams.Add(new Team()
     {
         Name = "No team", Country = context.Countries.FirstOrDefault(c => c.Name == "No country"), City = context.Cities.FirstOrDefault(c => c.Name == "No city")
     });
     context.SaveChanges();
 }
Example #6
0
 private void CreateNoCountry(ESportsEventsContext context)
 {
     context.Countries.Add(new Country()
     {
         Name = "No country"
     });
     context.SaveChanges();
 }
Example #7
0
        public ActionResult Create(VenueBindingModel bind)
        {
            if (ModelState.IsValid)
            {
                var venue   = Mapper.Map <VenueBindingModel, Venue>(bind);
                var country = this.db.Countries.Find(bind.CountryId);
                venue.Country = country;
                var city = this.db.Cities.Find(bind.CityId);
                venue.City = city;
                db.Venues.Add(venue);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(bind));
        }
Example #8
0
        public ActionResult Create(EventBindingModel bind)
        {
            if (ModelState.IsValid)
            {
                //bind.Logo.Url = Constants.LogosFolderPath + bind.Logo.Url;
                var @event = Mapper.Map <EventBindingModel, Event>(bind);
                var season = this.db.Seasons.FirstOrDefault(s => s.Year == @event.EndDate.Value.Year);
                if (season == null)
                {
                    season = new Season {
                        Year = @event.EndDate.Value.Year
                    };
                }
                @event.Season = season;
                var country = this.db.Countries.Find(bind.CountryId);
                @event.Country = country;
                var city = this.db.Cities.Find(bind.CityId);
                @event.City = city;
                var venue = this.db.Venues.Find(bind.VenueId);
                @event.Venue = venue;
                db.Events.Add(@event);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var availableCountries      = this.db.Countries.ToList();
            var availableCountriesModel =
                Mapper.Map <IEnumerable <Country>, IEnumerable <CountryBindingModel> >(availableCountries);

            bind.AvailableCountries = availableCountriesModel;
            var availableCities      = this.db.Cities.ToList();
            var availableCitiesModel =
                Mapper.Map <IEnumerable <City>, IEnumerable <CityBindingModel> >(availableCities);

            bind.AvailableCities = availableCitiesModel;
            var venues = this.db.Venues;
            var availableVenuesModel = Mapper.Map <IEnumerable <Venue>, IEnumerable <VenueBindingModel> >(venues);

            bind.AvailableVenues = availableVenuesModel;

            return(View(bind));
        }