public LocalDataSettingsFlyout() { this.InitializeComponent(); _vm = new SampleDataViewModel(); this.DataContext = _vm; }
public ActionResult SampleData(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tournament _tournament = tournamentService.GetById((int)id); if (_tournament == null) { return(HttpNotFound()); } SampleDataViewModel sampleDataViewModel = new SampleDataViewModel() { TournamentId = (int)id }; return(View(sampleDataViewModel)); }
public ActionResult SampleDataConfirmed([Bind(Include = "TournamentId,TeamCount,MaxParticipantsInTeam")] SampleDataViewModel _sampleDataViewModel) { if (ModelState.IsValid) { Tournament _tournament = tournamentService.GetById(_sampleDataViewModel.TournamentId); var country = generalUnitService.GetByType(GeneralUnitType.Country).FirstOrDefault(); var ranking = sportUnitService.GetByTypeForGroup(_tournament.GroupId, SportUnitType.Ranking).FirstOrDefault(); Gender participantGender; string FirstName; Random rnd = new Random(); if (country != null && ranking != null) { for (int i = 0; i < _sampleDataViewModel.TeamCount; i++) { List <Participant> participants = new List <Participant>(); int participantCount = rnd.Next(4, _sampleDataViewModel.MaxParticipantsInTeam); for (int j = 0; j < participantCount; j++) { if (j % 4 == 0) { participantGender = Gender.Female; FirstName = "Alla"; } else { participantGender = Gender.Male; FirstName = "Max"; } var participant = new Participant() { FirstName = string.Format("{0}_{1}_{2}", FirstName, i, j), LastName = "Muster", Gender = participantGender, BirthDate = new DateTime(rnd.Next(1992, 2005), rnd.Next(1, 12), rnd.Next(1, 28)), Weight = rnd.Next(20, 50), RankingId = ranking.Id }; participants.Add(participant); } var team = new Team() { Name = "Team_" + i.ToString(), Coach = User.Identity.Name, City = "Berlin", CountryId = country.Id, TournamentId = _sampleDataViewModel.TournamentId, CoachRankingId = ranking.Id, Participants = participants }; teamService.Create(team); } } return(RedirectToAction("Details", new { id = _tournament.Id })); } return(View(_sampleDataViewModel)); }