Exemplo n.º 1
0
        /// <summary>
        /// To prepare survey response entity from payload
        /// </summary>
        /// <param name="response"></param>
        /// <param name="trace"></param>
        /// <returns></returns>
        public static Entity GetResponseEntityFromPayload(Response response, ITracingService trace)
        {
            if (trace == null)
            {
                throw new InvalidPluginExecutionException("trace is null");
            }
            trace.Trace("Processing GetResponseEntityFromPayLoad - start");
            if (response == null)
            {
                throw new InvalidPluginExecutionException("Response in Json is null");
            }
            var surveyResponse = new Entity(EntityName.SurveyResponse);

            surveyResponse[Attributes.SurveyResponse.ResponseId] = response.Id.ToString();

            if (response.SurveyId != null)
            {
                surveyResponse[Attributes.SurveyResponse.SurveyId] = response.SurveyId.Value.ToString();
            }

            if (!string.IsNullOrWhiteSpace(response.SurveyName))
            {
                surveyResponse[Attributes.SurveyResponse.Subject] = response.SurveyName;
            }

            if (!string.IsNullOrWhiteSpace(response.SurveyDescription))
            {
                surveyResponse[Attributes.SurveyResponse.SurveyDescription] = response.SurveyDescription;
            }

            if (!string.IsNullOrWhiteSpace(response.Mode))
            {
                surveyResponse[Attributes.SurveyResponse.Mode] = response.Mode;
            }

            if (!string.IsNullOrWhiteSpace(response.BeginTime))
            {
                surveyResponse[Attributes.SurveyResponse.BeginTime] = DateTime.Parse(response.BeginTime);
            }

            var customerFirstName = ContactHelper.GetFirstName(response.Contact, trace);

            if (!string.IsNullOrWhiteSpace(customerFirstName))
            {
                surveyResponse[Attributes.SurveyResponse.CustomerFirstName] = customerFirstName;
            }

            var customerLastName = ContactHelper.GetLastName(response.Contact, trace);

            if (!string.IsNullOrWhiteSpace(customerLastName))
            {
                surveyResponse[Attributes.SurveyResponse.CustomerLastName] = customerLastName;
            }

            var customerEmail = ContactHelper.GetEmail(response.Contact, trace);

            if (!string.IsNullOrWhiteSpace(customerEmail))
            {
                surveyResponse[Attributes.SurveyResponse.CustomerEmail] = customerEmail;
            }

            var customerPhone = ContactHelper.GetPhone(response.Contact, trace);

            if (!string.IsNullOrWhiteSpace(customerPhone))
            {
                surveyResponse[Attributes.SurveyResponse.CustomerPhone] = customerPhone;
            }

            surveyResponse[Attributes.SurveyResponse.ActivityAdditionalParams] = PrepareAdditionalParameters(response, trace);
            trace.Trace("Processing GetResponseEntityFromPayLoad - end");
            return(surveyResponse);
        }