public IActionResult ManageAccount() { try { var accountService = _logicFactory.GetAccountService(); var allAccounts = accountService.GetAll(); AdminManageAccountListView model = new AdminManageAccountListView(); model.AccountList = new List <AccountListView>(); foreach (Account acc in allAccounts) { model.AccountList.Add(new AccountListView { AccountName = acc.AccountName, AccountID = acc.AccountID, AccountEmail = acc.AccountEmail, AccountPlayerName = acc.AccountPlayer?.PlayerName }); } return(PartialView("Account/_ManageAccountListPartial", model)); } catch (Exception ex) { _logger.LogError($"Something went wrong trying to get all accounts for the manage modal. |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 DeleteAccount(int id) { try { var accountService = _logicFactory.GetAccountService(); //delete the team accountService.Remove(new Account { AccountID = id }); //get all the teams that remain to update the view var accounts = accountService.GetAll(); var allAccounts = accountService.GetAll(); AdminManageAccountListView model = new AdminManageAccountListView(); model.AccountList = new List <AccountListView>(); foreach (Account acc in allAccounts) { model.AccountList.Add(new AccountListView { AccountName = acc.AccountName, AccountID = acc.AccountID, AccountEmail = acc.AccountEmail, AccountPlayerName = acc.AccountPlayer?.PlayerName }); } return(PartialView("Account/_ManageAccountListPartial", model)); } catch (Exception ex) { _logger.LogError($"Something went wrong trying to delete a team to the database. |Message: {ex.Message} |Stacktrace: {ex.StackTrace}"); //notfound will result in a ajax error result. this will show a message to the user. //could also return a partial view with a script that runs to show the messagebox. this feels cleaner. //i couldn't find a way to send a Json result with partial view and success yes or no return(NotFound()); } }