public ActionResult AddTrack(TrackModel model) { var newTrack = new Track { trackId = model.Id, trackName = model.trackName, location = model.location, fastestLap = model.fastestLap, fastestLapHolder = model.fastestLapHolder, pastWinner = model.pastWinner, trackImageUrl = model.imageUrl }; db.Tracks.InsertOnSubmit(newTrack); db.SubmitChanges(); return Redirect("/"); }
public ActionResult _EditTrackDetails(FormCollection collection) { /* This method determines which track the user wants to edit, populates a model and then send it on to the view */ var trackName = collection["lstTrack"]; /* Getting all the track information based on the selection made */ var track = (db.Tracks.Where(t => t.trackName == trackName)).Single(); var editTrack = new TrackModel { trackName = track.trackName, Id = track.trackId, fastestLap = track.fastestLap, fastestLapHolder = track.fastestLapHolder, location = track.location, pastWinner = track.pastWinner, imageUrl = track.trackImageUrl }; return PartialView("_EditTrackDetails", editTrack); }
public ActionResult AddTrack() { var trackModel = new TrackModel(); return View(trackModel); }
public ActionResult Index() { /* This method will pass two models to the view Index to use in the sidebar */ var drivers = (db.Drivers.Select(driver => new DriverModel { firstName = driver.firstName, lastName = driver.lastName, age = Convert.ToString(driver.age), weight = driver.weight, height = driver.height, nationality = driver.nationality, championshipsWon = driver.championshipsWon, profileImage = driver.profileImageUrl, championshipPoints = driver.championshipPoints, teamName = driver.Team.teamName })).OrderByDescending(d => d.championshipPoints); /* Selecting all the teams from the DB and ordering it by the championship points */ var constructors = (db.Teams.Select(team => new TeamModel { teamName = team.teamName, championshipPoints = team.championshipPoints })).OrderByDescending(t => t.championshipPoints); /* Select the next race date from the database */ var currentDate = @DateTime.Now; /* Selecting all the races from the RaceCalendar table and ordering them so that the first race of the season is on top */ var allRaces = db.RaceCalendars.Select(t => t).OrderBy(t => t.startDate); var nextRaceIndex = 0; var startDate = new DateTime(); var endDate = new DateTime(); foreach (var raceCalendar in allRaces) { var result = DateTime.Compare(raceCalendar.startDate, currentDate); if(result > 0) { /* The start date from the database is AFTER The current Date */ nextRaceIndex = raceCalendar.raceId; startDate = raceCalendar.startDate; endDate = raceCalendar.endDate; break; /* Jumping out of the for loop because we got the upcoming race so we can discard the rest of the data */ } } /* Creating a blank track model*/ var trackModel = new TrackModel(); var raceInformation = db.Tracks.Where(track => track.raceId == nextRaceIndex); foreach (var track in raceInformation) { /* There will only be one track in the loop */ trackModel.trackName = track.trackName; trackModel.location = track.location; trackModel.fastestLap = track.fastestLap; trackModel.fastestLapHolder = track.fastestLapHolder; trackModel.imageUrl = track.trackImageUrl; trackModel.pastWinner = track.pastWinner; } /* Coverting the LINQ to a list of tracks */ var nextTrack = new List<TrackModel>(); nextTrack.Add(trackModel); /* Converting the LINQ to a list of drivers */ List<DriverModel> allDrivers = drivers.ToList(); /* Converting the LINQ to a list of teams */ List<TeamModel> allTeams = constructors.ToList(); var model = new StandingsViewModel() { DriverModel = allDrivers, TeamModel = allTeams, TrackModels = nextTrack, StartDate = startDate, EndDate = endDate }; return View(model); }