Ejemplo n.º 1
0
        public void AddNewRace(RaceCreateViewModel model)
        {
            using (var unit = new UnitOfWork())
            {
                var race = new Race
                {
                    DateTimeOfRace  = DateTime.Parse(model.DateTimeOfRace),
                    NumberRaceInDay = Convert.ToInt32(model.NumberRaceInDay)
                };
                unit.Race.Save(race);

                foreach (var viewModel in model.Participants)
                {
                    var racer       = unit.Racer.Get(viewModel.RacerId);
                    var participant = new Participant
                    {
                        Race         = race,
                        Racer        = racer,
                        NumberInRace = viewModel.NumberInRace,
                        PlaceInRace  = viewModel.PlaceInRace
                    };
                    unit.Participant.Save(participant);
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult Create(RaceCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            work.RaceRepository.Create(RaceModel.GenerateRaceDTOFromModel(model.Race));
            work.Save();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Create(RaceCreateViewModel model)
        {
            if (model.Participants == null)
            {
                ModelState.AddModelError(string.Empty, "Заезд должен иметь участников!");
                model = _raceService.GetRaceCreateViewModel(DateTime.Parse(model.DateTimeOfRace), model.NumberRaceInDay);
                return(View(model));
            }

            _raceService.AddNewRace(model);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public RaceCreateViewModel GetRaceCreateViewModel(DateTime dateTime, string numberInDay = null)
        {
            using (var unit = new UnitOfWork())
            {
                var model        = new RaceCreateViewModel();
                var participants = unit.Racer.LoadRacers(
                    new RacerFilter
                {
                    WithHorse  = true,
                    WithJockey = true
                });
                model.ListParticipantsForDropdown = getPartisipantsListForDropdown(participants);
                model.DateTimeOfRace = dateTime.ToString("MM-dd-yyyy");
                if (!string.IsNullOrWhiteSpace(numberInDay))
                {
                    model.NumberRaceInDay = numberInDay;
                }

                return(model);
            }
        }
Ejemplo n.º 5
0
        public IActionResult Create()
        {
            var model = new RaceCreateViewModel();

            return(View(model));
        }