public Question GetQuestion(int id)
        {
            Validation.IdCheck(id);

            Question question = new Question();

            using (IntelliCloudContext ctx = new IntelliCloudContext())
            {
                // TODO: make sure only users of type employee can retrieve private questions.
                QuestionEntity entity = (from q in ctx.Questions
                                                                 .Include(q => q.Source)
                                                                 .Include(q => q.User)
                                                                 .Include(q => q.User.Sources)
                                                                 .Include(q => q.Answerer)
                                                                 .Include(q => q.Answerer.Sources)
                                                                 .Include(q => q.User.Sources.Select(s => s.SourceDefinition))
                                         where q.Id == id
                                         select q).SingleOrDefault();

                if (entity == null)
                    throw new NotFoundException("No Question entity exists with the specified ID.");

                question = ConvertEntities.QuestionEntityToQuestion(entity);
            }
            return question;
        }
 public void Initialize()
 {
     twitterSendAnswerPlugin = new TwitterSendAnswerPlugin();
     QuestionSource questionSource = new QuestionSource();
     Source source = new Source();
     questionSource.Source = source;
     question = new Question();
     question.Source = questionSource;
     answer = new Answer();
 }
        /// <summary>
        /// Send an answer through twitter with the related question
        /// </summary>
        /// <param name="question"></param>
        /// <param name="answer">The answer given by expert, answer.Content + reference can't be longer then 140 characters</param>
        public void SendAnswer(Question question, Answer answer)
        {
            var reference = question.Source.Source.Value;
            var postId = question.Source.PostId;

            var status = reference + " " + answer.Content;

            validation.StringCheck(postId);
            validation.TweetLengthCheck(status);

            using (TwitterContext twitterCtx = new TwitterContext(PinAutharizedUser))
            {
                var tweet = twitterCtx.UpdateStatus(status, postId);                
            }
        }        
        /// <summary>
        /// Sends answer through a comment on a facebook post
        /// </summary>
        /// <param name="question"></param>
        /// <param name="answer"></param>
        public void SendAnswer(Question question, Answer answer)
        {
            //Get the id of the post containing the question
            String postId = question.Source.PostId;

            //Create a new dynamic object that contains the content of the answer
            dynamic parameters = new ExpandoObject();
            parameters.message = answer.Content;
            
            //Create a new facebook client
            FacebookClient facebookClient = new FacebookClient(accessToken);

            //Comment to the post containing the question
            facebookClient.Post("/" + postId + "/comments", parameters);
        }
 /// <summary>
 /// Converts a QuestionEntity to a Question.
 /// </summary>
 /// <param name="entity">The QuestionEntity that has to be converted.</param>
 /// <returns>The question object.</returns>
 public Question QuestionEntityToQuestion(QuestionEntity entity)
 {
     Question question = new Question();
     question.Id = entity.Id;
     if (entity.Answerer != null)
     {
         question.Answerer = UserEntityToUser(entity.Answerer);
     }
     question.User = UserEntityToUser(entity.User);
     question.Content = entity.Content;
     question.CreationTime = entity.CreationTime;
     question.QuestionState = entity.QuestionState;
     question.Source = this.QuestionSourceEntityToQuestionSource(entity.Source);
     return question;
 }
        /// <summary>
        /// Send an answer through e-mail with the related question
        /// </summary>
        /// <param name="question"></param>
        /// <param name="answer"></param>
        public void SendAnswer(Question question, Answer answer)
        {
            CreateClient();
            
            //Create the from address
            MailAddress fromAddress = new MailAddress(clientUsername, "IntelliCloud Team");

            //Create the to address
            string askerName = question.User.FirstName + " " + question.User.LastName;
            MailAddress toAddress = new MailAddress(question.Source.Source.Value, askerName);

            //Set the e-mail content
            string subject = "Answer to: " + question.Title;
            string body = "Hello " + askerName + ",\n" +
                "\n" +
                "You have recently asked the following question:\n" +
                question.Content + "\n" +
                "\n" +
                "We give you the following answer:\n" +
                answer.Content + "\n" +
                "\n" +
                "We hope to have answered your question.\n" +
                "\n" +
                "Kind regards,\n" +
                "IntelliCloud Team";

            //Create the e-mail with the addresses and content
            using (MailMessage message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })

            //Send the mail
            client.Send(message);
            
            //Dispose the smtp client
            client.Dispose();
        }
 /// <summary>
 /// Sends a confirmation the the asker of the question
 /// </summary>
 /// <param name="question">the question asked by a user</param>
 public void SendQuestionRecieved(Question question)
 {
     throw new NotImplementedException();
 }