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> /// 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> /// Retrieve the answer with the given identifier. /// </summary> /// <param name="id">The identifier of the answer.</param> /// <returns>Returns the answer with the given identifier.</returns> public Answer GetAnswer(string id) { Validation.IdCheck(id); Answer answer = new Answer(); using (var ctx = new IntelliCloudContext()) { int iId = Convert.ToInt32(id); AnswerEntity answerentity = (from a in ctx.Answers .Include(a => a.User) .Include(a => a.User.Sources) .Include(a => a.User.Sources.Select(s => s.SourceDefinition)) where a.Id == iId select a).Single(); answer = ConvertEntities.AnswerEntityToAnswer(answerentity); } return answer; }
/// <summary> /// Converts an AnswerEntity to an Answer. /// </summary> /// <param name="entity">The AnswerEntity that has to be converted.</param> /// <returns>The Answer object.</returns> public Answer AnswerEntityToAnswer(AnswerEntity entity) { Answer answer = new Answer(); answer.Id = entity.Id; answer.CreationTime = entity.CreationTime; answer.Content = entity.Content; answer.AnswerState = entity.AnswerState; answer.User = UserEntityToUser(entity.User); return answer; }