public ActionResult Index() { var model = new AddPlayerViewModel(); model.Teams = this.GetTeams(); return(this.View(model)); }
public (bool created, string error) Create(AddPlayerViewModel model) { bool created = false; string error = null; var(isValid, validationError) = validationService.ValidateModel(model); if (!isValid) { return(isValid, validationError); } var player = new Player() { FullName = model.FullName, Description = model.Description, Speed = model.Speed, Endurance = model.Endurance, ImageUrl = model.ImageUrl, Position = model.Position }; try { repo.Add(player); repo.SaveChanges(); created = true; } catch (Exception) { error = "Could not save player"; } return(created, error); }
private Player GetPlayer(AddPlayerViewModel playerModel) { var filename = playerModel.PhotoFile.FileName; //var path = this.Server.MapPath($"~/Content/Images/{filename}"); var path = this.Server.MapPath(ProjectConstants.ImagesRelativePath + filename); playerModel.PhotoFile.SaveAs(path); // TODO map? var player = new Player() { FirstName = playerModel.FirstName, LastName = playerModel.LastName, NickName = playerModel.NickName, CV = "", //playerModel.CV, Email = playerModel.Email, IsCoach = false, //playerModel.IsCoach, Picture = filename, Rating = 0, Votes = 0, //Team = playerModel.Team, TeamId = 1, // playerModel.TeamId, todo //User = playerModel.User, UserId = new Guid(this.User.Identity.GetUserId()) }; return(player); }
public IActionResult AddPlayer(AddPlayerViewModel model) { Player p = data.Players.Get(model.PlayerID); if (p.Password == model.Password) { GamePlayed game = new GamePlayed(); game.CourseID = model.CourseID; game.PlayerID = model.PlayerID; game.StartedByPlayerID = model.StartedByPlayerID; game.GameFinished = false; data.GamesPlayed.Insert(game); data.GamesPlayed.Save(); } Player loggedInPlayer = data.Players.Get(model.StartedByPlayerID); ViewBag.LoggedInPlayer = loggedInPlayer; ViewBag.Courses = data.Courses.List(new QueryOptions <Course> { }); ViewBag.Games = data.GamesPlayed.List(new QueryOptions <GamePlayed> { Includes = "Player, Course", Where = gp => gp.GameFinished == false && gp.StartedByPlayerID == model.StartedByPlayerID && gp.Score == 0 }); return(View("GameSetup")); }
public async Task AddPlayer(AddPlayerViewModel addPlayerViewModel) { Player player = new Player(); player.Name = addPlayerViewModel.Name; player.RoleId = Role.Player; await _playerRepository.InsertPlayer(player); }
public ActionResult AddPlayerToTable(AddPlayerViewModel addPlayer) { string httpNotFound = null; var vm = AddSelfToTable(addPlayer, out httpNotFound); if (vm == null && httpNotFound != null) { return(HttpNotFound(httpNotFound)); } return(PartialView("GamePlayers", vm)); }
public HttpResponse Add(AddPlayerViewModel model) { var errors = playerService.Create(model); if (errors.Any()) { return(Error(errors)); } return(Redirect("/Players/All")); }
public Response Add(AddPlayerViewModel model) { var(created, error) = playerService.Create(model); if (!created) { return(View(new { ErrorMessage = error }, "/Error")); } return(Redirect("/Players/All")); }
public void ReturnViewWithModel_WhenModelStateIsNotValid() { // Arrange this.controller.ModelState.AddModelError("error", "message"); var submitModel = new AddPlayerViewModel(); // Act & Assert controller.WithCallTo(c => c.Index(submitModel)) .ShouldRenderDefaultView() .WithModel(submitModel) .AndModelError("error"); }
private TableRoundViewModel AddSelfToTable(AddPlayerViewModel addPlayer, out string httpNotFound, bool skipExtra = false) { var table = db.Tables.Find(addPlayer.TableId); if (table == null) { httpNotFound = "No table exists for the id"; return(null); } var round = db.Rounds.Include(x => x.Players) .FirstOrDefault(x => x.Id == addPlayer.RoundId && x.Players.Count < Constants.MAX_PLAYERS); if (round == null || round.Id == Guid.Empty) { httpNotFound = "Either the round doesn't exist, or the table is already full. Try another table."; return(null); } var player = db.Players.Find(addPlayer.PlayerId); if (player == null) { httpNotFound = "Player does not exist"; return(null); } if (db.PlayerHands.Find(addPlayer.PlayerId, addPlayer.RoundId) != null) { httpNotFound = "Player is already a part of the game"; return(null); } if (player.Cash < table.BuyIn) { httpNotFound = "Sorry you can't afford the game, go reup"; return(null); } player.Cash -= table.BuyIn; db.PlayerHands.Add(new PlayerHand { PlayerId = player.Id, RoundId = round.Id, TotalCash = table.BuyIn, Acting = false, Active = true, Won = false, Waiting = skipExtra }); db.SaveChanges(); httpNotFound = null; return(skipExtra ? null : SetupTableRoundViewModel(round, table)); }
public void ReturnViewWithModelError_WhenFileIsNull() { // Arrange var submitModel = new AddPlayerViewModel(); submitModel.PhotoFile = null; // Act & Assert this.controller.WithCallTo(x => x.Index(submitModel)) .ShouldRenderDefaultView() .WithModel(submitModel) .AndModelErrorFor(m => m.PhotoFile) .Containing("photo"); }
public PlayersManager(IFootballPlayerList players, IFootballField field, IEfficiencyChart chart) { players.LoadPlayers(); _players = players; _playerEditor = players.GetPlayerEditor(); _playerEditor.AcceptChanges += _playerEditor_AcceptChanges; _players.AddedPlayer += Players_AddedPlayer; _addPlayersVM = new AddPlayerViewModel(players.Editor); _parametersEditorVM = new ParametersEditorViewModel(_playerEditor); _chartVM = new ChartViewModel(chart); _selectedField = true; DistributePlayers(players, field); }
public async Task <ActionResult> Add(AddPlayerViewModel dealer) { try { await _playerService.AddDealer(dealer); return(RedirectToAction("Index")); return(View()); } catch (Exception e) { return(View("Error")); } }
public async Task <ActionResult> Add(AddPlayerViewModel player) { try { await _playerService.AddPlayer(player); return(RedirectToAction("StartGame", "Game")); return(View()); } catch (Exception e) { return(View("Error")); } }
public ActionResult AddPlayer() { var model = new AddPlayerViewModel(); var user = System.Web.HttpContext.Current.GetCurrentUser(); using (var dbContext = new ManagementDataContext()) { var team = dbContext.Teams.FindTeamByUserId(user.UserId); model.TeamId = team.Id; } return(View(model)); }
public void ReturnViewWithModelError_WhenFileIsNotImage() { // Arrange var submitModel = new AddPlayerViewModel(); var mockedFile = new Mock <HttpPostedFileBase>(); mockedFile.Setup(x => x.ContentType).Returns("not image"); submitModel.PhotoFile = mockedFile.Object; // Act & Assert this.controller.WithCallTo(x => x.Index(submitModel)) .ShouldRenderDefaultView() .WithModel(submitModel) .AndModelErrorFor(m => m.PhotoFile) .Containing("photo"); }
// DELETE api/values/5 public HttpResponseMessage RemovePlayer([FromBody] AddPlayerViewModel model) { try { using (FintellixPremierLeagueEntities FplDbEntities = new FintellixPremierLeagueEntities()) { FplDbEntities.removePlayer(model.TeamID, model.PlayerID, model.Year); var msg = Request.CreateResponse(HttpStatusCode.OK, model); msg.Headers.Location = new Uri(Request.RequestUri + model.ToString()); return(msg); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
[ValidateInput(false)] //Perhaps remove public ActionResult Index([Bind(Exclude = "Teams")] AddPlayerViewModel playerModel) { if (!ModelState.IsValid) { playerModel.Teams = this.GetTeams(); return(View(playerModel)); } if (!this.IsImageFile(playerModel.PhotoFile)) { this.ModelState.AddModelError("Photofile", "Player photo photo should be an image file."); return(View(playerModel)); } var player = this.GetPlayer(playerModel); this.playerService.AddPlayer(player); return(this.Redirect("/home")); }
public async Task <IActionResult> Add(AddPlayerViewModel input, int id) { if (!this.ModelState.IsValid) { return(this.View(input)); } string fileExtn = Path.GetExtension(input.ProfileImage.FileName); if (fileExtn != ".jpg") { await this.Response.WriteAsync("Select jpg format for the picture!"); return(this.View(input)); } string uniqueFileName = this.UploadFile(input.ProfileImage); await this.playersService.Register(input.Name, input.Age, input.Height, input.Kilos, input.Number, input.PositionType, id, uniqueFileName); return(this.Redirect("/Teams/Details")); }
public List <string> Create(AddPlayerViewModel model) { var modelErrors = validationService.ValidatePlayer(model); if (!modelErrors.Any()) { var player = new Player { FullName = model.FullName, Description = model.Description, Position = model.Position, Speed = model.Speed, Endurance = model.Endurance, ImageUrl = model.ImageUrl }; repo.Add(player); repo.SaveChanges(); } return(modelErrors.ToList()); }
public ICollection <string> ValidatePlayer(AddPlayerViewModel player) { var errors = new List <string>(); if (player.FullName == null || player.FullName.Length < FullNameMinLength || player.FullName.Length > FullNameMaxLength) { errors.Add($"FullName '{player.FullName}' must be between {FullNameMinLength} and {FullNameMaxLength} characters long"); } if (player.ImageUrl == null) { errors.Add($"Url '{player.ImageUrl}' is not valid"); } if (player.Position == null || player.Position.Length < PositionMinLength || player.Position.Length > PositionMaxLength) { errors.Add($"Position must be between {PasswordMinLength} and {PasswordMaxLength} characters long"); } if (player.Speed < SpeedMinValue || player.Speed > SpeedMaxValue) { errors.Add($"Speed must be in range ({SpeedMinValue}-{SpeedMaxValue})"); } if (player.Endurance < EnduranceMinValue || player.Endurance > EnduranceMaxValue) { errors.Add($"Endurance must be in range ({EnduranceMinValue}-{EnduranceMaxValue})"); } if (player.Description == null || player.Description.Length > DescriptionMaxLength) { errors.Add($"Description cannot be greater than {DescriptionMaxLength}"); } return(errors); }
public AddPlayerPage() { InitializeComponent(); BindingContext = new AddPlayerViewModel(Navigation); }
protected override void OnAppearing() { base.OnAppearing(); BindingContext = new AddPlayerViewModel(teamId); }