public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            // GetDataHelper helper = new GetDataHelper();
            var query = activity.GetComposeExtensionQueryData();

            if (query == null)
            {
                // We only process the 'getRandomText' queries with this message extension
                return(null);
            }
            if (query.CommandId == "News")
            {
                NewsModel news       = GetDataHelper.GetNews();
                var       title      = "";
                var       titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "newstitle");
                var       response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    // List<string> searchtitle = news.Select(a => a.NewsTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    //  List<string> searchImages = news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsThumbnailUrl).ToList();
                    //  List<string> searchDateTime = news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsDateTIme).ToList();
                    //  List<string> searchviews = news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NoOfViews).ToList();
                    //  List<string> searchby = news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsBy).ToList();
                    //  int attacCount = searchtitle.Count();
                    // attachments = new ComposeExtensionAttachment[attacCount];
                    // for (int i = 0; i < attacCount; i++)
                    //  {
                    //      attachments[i] = GetAttachment(searchImages[i], searchtitle[i], searchDateTime[i], searchviews[i],searchby[i]);
                    //  }


                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    // List<string> searchtitle = news.Select(c => c.NewsTitle).ToList();
                    // List<string> searchImages = news.Select(c => c.NewsThumbnailUrl).ToList();
                    //  List<string> searchDateTime = news.Select(c => c.NewsDateTIme).ToList();
                    //  List<string> searchviews = news.Select(c => c.NoOfViews).ToList();
                    //  List<string> searchby=news.Select(c => c.NewsBy).ToList();
                    //  attachments = new ComposeExtensionAttachment[searchtitle.Count()];
                    //  for (int i = 0; i < searchtitle.Count(); i++)
                    //  {
                    //      attachments[i] = GetAttachment(searchImages[i], searchtitle[i], searchDateTime[i], searchviews[i],searchby[i]);
                    //  }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else
            {
                return(null);
            }
        }
        public ActionResult News()
        {
            NewsModel news = new NewsModel();
            int       day  = DateTime.Now.Day;

            if (day == 15 || day == 30)
            {
                MockDataHelper.UpdateNewsMockData();
            }
            news = GetDataHelper.GetNews();
            return(View(news));
        }
