示例#1
0
        public TeamViewModel Create(TeamViewModel vmTeam)
        {
            var team = vmTeam.ToDataModel();

            team.AdditionalDetailsJson = AdditionalDetailsFactory.CreateFootbalTeamsLocalCreationDetails().ToJson();

            if (vmTeam.ManagerId.HasValue)
            {
                var manager = _memberRepository.GetManager(vmTeam.ManagerId.Value);

                team.AddManager(manager);
            }

            foreach (var playerId in vmTeam.SelectedPlayerIds)
            {
                var player = _memberRepository.GetPlayerWithNoTeam(playerId);

                if (player != null)
                {
                    team.AddPlayer(player);
                }
            }

            _teamRepository.Add(team);

            return(team.ToViewModel());
        }
示例#2
0
        public ActionResult Register(TeamMemberViewModel vmPlayer)
        {
            if (ModelState.IsValid)
            {
                vmPlayer.Role = MemberRole.Player;

                vmPlayer.AdditionalDetailsJson = AdditionalDetailsFactory.CreateFootbalTeamsLocalCreationDetails().ToJson();

                _memeberRespository.Add(vmPlayer.ToDataModel());

                AlertSuccess("Saved", "Player registered");
                return(RedirectToAction("Index"));
            }

            ViewBag.AvailableTeams = _teamRepository.GetAll().ToViewModel();

            AlertModelStateErrors();

            return(View(vmPlayer));
        }