public override BaseResource[] SynchronizeIds(BaseResource[] source, Uri subjectUri, BaseResource[] target)
        {
            IndexingAndSearchWrittenQuestion question = source.OfType <IndexingAndSearchWrittenQuestion>().SingleOrDefault();

            question.Id = subjectUri;
            if ((question.QuestionHasAnsweringBodyAllocation != null) && (question.QuestionHasAnsweringBodyAllocation.Any()))
            {
                AnsweringBodyAllocation answeringBodyAllocationTarget = target.OfType <AnsweringBodyAllocation>().SingleOrDefault();
                if (answeringBodyAllocationTarget != null)
                {
                    question.QuestionHasAnsweringBodyAllocation.SingleOrDefault().Id = answeringBodyAllocationTarget.Id;
                }
                if (question.QuestionHasAnsweringBodyAllocation.SingleOrDefault()?.AnsweringBodyAllocationHasAnsweringBody?.AnsweringBodyHasWrittenAnswer != null)
                {
                    question.QuestionHasAnsweringBodyAllocation
                    .SingleOrDefault()
                    .AnsweringBodyAllocationHasAnsweringBody
                    .AnsweringBodyHasWrittenAnswer
                    .SingleOrDefault()
                    .AnswerHasQuestion = new Question[]
                    {
                        new Question()
                        {
                            Id = subjectUri
                        }
                    };
                    WrittenAnswer answerTarget = target.OfType <WrittenAnswer>().SingleOrDefault();
                    if (answerTarget != null)
                    {
                        question.QuestionHasAnsweringBodyAllocation
                        .SingleOrDefault()
                        .AnsweringBodyAllocationHasAnsweringBody
                        .AnsweringBodyHasWrittenAnswer
                        .SingleOrDefault()
                        .Id = answerTarget.Id;
                    }
                }
            }
            if ((question.QuestionHasWrittenAnswerExpectation != null) && (question.QuestionHasWrittenAnswerExpectation.Any()))
            {
                WrittenAnswerExpectation expectationTarget = target.OfType <WrittenAnswerExpectation>().SingleOrDefault();
                if (expectationTarget != null)
                {
                    question.QuestionHasWrittenAnswerExpectation
                    .SingleOrDefault()
                    .Id = expectationTarget.Id;
                }
            }

            return(new BaseResource[] { question });
        }
        public override BaseResource[] TransformSource(XDocument doc)
        {
            var arrElements = doc?.Element("response")?.Element("result")?.Element("doc")?.Elements("arr")?.ToList();
            var strElements = doc?.Element("response")?.Element("result")?.Element("doc")?.Elements("str")?.ToList();

            if ((arrElements == null) || (strElements == null))
            {
                return(null);
            }

            Response data = new Response();

            data.DateTabled           = FindXElementByAttributeName(arrElements, "dateTabled_dt", "date").GetDate();
            data.QuestionText         = FindXElementByAttributeName(arrElements, "questionText_t", "str").GetText();
            data.QuestionHeading      = strElements.Where(x => x.Attribute("name").Value == "title_t").FirstOrDefault().GetText();
            data.AskingMemberSesId    = FindXElementByAttributeName(arrElements, "askingMember_ses", "int").GetText();
            data.AnsweringDeptSesId   = FindXElementByAttributeName(arrElements, "answeringDept_ses", "int").GetText();
            data.HeadingDueDate       = FindXElementByAttributeName(arrElements, "headingDueDate_dt", "date").GetDate();
            data.AnswerText           = FindXElementByAttributeName(arrElements, "answerText_t", "str").GetText();
            data.DateOfAnswer         = FindXElementByAttributeName(arrElements, "dateOfAnswer_dt", "date").GetDate();
            data.AnsweringMemberSesId = FindXElementByAttributeName(arrElements, "answeringMember_ses", "int").GetText();
            data.DateForAnswer        = FindXElementByAttributeName(arrElements, "dateForAnswer_dt", "date").GetDate();
            data.Uin = FindXElementByAttributeName(arrElements, "uin_t", "str").GetText();

            IndexingAndSearchWrittenQuestion question = new IndexingAndSearchWrittenQuestion();

            question.QuestionAskedAt = data.DateTabled;
            question.QuestionHeading = data.QuestionHeading;
            question.QuestionText    = data.QuestionText;
            if (string.IsNullOrWhiteSpace(data.Uin) == false)
            {
                question.WrittenQuestionIndexingAndSearchUin = new string[] { data.Uin }
            }
            ;

            question.IndexingAndSearchUri = new String[] { strElements.Where(x => x.Attribute("name").Value == "uri").FirstOrDefault().GetText() };

            if (data.AskingMemberSesId != null)
            {
                Uri memberId = GetMemberId(data.AskingMemberSesId, data.DateTabled == null ? data.DateOfAnswer : data.DateTabled, logger);
                if (memberId != null)
                {
                    question.QuestionHasAskingPerson = new Person[]
                    {
                        new Person()
                        {
                            Id = memberId
                        }
                    }
                }
                ;
                else
                {
                    logger.Warning($"Member with Ses Id ({data.AskingMemberSesId}) not found");
                }
            }

            AnsweringBodyAllocation answeringBodyAllocation = giveMeAnsweringBodyAllocation(data);

            if (answeringBodyAllocation != null)
            {
                question.QuestionHasAnsweringBodyAllocation = new AnsweringBodyAllocation[] { answeringBodyAllocation }
            }
            ;
            WrittenAnswerExpectation writtenAnswerExpectation = giveMeWrittenAnswerExpectation(data);

            if (writtenAnswerExpectation != null)
            {
                question.QuestionHasWrittenAnswerExpectation = new WrittenAnswerExpectation[] { writtenAnswerExpectation }
            }
            ;

            return(new BaseResource[] { question });
        }