public IActionResult EditGetAccount(int id) { try { var accountService = _logicFactory.GetAccountService(); //get the team Account a = accountService.GetByID(id); //create the view model AdminAccountEditView editAccountView = new AdminAccountEditView { AccountID = a.AccountID, AccountName = a.AccountName, AccountEmail = a.AccountEmail, AccountPassword = a.AccountPassword, PlayerID = a.AccountPlayer?.PlayerID, PlayerName = a.AccountPlayer?.PlayerName, PlayerPlatformID = a.AccountPlayer?.PlayerPlatformID }; return(PartialView("Account/_EditAccountPartial", editAccountView)); } catch (Exception ex) { _logger.LogError($"Something went wrong trying to get a team to edit. |Message: {ex.Message} |Stacktrace: {ex.StackTrace}"); //notfound will result in a ajax error result. this will show a message to the user. return(NotFound()); } }
public IActionResult EditAccount(AdminAccountEditView model) { if (ModelState.IsValid) { try { var accountService = _logicFactory.GetAccountService(); var oldValues = accountService.GetByID(model.AccountID); //change this, password should be handled in logic layer Account accountToEdit = new Account { AccountID = model.AccountID, AccountName = model.AccountName, AccountPassword = model.AccountPassword != null ? model.AccountPassword : oldValues.AccountPassword, //change this AccountEmail = model.AccountEmail, AccountPlayer = model.PlayerID != null ? new Player { PlayerID = model.PlayerID, PlayerName = model.PlayerName, PlayerPlatformID = model.PlayerPlatformID } : oldValues.AccountPlayer }; accountService.Update(accountToEdit); return(PartialView("Account/_AccountEditSuccess")); //success } catch (Exception ex) { _logger.LogError($"Something went wrong trying to get an account to edit. |Message: {ex.Message} |Stacktrace: {ex.StackTrace}"); //notfound will result in a ajax error result. this will show a message to the user. return(NotFound()); } } else { return(PartialView("_EditTeamFormPartial", model)); } }