Example #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);
                }
            }
        }
Example #2
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;
            }
        }