public virtual ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlayerDetails player; try { player = playerRetriever.GetPlayerDetails(id.Value, 0); } catch (UnauthorizedAccessException) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } catch (KeyNotFoundException) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var playerEditViewModel = new PlayerEditViewModel { Active = player.Active, Id = player.Id, GamingGroupId = player.GamingGroupId, Name = player.Name }; return(View(MVC.Player.Views.Edit, playerEditViewModel)); }
public virtual ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PlayerDetails player; try { player = playerRetriever.GetPlayerDetails(id.Value, 0); } catch (UnauthorizedAccessException) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } catch (KeyNotFoundException) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var playerEditViewModel = new PlayerEditViewModel { Active = player.Active, Id = player.Id, GamingGroupId = player.GamingGroupId, Name = player.Name, IsDeleteable = !player.PlayerGameSummaries.Any() && string.IsNullOrEmpty(player.ApplicationUserId) }; return(View(MVC.Player.Views.Edit, playerEditViewModel)); }
public void SetUp() { player = new Player { Active = false, Id = 123, Name = "the name", GamingGroupId = 789 }; actualModel = new PlayerEditViewModelBuilder().Build(player); }
public ViewResult Edit(int id) { Player player = _playerRepository.GetPlayer(id); PlayerEditViewModel playerEditViewModel = new PlayerEditViewModel { Id = player.Id, Name = player.Name, Age = player.Age, Points = player.Points, Country = player.Country }; return(View(playerEditViewModel)); }
public IActionResult Edit(PlayerEditViewModel model) { if (ModelState.IsValid) { Player newPlayer = new Player { Id = model.Id, Name = model.Name, Age = model.Age, Points = model.Points, Country = model.Country }; _playerRepository.Update(newPlayer); return(RedirectToAction("Players", "Home")); } return(View(model)); }
public MainViewViewModel() { Log.Info("MainViewViewModel() starting"); DisplayName = "I am the Tennis Master!!!"; //base.DisplayName = Strings.MainWindowViewModel_DisplayName; //_customerRepository = new CustomerRepository(customerDataFile); //_activeViewModel = new MatchHistoryViewModel(); //ViewAllMatches(); //ViewPlayerCommand = new RelayCommand(param => ActiveViewModel = new PlayerViewModel()); //ViewAllPlayersCommand = new RelayCommand(param => ActiveViewModel = new PlayerListViewModel()); //ViewTennisEventCommand = new RelayCommand(param => ActiveViewModel = new TennisEventViewModel()); //ViewAllTennisEventsCommand = new RelayCommand(param => ActiveViewModel = new TennisEventListViewModel(), param => true); //ViewAllMatchesCommand = new RelayCommand(param => ViewAllMatches()); //ViewMatchCommand = new RelayCommand(param => ActiveViewModel = new MatchViewModel()); NewMatchCommand = new RelayCommand(param => ItemDetailViewModel = new MatchEditViewModel()); NewPlayerCommand = new RelayCommand(param => ItemDetailViewModel = new PlayerEditViewModel()); //NewEventCommand = new RelayCommand(param => ItemDetailViewModel = new TennisEventEditViewModel()); Log.Info("MainViewViewModel() creating MatchEditViewModel"); ItemDetailViewModel = new MatchEditViewModel(); Log.Info("MainViewViewModel() creating NewMatchHistoryViewModel"); MatchHistoryViewModel = NewMatchHistoryViewModel(); Log.Info("MainViewViewModel() creating NewOpponentSummaryViewModel"); SummaryViewModel = NewOpponentSummaryViewModel(); //MatchHistoryViewModel. EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus)); Log.Info("MainViewViewModel() done"); }
public async Task <IActionResult> PlayerEdit(PlayerEditViewModel model) { //de user in var user steken var user = await _userManager.FindByIdAsync(model.Id); //de passwoorden van de model halen model.Password = user.PasswordHash; model.ConfirmPassword = user.PasswordHash; if (ModelState.IsValid) { if (user == null) { ViewBag.ErrorMessage = $"User with username = {model.Username} cannot be found"; return(View("NotFound")); } //checken voor nieuwe profielfoto if (model.Photo != null) { // we gaan zien of de foto wel een foto is if (!IsImage(model.Photo)) { ViewBag.ErrorMessage = ("Image validation error", "An error occured while processing your file. Please make sure the file you upload is an image, or contact the support team."); return(View("Error")); } if (model.ProfilePicturePath != null) { var filePath = Path.Combine(_webHostEnvironment.WebRootPath, "images/ProfilePictures", model.ProfilePicturePath); System.IO.File.Delete(filePath); } user.ProfilePicturePath = ProcessUploadedFile(model); } user.ProfileTitle = model.ProfileTitle; user.BackGround = model.BackgroundName; bool checkIfUsernameChanged = false;; //als de username veranderd is maken we checkifusernamechanged true if (model.Username != user.UserName) { user.UserName = model.Username; checkIfUsernameChanged = true; } user.Email = model.Email; user.UpdatedBy = user.Id; user.LastUpdateDate = DateTime.Now.Date; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { //als de username veranderd is loggen we de gebruiker uit want de cookie veranderd niet mee waardoor de gebruiker anders nooit meer de website zal kunnen gebruiken if (checkIfUsernameChanged) { await _signInManager.SignOutAsync(); } await _signInManager.PasswordSignInAsync(user, user.PasswordHash, false, false); //werkt niet return(RedirectToAction("PlayerDetails", new { id = user.Id })); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(model)); }
public async Task <IActionResult> PlayerEdit(string id) { var user = await _userManager.FindByIdAsync(id); if (user == null) { ViewBag.ErrorMessage = $"User with Id = {id} cannot be found"; return(View("NotFound")); } if (_userManager.FindByNameAsync(User.Identity.Name).Result != user) { ViewBag.ErrorMessage = "You are not allowed to do this action."; return(View("Error")); } var model = new PlayerEditViewModel { Id = user.Id, Username = user.UserName, Email = user.Email, ProfilePicturePath = user.ProfilePicturePath, Password = user.PasswordHash, ConfirmPassword = user.PasswordHash, ProfileTitle = user.ProfileTitle, BackgroundName = user.BackGround }; var playerPurchaseList = _playerPurchasesRepository.GetPlayerPurchasesByUser(user).ToList(); List <PlayerItem> profileTitleUser = new List <PlayerItem>(); List <PlayerItem> backgroundPictureUser = new List <PlayerItem>(); for (int i = 0; i < playerPurchaseList.Count(); i++) { var item = _playerItemRepository.FindByID(playerPurchaseList[i].ItemID); if (item == null) { ViewBag.ErrorMessage = "Something went wrong while trying to find the user's items. Please try again later or contact the support team"; return(View("Error")); } if (item.Type == ItemType.ProfileTitle) { profileTitleUser.Add(item); } else { backgroundPictureUser.Add(item); } } List <SelectListItem> profileTitlesSelect = new List <SelectListItem>(); List <SelectListItem> backgroundsSelect = new List <SelectListItem>(); foreach (PlayerItem profileTitle in profileTitleUser) { profileTitlesSelect.Add(new SelectListItem(profileTitle.Name, profileTitle.Name)); } foreach (PlayerItem backgroundPicture in backgroundPictureUser) { backgroundsSelect.Add(new SelectListItem(backgroundPicture.Name, backgroundPicture.Name)); } model.ProfileTitles = profileTitlesSelect; model.BackgroundNames = backgroundsSelect; return(View(model)); }
void PlayerViewModel_EditRequested(Player item) { ItemDetailViewModel = new PlayerEditViewModel(item); }