public ActionResult Create(RacerCreateViewModel model) { try { _racerService.AddNewRacer(model); return RedirectToAction("Index"); } catch { return View(model); } }
public void AddNewRacer(RacerCreateViewModel model) { using (var unit = new UnitOfWork()) { var horse = unit.Horse.Get(model.SelectedHorseId); var jockey = unit.Jockey.Get(model.SelectedJockeyId); var racer = new Racer { Horse = horse, Jockey = jockey, DateTimeStart = model.StartDateTime }; unit.Racer.Save(racer); } }
public RacerCreateViewModel GetRacerCreateViewModel() { var model = new RacerCreateViewModel(); using (var unit = new UnitOfWork()) { var horses = unit.Horse.GetAllHorses(); var jockeys = unit.Jockey.GetAllJockeys(); var listHorses = getHorsesListForDropdown(horses); var listJockeys = getJockeysListForDropdown(jockeys); model.ListHorsesForDropDown = listHorses; model.ListJockeysForDropDown = listJockeys; } return model; }