Esempio 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);
                }
            }
        }
Esempio n. 2
0
 public Role GetUserRole(string username)
 {
     using (var unit = new UnitOfWork())
     {
         var user = unit.User.GetUserByUsername(username);
         return user.Role;
     }
 }
Esempio n. 3
0
 public IList<Horse> GetListHorses()
 {
     using (var unit = new UnitOfWork())
     {
         var horses = unit.Horse.GetAllHorses();
         return horses;
     }
 }
Esempio n. 4
0
 public void DeleteHorse(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var horse = unit.Horse.Get(id);
         unit.Horse.Delete(horse);
     }
 }
Esempio n. 5
0
 public bool IsUserInRole(string username, string roleName)
 {
     using (var unit = new UnitOfWork())
     {
         var user = unit.User.GetUserByUsername(username);
         var isUserInRole = user.Role.Name.ToUpperInvariant() == roleName.ToUpperInvariant();
         return isUserInRole;
     }
 }
Esempio n. 6
0
 public void EditHorse(HorseViewModel model)
 {
     using (var unit = new UnitOfWork())
     {
         var horse = unit.Horse.Get(model.HorseId);
         horse.Nickname = model.Nickname;
         horse.DateBirth = DateTime.Parse(model.DateBirth);
         unit.Horse.Save(horse);
     }
 }
Esempio n. 7
0
 public IList<RacerViewModel> GetListRacers()
 {
     var list = new List<RacerViewModel>();
     using (var unit = new UnitOfWork())
     {
         var racers = unit.Racer.LoadRacers(new RacerFilter { WithHorse = true });
         list.AddRange(racers.Select(getRacerViewModel));
         return list;
     }
 }
Esempio n. 8
0
 public void AddNewHorse(HorseViewModel model)
 {
     using (var unit = new UnitOfWork())
     {
         var horse = new Horse
         {
             Nickname = model.Nickname,
             DateBirth = DateTime.Parse(model.DateBirth)
         };
         unit.Horse.Save(horse);
     }
 }
Esempio n. 9
0
 public void EditJockey(JockeyViewModel model)
 {
     using (var unit = new UnitOfWork())
     {
         var jockey = unit.Jockey.Get(model.JockeyId);
         jockey.Alias = model.Alias;
         jockey.DateBirth = DateTime.Parse(model.DateBirth);
         jockey.FirstName = model.FirstName;
         jockey.LastName = model.LastName;
         jockey.MiddleName = model.LastName;
         unit.Jockey.Save(jockey);
     }
 }
Esempio n. 10
0
 public void ChangePassword(int userId, string password)
 {
     using (var unit = new UnitOfWork())
     {
         var user = unit.User.Get(userId);
         var salt = _cryptoProvider.CreateSalt();
         user.Password = new Credentials
                         {
                             Salt = salt, 
                             PasswordHash = _cryptoProvider.CreateCryptoPassword(password, salt)
                         };
         unit.User.SaveUser(user);
     }
 }
Esempio n. 11
0
 public HorseViewModel GetHorseDetails(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var horse = unit.Horse.Get(id);
         var model = new HorseViewModel
         {
             HorseId = horse.Id,
             DateBirth = _generalService.GetDateTimeStringForDatepicker(horse.DateBirth),
             Nickname = horse.Nickname
         };
         return model;
     }
 }
Esempio n. 12
0
 public void AddNewJockey(JockeyViewModel model)
 {
     using (var unit = new UnitOfWork())
     {
         var jockey = new Jockey
         {
             Alias = model.Alias,
             DateBirth = DateTime.Parse(model.DateBirth),
             FirstName = model.FirstName,
             LastName = model.LastName,
             MiddleName = model.MiddleName
         };
         unit.Jockey.Save(jockey);
     }
 }
Esempio n. 13
0
 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);
     }
 }
Esempio n. 14
0
        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;
        }
Esempio n. 15
0
 public List<HorseParticipationViewModel> SelectHorseParticipation()
 {
     var model = new List<HorseParticipationViewModel>();
     using (var unit = new UnitOfWork())
     {
         var allHorses = unit.Horse.GetAllHorses();
         var participants = unit.Participant.LoadParticipants(new ParticipantFilter {WithHorse = true});
         model.AddRange(allHorses.Select(horse => new HorseParticipationViewModel
             {
                 HorseId = horse.Id, 
                 HorseNickname = horse.Nickname, 
                 RaceQuantity = participants.Count(x => x.Racer.HorseId == horse.Id)
             }));
     }
     return model;
 }
