public IActionResult New(PlayerViewModel viewModel) { //19720808-1231 //720101-0101 //if (viewModel.PersonNummer.Length == 10 || viewModel.PersonNummer.Length == 12) //7208021111 //{ // //Checksiffera a // ModelState.AddModelError("PersonNummer", "Fel personnumer"); // return View("Edit", viewModel); //} //if (_dbContext.Players.Any(p => p.JerseyNumber == viewModel.JerseyNumber)) //{ // ModelState.AddModelError("JerseyNumber", "Jersey is taken"); // return View("Edit", viewModel); //} if (ModelState.IsValid) { var p = new Player(); p.Name = viewModel.Name; p.Age = viewModel.Age; p.JerseyNumber = viewModel.JerseyNumber; p.Position = (Position)viewModel.PositionEnumValue; p.Team = _dbContext.Team.FirstOrDefault(t => t.Id == viewModel.TeamId); _dbContext.Players.Add(p); _dbContext.SaveChanges(); return(RedirectToAction("Index")); } viewModel.AllTeams = GetAllTeams(); viewModel.AllPositions = Enum.GetValues(typeof(Position)).Cast <Position>() .Select(v => new SelectListItem { Text = v.ToString(), Value = ((int)v).ToString() }) .ToList(); return(View("Edit", viewModel)); }
public void TransferShouldReturnErrorWhenSameTeams() { var options = new DbContextOptionsBuilder <HockeyDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .EnableSensitiveDataLogging() .Options; var ctx = new HockeyDbContext(options); sut = new TransferService(ctx); //var team = fixture.Create<Team>(); var player = fixture.Create <Player>(); ctx.Players.Add(player); ctx.SaveChanges(); Assert.AreEqual(TransferErrorCode.SameTeamError, sut.Transfer(player.Id, player.Team.Id)); }