public ChaperoneFormModel GetChaperoneFormModel(long eventCustomerId)
{
var chaperoneSignature = _chaperoneSignatureRepository.GetByEventCustomerId(eventCustomerId);
var staffSignatureFile = chaperoneSignature != null?_fileRepository.GetById(chaperoneSignature.StaffSignatureFileId) : null;
if (staffSignatureFile == null)
{
return(new ChaperoneFormModel
{
EventCustomerId = eventCustomerId,
CustomerAnswers = null,
PatientSignatureBytes = null,
});
}
var chaperoneQuestions = _chaperoneQuestionRepository.GetAllQuestions();
var chaperoneAnswers = _chaperoneAnswerRepository.GetByEventCustomerId(eventCustomerId);
var eventCustomer = _eventCustomerRepository.GetById(eventCustomerId);
var mediaLocation = _mediaRepository.GetChaperoneSignatureLocation(eventCustomer.EventId, eventCustomer.CustomerId);
string signatureFilePath = string.Empty;
var signatureFile = chaperoneSignature != null && chaperoneSignature.SignatureFileId.HasValue ? _fileRepository.GetById(chaperoneSignature.SignatureFileId.Value) : null;
if (signatureFile != null)
{
signatureFilePath = Path.Combine(mediaLocation.PhysicalPath, signatureFile.Path);
}
var staffSignatureFilePath = Path.Combine(mediaLocation.PhysicalPath, staffSignatureFile.Path);
var chaperoneFormModel = new ChaperoneFormModel();
chaperoneFormModel.EventCustomerId = eventCustomerId;
chaperoneFormModel.CustomerAnswers = chaperoneAnswers
.Select(x => new ChaperoneAnswerModel
{
QuestionId = x.QuestionId,
Answer = x.Answer
})
.ToArray();
if (!string.IsNullOrEmpty(signatureFilePath) && File.Exists(signatureFilePath))
{
var signatureFileByte = File.ReadAllBytes(signatureFilePath);
chaperoneFormModel.PatientSignatureBytes = Convert.ToBase64String(signatureFileByte);
}
if (File.Exists(staffSignatureFilePath))
{
var staffSignatureFileByte = File.ReadAllBytes(staffSignatureFilePath);
chaperoneFormModel.StaffSignatureBytes = Convert.ToBase64String(staffSignatureFileByte);
}
return(chaperoneFormModel);
}