@using HyperCube.Models @using Console = HyperCube.Utils.AdvConsole @code { [Inject] public IJSRuntime JsRuntime { get; set; } [Parameter] public RenderFragment Title { get; set; } string elementid = "modal_survey"; string _userName = "[UNKNOWN_USERNAME]"; Survey _survey = new(); int _currentQuestionPosition = 1; int _currentQuestionID = 1; public async Task Open(string userName, int eventID) { _userName = userName; await _survey.LoadByEventID(eventID); _currentQuestionID = _survey.SurveyItemsSorted.FirstOrDefault(i => i.Value.Position == _currentQuestionPosition).Key; await JsRuntime.InvokeVoidAsync("OpenModal", elementid); } public void Close() => JsRuntime.InvokeVoidAsync("CloseModal", elementid); void Answer(int position) { _survey.SurveyItems[_currentQuestionID].AnswerID = _survey.SurveyItems[_currentQuestionID].SurveyItemOptionsSorted.FirstOrDefault(o => o.Value.Position == position).Key; Console.WriteLine($"AnswerID: {_survey.SurveyItems[_currentQuestionID].AnswerID}."); if (_currentQuestionPosition < _survey.SurveyItems.Count) { _currentQuestionPosition++; _currentQuestionID = _survey.SurveyItemsSorted.FirstOrDefault(i => i.Value.Position == _currentQuestionPosition).Key; } else Close(); } string PositionToLetter(int position) { char character = Char.Parse("А"); return ((char)(position - 1 + character)).ToString(); } }