public ActionResult Results(EventResults model) { if (ModelState.IsValid) { foreach (var line in model.Teams) { var entry = db.EventTeamEntries.Find(line.EventTeamEntryId); entry.Points = line.Points; var riders = entry.EventRiderEntries.OrderBy(er => er.Id); riders.ElementAt(0).Participated = line.Rider1Participated; if (riders.Count() > 1) riders.ElementAt(1).Participated = line.Rider2Participated; if (riders.Count() > 2) riders.ElementAt(2).Participated = line.Rider3Participated; if (riders.Count() > 3) riders.ElementAt(3).Participated = line.Rider4Participated; if (riders.Count() == 5) riders.ElementAt(4).Participated = line.Rider5Participated; } db.SaveChanges(); return RedirectToAction("Index"); } //ViewBag.TeamId = new SelectList(db.Teams, "Id", "TeamName", model.TeamId); //ViewBag.EventId = new SelectList(db.Events, "Id", "EventName", model.EventId); return View(model); }
public ActionResult Results(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var model = new EventResults(); model.Teams= new List<TeamEntryResult>(); var e = db.Events.Find(id); model.EventType = e.EventType1.Type; foreach(var entry in e.EventTeamEntries.OrderBy(te=>te.Team==null?"":te.Team.TeamName)) { var line = new TeamEntryResult(); line.EventTeamEntryId = entry.Id; line.TeamName = entry.Team==null?"Independent Entrant": entry.Team.TeamName; line.EntryCategory = entry.Under17s ? "Under 17s" : "Open"; line.Points = entry.Points.GetValueOrDefault(); var riders = entry.EventRiderEntries.OrderBy(er => er.Id); line.Rider1Participated = riders.ElementAtOrDefault(0).Participated.GetValueOrDefault(true); line.Rider1Name = riders.ElementAtOrDefault(0).Rider.FullName; if (riders.Count() > 1) { line.Rider2Participated = riders.ElementAtOrDefault(1).Participated.GetValueOrDefault(true); line.Rider2Name = riders.ElementAtOrDefault(1).Rider.FullName; } if (riders.Count() > 2) { line.Rider3Participated = riders.ElementAtOrDefault(2).Participated.GetValueOrDefault(true); line.Rider3Name = riders.ElementAtOrDefault(2).Rider.FullName; } if (riders.Count() > 3) { line.Rider4Participated = riders.ElementAtOrDefault(3).Participated.GetValueOrDefault(true); line.Rider4Name = riders.ElementAtOrDefault(3).Rider.FullName; } if (riders.Count() == 5) { line.Rider5Participated = riders.ElementAtOrDefault(4).Participated.GetValueOrDefault(true); line.Rider5Name = riders.ElementAtOrDefault(4).Rider.FullName; } model.Teams.Add(line); } return View(model); }