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; } }
public void Insert(AnswerSurvayDto dto) { try { var metrixQ = dto.AnswerFields.Where(x => x.Type.Contains("mulitiSelect-matrix")); if (metrixQ != null && metrixQ.Any()) { foreach (var mQ in metrixQ) { // since mobile end sending matrix answer in dulicated way , need to removed them and concatinating them var newMatrixList = new List <MatrixAnswerDto>(); foreach (var answer in mQ.MatrixAnswers.GroupBy(x => x.Row)) { var selectedHeaders = string.Join(",", answer.Select(x => $"{x.HeaderList}")); var newMatrixANswer = new MatrixAnswerDto() { Row = answer.Key, HeaderList = selectedHeaders }; newMatrixList.Add(newMatrixANswer); } mQ.MatrixAnswers = newMatrixList; } } var entity = _mapper.Map <AnswerSurvayDto, AnswerSurvay>(dto); _unitOfWork.GetRepository <AnswerSurvay>().Insert(entity); Save(); } catch (Exception e) { _log.Error($"Error : {e}"); throw new Exception(e.Message); } }
private void GetRowOfAnswerValue(AnswerSurvayDto answer, List <FieldDto> allQuestions, List <object> answerRow) { foreach (var field in allQuestions) { try { var fieldAnswer = answer.AnswerFields.FirstOrDefault(x => x.FieldId == field.Id); if (fieldAnswer != null) { if (fieldAnswer.Type.ToLower() == "radio") { GetRadioQuestionAnswerValue(allQuestions, field.Id, fieldAnswer, answerRow); continue; } else if (fieldAnswer.Type.ToLower() == "checkboxes") { GetCheckboxQuestionAnswerValue(allQuestions, field.Id, fieldAnswer, answerRow); continue; } else if (fieldAnswer.Type.ToLower() == "checkwithtext") { GetCheckWithTextQuestionAnswerValue(allQuestions, field.Id, fieldAnswer, answerRow); continue; } else if (fieldAnswer.Type.ToLower() == "number" || fieldAnswer.Type.ToLower() == "text" || fieldAnswer.Type.ToLower() == "paragraph") { answerRow.Add(fieldAnswer.Answer); continue; } else if (fieldAnswer.Type.ToLower() == "mulitiselect-matrix" || fieldAnswer.Type.ToLower() == "single-matrix") { GetMatrixQuestionAnswerValue(allQuestions, field.Id, fieldAnswer, answerRow); continue; } else if (fieldAnswer.Type.ToLower() == "ranking-number") { answerRow.Add(fieldAnswer.Answer); continue; } else if (fieldAnswer.Type.ToLower() == "ranking-text") { answerRow.Add(fieldAnswer.Answer); continue; } else if (fieldAnswer.Type.ToLower() == "fileupload") { var filePathName = GetUploadFolderLocation(answer, fieldAnswer); answerRow.Add(filePathName); continue; } answerRow.Add(string.Empty); _log.Info($@"Info : Answer Question Id : {fieldAnswer.Id} , type : ""{fieldAnswer.Type}"" is not match with application allowed types , in survay Type Id : {answer.SurvayTypeID}, It might be type mismatching."); } else { var columnsCount = GetColumnsCountCorrespondingToSurvayQuestion(field); AddingEmptyStringToColumns(answerRow, columnsCount); _log.Info($"Info : Question Id : {field} is not found in answer list , survay Id : {answer.Id}, It might be an optional question."); } } catch (Exception e) { _log.Error($"Error : {e}"); answerRow.Add(string.Empty); } } answerRow.Add($"{answer.Client?.FirstName ?? string.Empty} {answer.Client?.LastName ?? string.Empty}"); answerRow.Add(answer.Client?.Address ?? string.Empty); answerRow.Add(answer.Client?.MobileNumber ?? string.Empty); answerRow.Add(DateTime.Now.Year - answer.Client?.BirthOfDate?.Year); }