Esempio n. 16
0
 public JockeyViewModel GetJockeyDetails(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var jockey = unit.Jockey.Get(id);
         var model = new JockeyViewModel
         {
             JockeyId = jockey.Id,
             Alias = jockey.Alias,
             DateBirth = _generalService.GetDateTimeStringForDatepicker(jockey.DateBirth),
             FirstName = jockey.FirstName,
             LastName = jockey.LastName,
             MiddleName = jockey.MiddleName
         };
         return model;
     }
 }
Esempio n. 17
0
 public RacerDetailsViewModel GetRacerDetails(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var racer = unit.Racer.Get(id);
         var model = new RacerDetailsViewModel
                     {
                         RacerId = racer.Id,
                         HorseNickname = racer.Horse.Nickname,
                         JockeyAlias = racer.Jockey.Alias,
                         JokeyFullName = racer.Jockey.FullName,
                         RacerDateTimeEnd = racer.DateTimeEnd.HasValue ? ((DateTime)racer.DateTimeEnd).ToShortDateString() : "-",
                         RacerDateTimeStart = racer.DateTimeStart.ToShortDateString()
                     };
         return model;
     }
 }
Esempio n. 18
0
        public IEnumerable<JockeyViewModel> GetListJokeys()
        {
            using (var unit = new UnitOfWork())
            {
                var jockeys = unit.Jockey.GetAllJockeys();
                var jockeysList = jockeys.Select(
                    jockey => new JockeyViewModel
                    {

                        Alias = jockey.Alias,
                        DateBirth = _generalService.GetDateTimeStringForDatepicker(jockey.DateBirth),
                        FirstName = jockey.FirstName,
                        JockeyId = jockey.Id,
                        LastName = jockey.LastName,
                        MiddleName = jockey.MiddleName
                    });
                return jockeysList;
            }
        }
Esempio n. 19
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;
     }
 }
Esempio n. 20
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;
            }
        }
Esempio n. 21
0
        public IEnumerable<RaceViewModel> GetListRaces()
        {
            using (var unit = new UnitOfWork())
            {
                var model = new List<RaceViewModel>();
                var allRaces = unit.Race.GetAllRaces();
                foreach (var race in allRaces)
                {

                    var participants = getParticipantsViewModelsList(unit, race.Id);
                    model.Add(
                        new RaceViewModel
                            {
                                RaceId = race.Id,
                                RaceDateTime = _generalService.GetDateTimeStringForDatepicker(race.DateTimeOfRace),
                                RaceNumberInDay = race.NumberRaceInDay.ToString(CultureInfo.InvariantCulture),
                                Participants = participants
                            });
                }

                return model;
            }
        }
Esempio n. 22
0
        public List<ParticipantViewModel> GetParticipantsForRace(DateTime raceDate, int raceNumber)
        {
            using (var unit = new UnitOfWork())
            {
                var race = unit.Race.GetRace(raceDate, raceNumber);
                if (race == null)
                {
                    return null;
                }

                var list = getParticipantsViewModelsList(unit, race.Id);
                return list;
            }
        }
Esempio n. 23
0
 public void DeleteJockey(int id)
 {
     using (var unit = new UnitOfWork())
     {
         var jockey = unit.Jockey.Get(id);
         unit.Jockey.Delete(jockey);
     }
 }
Esempio n. 24
0
 public List<WinnerJockeyForYearViewModel> GetWinnerJokeysForYear(int year)
 {
     using (var unit = new UnitOfWork())
     {
         var participants = unit.Participant.GetWinnersForYear(year);
         var model = participants.Select(participant => new WinnerJockeyForYearViewModel
             {
                 JockeyId = participant.Racer.JockeyId,
                 JockeyAlias = participant.Racer.Jockey.Alias,
                 QuantityWinnerRaces = unit.Participant.GetCountWinnerRaces(participant.Id),
                 JockeyFullName = participant.Racer.Jockey.FullName
             }).OrderByDescending(x => x.JockeyFullName).ToList();
         return model;
     }
 }
Esempio n. 25
0
        public RaceDetailsViewModel GetRaceDetailsViewModel(int id)
        {
            using (var unit = new UnitOfWork())
            {
                var race = unit.Race.Get(id);
                var model = getRaceDetailsViewModelWithoutParticipants(race);
                model.Participants = new List<ParticipantViewModel>();
                var participants = unit.Participant.LoadParticipants(new ParticipantFilter { RaceId = race.Id, WithRacerHorceAndJockey = true });
                foreach (var participant in participants)
                {
                    model.Participants.Add(new ParticipantViewModel
                    {
                        HorseId = participant.Racer.Horse.Id,
                        HorseNickname = participant.Racer.Horse.Nickname,
                        ParticipantId = participant.Id,
                        RacerId = participant.Racer.Id,
                        JockeyId = participant.Racer.Jockey.Id,
                        JockeyAlias = participant.Racer.Jockey.Alias,
                        NumberInRace = participant.NumberInRace,
                        PlaceInRace = participant.PlaceInRace
                    });
                }

                return model;
            }
        }
Esempio n. 26
0
 public void EditRace(RaceDetailsViewModel model)
 {
     using (var unit = new UnitOfWork())
     {
         var loadParticipants = unit.Participant.LoadParticipants(new ParticipantFilter { RaceId = model.RaceId });
         foreach (var participantViewModel in model.Participants)
         {
             var viewModel = participantViewModel;
             foreach (var participant in loadParticipants.Where(participant => viewModel.ParticipantId == participant.Id))
             {
                 participant.NumberInRace = participantViewModel.NumberInRace;
                 participant.PlaceInRace = participantViewModel.PlaceInRace;
                 unit.Participant.Save(participant);
                 break;
             }
         }
     }
 }
Esempio n. 27
0
        public void DeleteRace(int id)
        {
            using (var unit = new UnitOfWork())
            {
                var race = unit.Race.Get(id);
                var loadParticipants = unit.Participant.LoadParticipants(new ParticipantFilter { RaceId = race.Id });
                foreach (var participant in loadParticipants)
                {
                    unit.Participant.Delete(participant);
                }

                unit.Race.Delete(race);
            }
        }
Esempio n. 28
0
        public List<WinnersViewModel> SelectWinners(int quantityParticipants)
        {
            using (var unit = new UnitOfWork())
            {
                var participants = unit.Participant.LoadParticipants(new ParticipantFilter { WithHorse = true, WithJockey = true });

                var models = new List<WinnersViewModel>();
                foreach (var participant in participants)
                {
                    var countWinnerRaces = unit.Participant.GetCountWinnerRaces(participant.Id);
                    if (countWinnerRaces > 0)
                    {
                        models.Add(new WinnersViewModel
                        {
                            HorseNickname = participant.Racer.Horse.Nickname,
                            JockeyAlias = participant.Racer.Jockey.Alias,
                            CountWinnerRaces = countWinnerRaces
                        });
                    }
                }

                var list = models.OrderByDescending(x => x.CountWinnerRaces).Take(quantityParticipants).ToList();
                return list;
            }
        }
Esempio n. 29
0
 public List<RaceDetailsViewModel> GetRaces(DateTime date)
 {
     using (var unit = new UnitOfWork())
     {
         var races = unit.Race.GetRacesListForMonth(date);
         return races.Select(getRaceDetailsViewModelWithoutParticipants).ToList();
     }
 }
Esempio n. 30
0
 private List<ParticipantViewModel> getParticipantsViewModelsList(UnitOfWork unit, int id)
 {
     var loadParticipants = unit.Participant.LoadParticipants(
         new ParticipantFilter
         {
             RaceId = id,
             WithJockey = true,
             WithHorse = true
         });
     return loadParticipants.Select(participant =>
                                    new ParticipantViewModel
                                    {
                                        HorseId = participant.Racer.HorseId,
                                        HorseNickname = participant.Racer.Horse.Nickname,
                                        JockeyId = participant.Racer.JockeyId,
                                        JockeyAlias = participant.Racer.Jockey.Alias,
                                        ParticipantId = participant.Id,
                                        NumberInRace = participant.NumberInRace,
                                        PlaceInRace = participant.PlaceInRace
                                    }).ToList();
 }