Beispiel #1
0
        /// <summary>
        /// Helper method to create a simple task card and send it back as a message.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="reqId"></param>
        /// <returns></returns>
        private async Task SendTopCandidatesMessage(IDialogContext context, string reqId)
        {
            // Create a message object.
            IMessageActivity reply = context.MakeMessage();

            reply.Attachments = new List <Attachment>();
            reply.Text        = $"Okay, here are top candidates who have recently applied to your position";

            // Create the task using the data controller.
            var candidates = new CandidatesDataController().GetTopCandidates(reqId);

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

            foreach (Candidate c in candidates)
            {
                var card = CardHelper.CreateSummaryCardForCandidate(c);
                reply.Attachments.Add(card.ToAttachment());
            }

            // Send the message back to the user.
            await context.PostAsync(reply);
        }
Beispiel #2
0
        /// <summary>
        /// Helper method to generate a the messaging extension response.
        ///
        /// Note that for this sample, we are returning generated positions for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateResponse()
        {
            ComposeExtensionResponse response = null;

            var     query = activity.GetComposeExtensionQueryData();
            JObject data  = activity.Value as JObject;

            // Check if this is a task module invocation.
            if (data != null && data["type"] != null)
            {
                // Handle other types of Invoke activities here, e.g. CardActions
                if (data["type"].ToString() == TaskModuleCommandType && data["command"].ToString() == CreatePostingCommand)
                {
                    response = CreateTaskModuleResponse();
                }
            }
            else
            {
                //Check to make sure a query was actually made:
                if (query.CommandId == null || query.Parameters == null)
                {
                    return(null);
                }
                else if (query.Parameters.Count > 0)
                {
                    // query.Parameters has the parameters sent by client
                    var results = new ComposeExtensionResult()
                    {
                        AttachmentLayout = "list",
                        Type             = "result",
                        Attachments      = new List <ComposeExtensionAttachment>(),
                    };

                    if (query.CommandId == "searchPositions")
                    {
                        OpenPositionsDataController controller = new OpenPositionsDataController();
                        IEnumerable <OpenPosition>  positions;

                        if (query.Parameters[0].Name == "initialRun")
                        {
                            // Default query => list all
                            positions = controller.ListOpenPositions(10);
                        }
                        else
                        {
                            // Basic search.
                            string title = query.Parameters[0].Value.ToString().ToLower();
                            positions = controller.ListOpenPositions(10).Where(x => x.Title.ToLower().Contains(title));
                        }

                        // Generate cards for the response.
                        foreach (OpenPosition pos in positions)
                        {
                            var card = CardHelper.CreateCardForPosition(pos, true);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }
                    else if (query.CommandId == "searchCandidates")
                    {
                        string name = query.Parameters[0].Value.ToString();
                        CandidatesDataController controller = new CandidatesDataController();

                        foreach (Candidate c in controller.GetTopCandidates("ABCD1234"))
                        {
                            c.Name = c.Name.Split(' ')[0] + " " + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name);
                            var card = CardHelper.CreateSummaryCardForCandidate(c);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment(CardHelper.CreatePreviewCardForCandidate(c).ToAttachment());
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }

                    response = new ComposeExtensionResponse()
                    {
                        ComposeExtension = results
                    };
                }
            }
            return(response);
        }