public ActionResult Edit(string username = "", string role = "") { var player = this.playersService.GetUserByUsername(username); var roleExist = Enum.TryParse <Role>(role, out Role resultRole); if (player == null) { this.TempData["Error"] = "Player not found!"; return(RedirectToAction(nameof(All))); } if (!roleExist) { this.TempData["Error"] = "Role is invalid!"; return(RedirectToAction(nameof(All))); } var model = new PlayerEditModel { Username = username, Role = role }; return(this.View(nameof(this.Edit), model)); }
public async Task Update(PlayerEditModel model) { var obj = _mapper.Map <Player>(model); model.AuthenticationCode = AuthService.HashPassword(model.AuthenticationCode); await _repository.UpdateAndSaveAsync(obj); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var player = _playersRepository.FindBy(c => c.Id == id).Single(); if (player == null) { return(HttpNotFound()); } PlayerEditModel vm = new PlayerEditModel { Id = player.Id, Phone = player.Phone, Name = player.Name, ImageUrl = player.ImageUrl, Address = player.Address, Vk = player.Vk, AdditionInfo = player.AdditionInfo }; return(View(vm)); }
public async Task <IActionResult> Create(PlayerEditModel model) { Db.Add( new User { FirstName = model.FirstName, LastName = model.LastName }); await Db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Edit(PlayerEditModel inputModel) { if (!ModelState.IsValid) { return(this.View(inputModel)); } this.playersService.UpdateRoleByUsername(inputModel.Username, inputModel.Role, inputModel.NewRole); var player = this.playersService.GetUserByUsername(inputModel.Username); var newRoles = this.playersService.GetUserRoles(player.UserName); return(RedirectToAction("Edit", new { Username = inputModel.Username, Role = newRoles })); }
private PlayerEditModel GetEditData(int id) { var model = new PlayerEditModel { Command = _editPlayerQuery.Handle(new GetPlayerEditQuery() { Id = id }), Teams = _htmlselectTeamQuery.Handle(new GetTeamHtmlSelectQuery() { HtmlSelectOption = HtmlSelectOption.FirstRow_DefaultText }) }; return(model); }
public async Task <IActionResult> Edit(Guid?id, PlayerEditModel model) { if (id == null) { return(NotFound()); } if (ModelState.IsValid) { var player = await _context.Players.FindAsync(id); player.Name = model.Name; await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Teams", new { id = model.TeamId })); } ViewData["teamId"] = model.TeamId; return(View(model)); }
public async Task <IActionResult> Create(PlayerEditModel model) { if (ModelState.IsValid) { var player = new Player() { Id = Guid.NewGuid(), Name = model.Name, TeamId = model.TeamId }; _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Teams", new { id = model.TeamId })); } ViewData["teamId"] = model.TeamId; return(View(model)); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var player = await _context.Players.FindAsync(id); if (player == null) { return(NotFound()); } var model = new PlayerEditModel() { Id = player.Id, Name = player.Name, TeamId = player.TeamId }; return(View(player)); }
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)); }
//[Authorize(Roles = PlayerRolesConst.MainPlayer)] public async Task <IActionResult> Update(PlayerEditModel model) { await _playerService.Update(model); return(Ok()); }