Пример #1
0
 public ActionResult Edit(RacerEditViewModel model)
 {
     try
     {
         _racerService.EditRacer(model);
         return RedirectToAction("Index");
     }
     catch
     {
         ModelState.AddModelError(string.Empty, "Что-то пошло не так. Попробуйте ещё раз!");
         return View(model);
     }
 }
Пример #2
0
 public RacerEditViewModel GetRacerEditModel(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var racer = unit.Racer.Get(id);
         var horses = unit.Horse.GetAllHorses();
         var jockeys = unit.Jockey.GetAllJockeys();
         var model = new RacerEditViewModel
         {
             RacerId = racer.Id,
             StartDateTime = racer.DateTimeStart,
             ListHorsesForDropDown = getHorsesListForDropdown(horses),
             ListJockeysForDropDown = getJockeysListForDropdown(jockeys),
             SelectedHorseId = racer.Horse.Id,
             SelectedJockeyId = racer.Jockey.Id,
             EndDateTime = racer.DateTimeEnd
         };
         return model;
     }
 }
Пример #3
0
        public void EditRacer(RacerEditViewModel model)
        {
            using (var unit = new UnitOfWork())
            {
                var racer = unit.Racer.Get(model.RacerId);
                if (racer.Horse.Id != model.SelectedHorseId)
                {
                    var horse = unit.Horse.Get(model.SelectedHorseId);
                    racer.Horse = horse;
                }

                if (racer.Jockey.Id != model.SelectedJockeyId)
                {
                    var jockey = unit.Jockey.Get(model.SelectedJockeyId);
                    racer.Jockey = jockey;
                }

                if (model.EndDateTime != null)
                {
                    racer.DateTimeEnd = model.EndDateTime;
                }

                racer.DateTimeStart = model.StartDateTime;
                unit.Racer.Save(racer);
            }
        }