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); }
public MobileResponseModel Save(ChaperoneFormModel model) { try { _logger.Info("Chaperone Form (Save) EventCustomerId : " + model.EventCustomerId); var isSuccess = _chaperoneService.SaveAnswers(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId); if (isSuccess) { return(new MobileResponseModel { IsSuccess = true, Message = "Chaperone form data saved successfully." }); } else { return(new MobileResponseModel { IsSuccess = false, Message = "Unable to save Chaperone form data." }); } } catch (Exception ex) { _logger.Error("Error while saving Chaperone form data."); _logger.Error("Message : " + ex.Message); _logger.Error("Stack Trace : " + ex.StackTrace); return(new MobileResponseModel { IsSuccess = false, Message = string.Format("Error while saving Chaperone form data. Message : {0}", ex.Message) }); } }
public bool SaveAnswers(ChaperoneFormModel model, long orgRoleUserId) { var evenntCustomer = _eventCustomerRepository.GetById(model.EventCustomerId); if (evenntCustomer == null) { return(false); } var signatureLocation = _mediaRepository.GetChaperoneSignatureLocation(evenntCustomer.EventId, evenntCustomer.CustomerId); var version = _chaperoneSignatureRepository.GetLatestVersion(model.EventCustomerId); var answers = new List <ChaperoneAnswerModel>(); if (!model.CustomerAnswers.IsNullOrEmpty()) { answers.AddRange(model.CustomerAnswers); } if (!answers.IsNullOrEmpty()) { var chaperoneAnswers = new List <ChaperoneAnswer>(); var answerVersion = _chaperoneAnswerRepository.GetLatestVersion(model.EventCustomerId); foreach (var answer in answers) { var chaperoneAnswer = new ChaperoneAnswer { EventCustomerId = model.EventCustomerId, QuestionId = answer.QuestionId, Answer = answer.Answer, Version = answerVersion + 1, IsActive = true, DateCreated = DateTime.Now, CreatedBy = orgRoleUserId }; chaperoneAnswers.Add(chaperoneAnswer); } _chaperoneAnswerRepository.SaveAnswer(chaperoneAnswers); } var chaperoneSignature = new ChaperoneSignature { EventCustomerId = model.EventCustomerId, Version = version, IsActive = true, CreatedBy = orgRoleUserId, DateCreated = DateTime.Now }; if (!string.IsNullOrWhiteSpace(model.PatientSignatureBytes)) { var fileName = "PatientSignature_" + Guid.NewGuid() + ".jpg"; var patientImageFile = SaveSignatureImage(model.PatientSignatureBytes, orgRoleUserId, signatureLocation, fileName); chaperoneSignature.SignatureFileId = patientImageFile.Id; } if (!string.IsNullOrWhiteSpace(model.StaffSignatureBytes)) { var fileName = "StaffSignature_" + Guid.NewGuid() + ".jpg"; var patientImageFile = SaveSignatureImage(model.StaffSignatureBytes, orgRoleUserId, signatureLocation, fileName); chaperoneSignature.StaffSignatureFileId = patientImageFile.Id; } _chaperoneSignatureRepository.Save(chaperoneSignature); return(true); }