private string GetUploadFolderLocation(AnswerSurvayDto answer, AnswerFieldDto answerField)
        {
            try
            {
                var path    = ConfigurationManager.AppSettings["AnswerDocumentDirectory"];
                var ftpPath = ConfigurationManager.AppSettings["FtpPath"];

                string directoryName        = Path.Combine(path, "FilesOfAnswer");
                string survayFolderName     = Path.Combine(directoryName, answer?.SurvayId.ToString());
                string survayTypeFolderName = Path.Combine(survayFolderName, answer?.SurvayTypeID.ToString());
                string clientFolder         = Path.Combine(survayTypeFolderName, $"{answer?.ClientId.ToString()}");

                if (Directory.Exists(clientFolder))
                {
                    return($"{ftpPath}/{answer?.SurvayId.ToString()}/{answer?.SurvayTypeID.ToString()}/{answer?.ClientId.ToString()}/{answerField.Answer}");
                }

                return("File not found");
            }
            catch (Exception ex)
            {
                _log.Error($"Error :  {ex}");
                throw;
            }
        }
        private void GetMatrixQuestionAnswerValue(List <FieldDto> allQuestions, int field, AnswerFieldDto fieldAnswer, List <object> answerRow)
        {
            try
            {
                if (fieldAnswer.MatrixAnswers == null || !fieldAnswer.MatrixAnswers.Any())
                {
                    _log.Info($"Info :Matrix question : {field} answers are not there");
                    return;
                }

                var matrixAnswers         = fieldAnswer.MatrixAnswers;
                var matrixQuestionsHeader = allQuestions.FirstOrDefault(x => x.Id == field).FieldOption?.MatrixHeaders.OrderBy(x => x.Id).ToList();
                var matrixQuestionsRow    = allQuestions.FirstOrDefault(x => x.Id == field).FieldOption?.MatrixRows.OrderBy(x => x.Id).ToList();

                foreach (var row in matrixQuestionsRow)
                {
                    // check if answer row is equal with question row
                    var matrixAnswer = matrixAnswers.FirstOrDefault(r => Convert.ToInt32(r.Row.Replace("ROW_", "")) == row.Id);

                    if (matrixAnswer == null || string.IsNullOrEmpty(matrixAnswer.HeaderList))
                    {
                        _log.Info($"Info :Matrix question Id : {field} and matrix answer row Id : {row.RowId}  answers are not there");

                        AddingEmptyStringToColumns(answerRow, matrixQuestionsHeader.Count);
                        continue;
                    }

                    var answerHeaders = matrixAnswer.HeaderList.Split(',').Select(i => Convert.ToInt32(i.Replace("HEADER_", ""))).ToList();

                    if (answerHeaders == null || !answerHeaders.Any())
                    {
                        _log.Info($"Info :Matrix question Id : {field} and row Id : {row}  and matrixAnswerId : {matrixAnswer.Id} headerList is not valid or no values ");

                        AddingEmptyStringToColumns(answerRow, matrixQuestionsHeader.Count);
                        continue;
                    }

                    foreach (var header in matrixQuestionsHeader)
                    {
                        // check if answer header id equal with question header id
                        if (answerHeaders.Any(c => c == header.Id))
                        {
                            answerRow.Add(1);
                        }
                        else
                        {
                            answerRow.Add(0);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }
        private void GetCheckWithTextQuestionAnswerValue(List <FieldDto> allQuestions, int questionId, AnswerFieldDto questionAnswer, List <object> answerRow)
        {
            try
            {
                var checkWithText = questionAnswer.Answer?.Split('|');
                if (checkWithText == null && !checkWithText.Any())
                {
                    _log.Info($@"Info : Answer question Id : {questionAnswer.Id} and type : ""checkWithText"" ,answer value passed is not in valid format , This should be like ""12112,value|8181,value"" ");
                    return;
                }

                var question = allQuestions.FirstOrDefault(x => x.Id == questionId && string.Equals(x.Field_Type, "checkWithText", StringComparison.CurrentCultureIgnoreCase));

                if (question != null)
                {
                    if (question.FieldOption.Options.Any())
                    {
                        var checkboxAnswer  = new List <string>();
                        var questionOptions = question.FieldOption.Options.OrderBy(x => x.Id).ToList();

                        if (question.FieldOption.Include_other_option)
                        {
                            if (!string.IsNullOrEmpty(questionAnswer.IncludeOther))
                            {
                                answerRow.Add(questionAnswer.IncludeOther);
                            }
                        }

                        var selectedOptions = questionAnswer.Answer?.Split('|').Select(x => x.Split(','))
                                              .ToDictionary(c => Convert.ToInt32(c[0].Trim()), c => c[1]);

                        foreach (var checkBoxWithTextQ in questionOptions)
                        {
                            if (selectedOptions.TryGetValue(checkBoxWithTextQ.Id, out string value))
                            {
                                answerRow.Add(value);
                            }
                            else
                            {
                                answerRow.Add(string.Empty);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error($"Error :  {e}");
            }
        }
        private void GetCheckboxQuestionAnswerValue(List <FieldDto> allQuestions, int questionId, AnswerFieldDto questionAnswer, List <object> answerRow)
        {
            try
            {
                var question = allQuestions.FirstOrDefault(x => x.Id == questionId && string.Equals(x.Field_Type, "checkboxes", StringComparison.CurrentCultureIgnoreCase));

                if (question != null)
                {
                    if (question.FieldOption.Options.Any())
                    {
                        var checkboxAnswer  = new List <string>();
                        var questionOptions = question.FieldOption.Options.OrderBy(x => x.Id).ToList();

                        if (question.FieldOption.Include_other_option)
                        {
                            if (!string.IsNullOrEmpty(questionAnswer.IncludeOther))
                            {
                                answerRow.Add(questionAnswer.IncludeOther);
                            }
                            else
                            {
                                answerRow.Add(0);
                            }
                        }

                        var selectedOptions = questionAnswer.Answer?.Split(',').ToArray();

                        foreach (var checkboxQ in question.FieldOption.Options.OrderBy(x => x.Id))
                        {
                            if (selectedOptions.Any(c => Convert.ToInt32(c) == checkboxQ.Id))
                            {
                                answerRow.Add(1);
                            }
                            else
                            {
                                answerRow.Add(0);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }
        private void GetRadioQuestionAnswerValue(List <FieldDto> allQuestions, int questionId, AnswerFieldDto questionAnswer, List <object> answerRow)
        {
            try
            {
                var question = allQuestions.FirstOrDefault(x => x.Id == questionId && string.Equals(x.Field_Type, "radio", StringComparison.CurrentCultureIgnoreCase));

                if (question != null)
                {
                    if (question.FieldOption.Options.Any())
                    {
                        var radioAnswer      = new List <string>();
                        var questionOptions  = question.FieldOption.Options.OrderBy(x => x.Id).ToList();
                        var OtherOptionIndex = questionOptions.Count + 1;

                        // Check if user has selected the "Includeother" option
                        if (!string.IsNullOrEmpty(questionAnswer.IncludeOther))
                        {
                            answerRow.Add(questionAnswer.IncludeOther);
                            return;
                        }

                        var selectedOptions = questionAnswer.Answer?.Split(',').ToArray();

                        for (int j = 0; j < questionOptions.Count; j++)
                        {
                            if (selectedOptions.Any(x => Convert.ToInt32(x) == questionOptions[j].Id))
                            {
                                answerRow.Add(questionOptions[j].Label);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }