public CreatePlayerDTO Create(string name)
        {
            var player           = new Player(name);
            var playerValidation = player.Validate();

            if (playerValidation.IsValid)
            {
                PlayersRepository.Add(player);
                return(new CreatePlayerDTO(player.Id));
            }
            return(new CreatePlayerDTO(playerValidation.errors));
        }
Beispiel #2
0
        public ActionResult <IEnumerable <string> > Post(Players player)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (true == _playersRepository.Add(player))
            {
                return(Ok(player));
            }
            return(BadRequest());
        }
Beispiel #3
0
        public Player Create(string firstName, string phone)
        {
            var newAccount = new Account()
            {
                Type = AccountType.Virtual
            };

            var newPlayer = new Player()
            {
                Name    = firstName,
                Phone   = phone,
                Account = newAccount
            };

            _playersRepository.Add(newPlayer);
            _playersRepository.Save();

            return(newPlayer);
        }
        public ActionResult Add(Player player)
        {
            var Id = Convert.ToInt32(TeamsRep.GetAllTeams().OrderBy(t => t.Id));
            List <SelectListItem> teamlist = new List <SelectListItem>();

            var myteams = TeamsRep.GetAllTeams().OrderBy(k => k.Name);

            if (myteams.Count() > 0)
            {
                foreach (Team t in myteams)
                {
                    SelectListItem sli = new SelectListItem();
                    sli.Value = t.Id.ToString();
                    sli.Text  = t.Name;
                    teamlist.Add(sli);
                }
            }

            ViewData["MyTeams"] = teamlist;

            var teamplayers = TeamsRep.GetAllTeams().Where(t => t.Id == player.TeamId);

            if (!String.IsNullOrEmpty(player.FirstNames))
            {
                if (PlayersRep.GetAllPlayers().Where(k => k.FirstNames.ToLower() == player.FirstNames.ToLower()).Count() > 0)
                {
                    ModelState.AddModelError("FullName", "That player already exist");
                }
                else
                {
                    PlayersRep.Add(player);
                    PlayersRep.SaveChanges();

                    return(Redirect("/players/index/id"));
                }
            }
            else
            {
                //No player entered
                ModelState.AddModelError("FullName", "Please enter player name");
            }
            return(View(player));
        }
Beispiel #5
0
        public ActionResult Edit(PlayerEditModel model)
        {
            if (ModelState.IsValid)
            {
                var    isNew = model.Id == 0;
                Player player;

                if (isNew)
                {
                    player = new Player
                    {
                        Account = new Account()
                    };
                }
                else
                {
                    player = _playersRepository.FindBy(c => c.Id == model.Id).Single();
                }

                player.Phone        = model.Phone;
                player.Name         = model.Name;
                player.ImageUrl     = model.ImageUrl;
                player.Address      = model.Address;
                player.Vk           = model.Vk;
                player.AdditionInfo = model.AdditionInfo;

                if (isNew)
                {
                    _playersRepository.Add(player);
                }

                _playersRepository.Save();
                return(RedirectToAction("Profile", new { @id = player.Id }));
            }

            return(View(model));
        }