Esempio n. 3
0
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            GetDataHelper helper = new GetDataHelper();
            List <News>   news   = helper.GetNews();


            var query = activity.GetComposeExtensionQueryData();

            if (query == null /*|| (query.CommandId != "Speakers" || query.CommandId != "Sessions")*/)
            {
                return(null);
            }

            /* if (query.CommandId == "speaker")
             * {
             *   var title = "";
             *   var titleParam = query.Parameters?.FirstOrDefault(p => p.category == "speakerTitle");
             *   var response = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
             *   ComposeExtensionAttachment[] attachments = null;
             *   if (titleParam != null)
             *   {
             *       title = titleParam.Value.ToString();
             *
             *       List<string> searchNames = speakers.Select(a => a.SpeakerName).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
             *       List<string> searchImages = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Snap).ToList();
             *       List<string> searchBio = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Bio).ToList();
             *       List<string> searchTitle = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Title).ToList();
             *       int attacCount = searchNames.Count();
             *
             *       attachments = new ComposeExtensionAttachment[attacCount];
             *       for (int i = 0; i < attacCount; i++)
             *       {
             *           attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
             *       }
             *       response.ComposeExtension.Attachments = attachments.ToList();
             *   }
             *   else
             *   {
             *       List<string> searchNames = speakers.Select(c => c.SpeakerName).ToList();
             *       List<string> searchImages = speakers.Select(c => c.Snap).ToList();
             *       List<string> searchTitle = speakers.Select(c => c.Title).ToList();
             *       List<string> searchBio = speakers.Select(c => c.Bio).ToList();
             *       attachments = new ComposeExtensionAttachment[searchNames.Count];
             *       for (int i = 0; i < searchNames.Count; i++)
             *       {
             *           attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
             *       }
             *       response.ComposeExtension.Attachments = attachments.ToList();
             *   }
             *
             *   return response;
             * }*/
            else if (query.CommandId == "EventsTrainings")
            {
                List <EventsAndTrainings> eventsTrainings = helper.GetEandT();

                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "ETTitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();

                    List <string> searchTitle  = eventsTrainings.Select(a => a.ETTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdate   = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETStartDate).ToList();
                    List <string> searchend    = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETEndDate).ToList();
                    List <string> searchETType = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETType).ToList();;
                    int           attacCount   = searchTitle.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        // string Type = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachment(searchdate[i], searchend[i], searchTitle[i], searchETType[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchTitle  = eventsTrainings.Select(c => c.ETTitle).Take(20).ToList();
                    List <string> searchdate   = eventsTrainings.Select(c => c.ETStartDate).Take(20).ToList();
                    List <string> searchend    = eventsTrainings.Select(c => c.ETEndDate).Take(20).ToList();
                    List <string> searchETType = eventsTrainings.Select(c => c.ETType).ToList();
                    attachments = new ComposeExtensionAttachment[searchTitle.Count];
                    for (int i = 0; i < searchTitle.Count; i++)
                    {
                        //string speakerAndSessionType = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachment(searchdate[i], searchend[i], searchTitle[i], searchETType[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }

                return(response);
            }

            return(null);
        }
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            var query = activity.GetComposeExtensionQueryData();

            if (query == null)
            {
                // We only process the 'getRandomText' queries with this message extension
                return(null);
            }
            if (query.CommandId == "News")
            {
                NewsModel news       = GetDataHelper.GetNews();
                var       title      = "";
                var       titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "newsTitle");
                var       response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    List <string> searchtitle    = news.news.Select(a => a.NewsTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchImages   = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsThumbnailUrl).ToList();
                    List <string> searchDateTime = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsDateTIme).ToList();
                    List <string> searchdetail   = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.DetailedNews).ToList();
                    List <string> searchby       = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsBy).ToList();
                    int           attacCount     = searchtitle.Count();
                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetNewsAttachment(searchImages[i], searchtitle[i], searchby[i], searchdetail[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchtitle    = news.news.Select(c => c.NewsTitle).Take(20).ToList();
                    List <string> searchImages   = news.news.Select(c => c.NewsThumbnailUrl).Take(20).ToList();
                    List <string> searchDateTime = news.news.Select(c => c.NewsDateTIme).Take(20).ToList();
                    List <string> searchdetail   = news.news.Select(c => c.DetailedNews).Take(20).ToList();
                    List <string> searchby       = news.news.Select(c => c.NewsBy).Take(20).ToList();
                    attachments = new ComposeExtensionAttachment[searchtitle.Count()];
                    for (int i = 0; i < searchtitle.Count(); i++)
                    {
                        attachments[i] = GetNewsAttachment(searchImages[i], searchtitle[i], searchby[i], searchdetail[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else if (query.CommandId == "Task")
            {
                SpfxPurchaseOrder task = GetDataHelper.GetPOs();
                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "tasktitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    //List<string> description = task.PurchaseOrder.Select(a => a.Description).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    //List<string> totamount = task.PurchaseOrder.Where(a => a.Description.ToLower().Contains(title.ToLower())).Select(c => c.TotalAmount).ToList();
                    List <string> description = task.value.Select(a => a.Description).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> totamount   = task.value.Where(a => a.Description.ToLower().Contains(title.ToLower())).Select(c => c.TotalAmount).ToList();

                    int attacCount = description.Count();
                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetTaskAttachments(description[i], totamount[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> description = task.value.Where(b => b.PoStatus == "pending").Select(c => c.Description).Take(20).ToList();
                    List <string> totamount   = task.value.Where(b => b.PoStatus == "pending").Select(c => c.TotalAmount).Take(20).ToList();
                    attachments = new ComposeExtensionAttachment[description.Count()];
                    for (int i = 0; i < description.Count(); i++)
                    {
                        attachments[i] = GetTaskAttachments(description[i], totamount[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else if (query.CommandId == "EventsAndTrainings")

            {
                EandTModel eventsTrainings = GetDataHelper.GetEandT();
                var        title           = "";
                var        titleParam      = query.Parameters?.FirstOrDefault(p => p.Name == "EventsAndTrainingstitle");
                var        response        = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;

                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    List <string> searchTitle   = eventsTrainings.EventsAndtraining.Select(a => a.ETTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdetails = eventsTrainings.EventsAndtraining.Select(a => a.ETDetails).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdate    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETStartDate).ToList();
                    List <string> searchimage   = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETThumbnailUrl).ToList();
                    List <string> searchETType  = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETType).ToList();
                    List <string> searchETid    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETID).ToList();
                    List <bool>   searchETar    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.UserAdded).ToList();

                    int attacCount = searchTitle.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];

                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetEventsAttachment(searchimage[i], searchTitle[i] + ',' + searchETType[i], searchdate[i], searchdetails[i], searchETid[i], searchETar[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchTitle   = eventsTrainings.EventsAndtraining.Select(c => c.ETTitle).ToList();
                    List <string> searchdetails = eventsTrainings.EventsAndtraining.Select(c => c.ETDetails).ToList();
                    List <string> searchdate    = eventsTrainings.EventsAndtraining.Select(c => c.ETStartDate).ToList();
                    List <string> searchimage   = eventsTrainings.EventsAndtraining.Select(c => c.ETThumbnailUrl).ToList();
                    List <string> searchETType  = eventsTrainings.EventsAndtraining.Select(c => c.ETType).ToList();
                    List <string> searchETid    = eventsTrainings.EventsAndtraining.Select(c => c.ETID).ToList();
                    List <bool>   searchETar    = eventsTrainings.EventsAndtraining.Select(c => c.UserAdded).ToList();
                    attachments = new ComposeExtensionAttachment[searchTitle.Count];
                    for (int i = 0; i < searchTitle.Count; i++)
                    {
                        attachments[i] = GetEventsAttachment(searchimage[i], searchTitle[i] + ',' + searchETType[i], searchdate[i], searchdetails[i], searchETid[i], searchETar[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else
            {
                return(null);
            }
        }