public IndexModel( IMapper mapper, IAPIHelper apiHelper, IRazorPartialToStringRenderer renderer, IModelHelper modelHelper) { _mapper = mapper; _apiHelper = apiHelper; _renderer = renderer; _modelHelper = modelHelper; userProfileModel = new UserProfileModel(); userTeamTableModel = new UserTeamTableModel(); StatusTypes statusTypes = new StatusTypes(); StatusList = new SelectList(statusTypes.GetStatusTypesDictionary(), "Key", "Value"); }
private async Task <bool> GeneratePageConstructionModel() { UserTeamTableModel dummyUserTeamTableModel = new UserTeamTableModel() { userProfileModel = GenerateDummyUserProfileModel(), StatusList = StatusList, TeamSelectList = userTeamTableModel.TeamSelectList }; var teamListHTML = await _renderer.RenderPartialToStringAsync("_UserTeamList", dummyUserTeamTableModel); teamListHTML = teamListHTML.Replace("\n", "").Replace("\r", "").Replace("\t", "").ToString(); var teamTableHTML = _renderer.GetStringBetween(teamListHTML, "<!--TeamTableRowsStart-->", "<!--TeamTableRowsEnd-->"); List <string> teamListRows = teamTableHTML.TrimStart().TrimEnd().Replace("<td>", "").Split("</td>").ToList(); for (int i = teamListRows.Count - 1; i >= 0; i--) { var eol = ","; teamListRows[i] = teamListRows[i].TrimStart().TrimEnd(); if (string.IsNullOrWhiteSpace(teamListRows[i])) { teamListRows.RemoveAt(i); continue; } if (i == teamListRows.Count - 1) { eol = ""; } teamListRows[i] = teamListRows[i].Replace("userProfileModel_userTeamJoins_0__", "userProfileModel_userTeamJoins_' + rowCount + '__"); teamListRows[i] = teamListRows[i].Replace("userProfileModel.userTeamJoins[0]", "userProfileModel.userTeamJoins[' + rowCount + ']"); teamListRows[i] = teamListRows[i].Replace("22222222-2222-2222-2222-222222222222", "' + userId + '"); teamListRows[i] = teamListRows[i].Replace("disabled", string.Empty); //Prevent the team drop down from being disabled on new rows teamListRows[i] = $"'{teamListRows[i]}'{eol}"; } userTeamTableModel.teamListRows = teamListRows.ToArray(); return(true); }