public void PreferenceInDb(string[] newsPrefCat, string newsTime, bool newsNotificationFlag, string newsNotifyMe, string eandtTime, string eandtNotify, bool eandtflag, string taskNotifyMe, string taskTime, bool taskNotificationFlag, string UserName, bool isAdded)
        {
            //Preference pref = new Preference();
            Preference userPref = GetDataHelper.UserPreference(UserName);
            Preference user     = new Preference()
            {
                UserName = UserName
            };

            if (userPref != null)
            {
                user = userPref;
                if (user == null)
                {
                    user = new Preference()
                    {
                        UserName = UserName
                    }
                }
                ;
            }


            user.News.NewsNotificationFlag = newsNotificationFlag;
            user.News.NewsNotificationTime = newsTime;

            var oldPrefList = user.News.SelectedCategories.ToList();

            foreach (var cat in newsPrefCat)
            {
                if (isAdded && !oldPrefList.Contains(cat))
                {
                    oldPrefList.Add(cat);
                }
                else
                {
                    oldPrefList.Remove(cat);
                }
            }
            user.News.SelectedCategories = oldPrefList.ToArray();


            // user.News[0].SelectedCategories = newsPrefCat;
            user.News.NewsNotifyMe = newsNotifyMe;

            user.EandT.EandTNotificationFlag = eandtflag;
            user.EandT.EandTNotifyMe         = eandtNotify;
            user.EandT.EandTNotificationTime = eandtTime;

            user.Task.TaskNotificationFlag = taskNotificationFlag;
            user.Task.TaskNotificationTime = taskTime;
            user.Task.TaskNotifyMe         = taskNotifyMe;

            GetDataHelper.WritePreferences(user);
        }
Пример #2
0
        /// <summary>
        /// Called when a message is received by the dialog
        /// </summary>
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var activity    = await result as Activity;
            var typingReply = activity.CreateReply();

            typingReply.Text = null;
            typingReply.Type = ActivityTypes.Typing;
            await context.PostAsync(typingReply);

            string message     = string.Empty;
            string userEmailId = string.Empty;
            string emailKey    = GetEmailKey(activity);
            var    userDetails = await GetCurrentUserDetails(activity);

            string userName = userDetails.UserPrincipalName;


            Models.Preference uPref    = GetDataHelper.UserPreference(userName);
            Models.Preference currUser = null;
            if (uPref != null && uPref.UserInfo != null)
            {
                currUser = uPref;
            }


            if (currUser == null)
            {
                string UniqueId   = activity.From.Id;
                string ServiceURL = activity.ServiceUrl;
                string TenantId   = activity.GetChannelData <TeamsChannelData>().Tenant.Id;

                Models.Preference userPref = new Models.Preference
                {
                    UserName = userName
                };
                Models.UserInfo        uInfo    = new Models.UserInfo();
                Models.NewsPreference  newsPref = new Models.NewsPreference();
                Models.EandtPreference entPref  = new Models.EandtPreference();
                Models.TaskPreference  taskPref = new Models.TaskPreference();
                uInfo.UniqueID   = UniqueId;
                uInfo.ServiceURl = ServiceURL;
                uInfo.TenantID   = TenantId;

                newsPref.NewsNotificationFlag = true;
                newsPref.NewsNotifyMe         = "true";
                newsPref.SelectedCategories   = new string[] { "AI", "Technology", "IT" };
                entPref.EandTNotificationFlag = true;
                entPref.EandTNotifyMe         = "true";
                taskPref.TaskNotificationFlag = true;
                taskPref.TaskNotifyMe         = "true";


                userPref.UserInfo = new[] { uInfo };
                userPref.News     = newsPref;
                userPref.EandT    = entPref;
                userPref.Task     = taskPref;

                GetDataHelper.WritePreferences(userPref);
            }


            if (!context.ConversationData.ContainsKey(emailKey))
            {
                //await SendOAuthCardAsync(context, (Activity)context.Activity);
                //return;
            }

            if (userDetails == null)
            {
                await context.PostAsync("Failed to read user profile. Please try again.");
            }
            if (!string.IsNullOrEmpty(activity.Text))
            {
                message = Microsoft.Bot.Connector.Teams.ActivityExtensions.GetTextWithoutMentions(activity).ToLowerInvariant();
                Attachment        card  = null;
                var               reply = context.MakeMessage();
                List <Attachment> res;
                switch (message.Trim())
                {
                case Common.Constants.Welcome:
                    string url = await GetSigninUrl(activity);

                    res = Helper.CardHelper.WelcomeCard();
                    for (int i = 0; i < res.Count(); i++)
                    {
                        reply.Attachments.Add(res.ElementAt(i));
                    }
                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    break;

                case Common.Constants.Refresh:
                    //await Helper.GetDataHelper.GetNewsFromSPandWriteToFile();
                    //await Helper.GetDataHelper.GetEandTFromSPandWriteToFile();
                    await Helper.GetDataHelper.GetTasksandWriteToFile();

                    //await Helper.GetDataHelper.GetPODetailsandWriteToFile();
                    //await Helper.GetDataHelper.GetPreferencesandWriteToFile();
                    reply.Text = "Cache is updated.";
                    break;

                case Common.Constants.SetPrefrences:
                    card       = Helper.CardHelper.SetTimePreference(userName);
                    reply.Text = string.Format("Set a preferred time to receive notifications for latest news, upcoming events and trainings and task reminders.");
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.UpcomingEventsTraining:
                    card = Helper.CardHelper.GetETCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.PendingApprovals:

                    card = Helper.CardHelper.PendingApprovals();
                    if (card != null)
                    {
                        reply.Attachments.Add(card);
                    }
                    else
                    {
                        reply.Text = "No pending approvals to show.";
                    }
                    break;

                case Common.Constants.PendingTasks:
                    card = Helper.CardHelper.PendingTasks();
                    if (card != null)
                    {
                        reply.Attachments.Add(card);
                    }
                    else
                    {
                        reply.Text = "No pending submissions to show.";
                    }
                    break;

                case Common.Constants.TrendingNews:
                    card = Helper.CardHelper.GetNewsCard(userName);
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.Policies:
                    card = Helper.CardHelper.GetPoliciesCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.MyTools:
                    card = Helper.CardHelper.GetMyToolsCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.HumanResourceTools:
                    card = Helper.CardHelper.HumanResourceCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.ITFacilitiesTools:
                    card = Helper.CardHelper.ITFacilitiesCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.PaymentsAndBenefitsTools:
                    card = Helper.CardHelper.PaymentsAndBenefitsCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.StoreOperationsTools:
                    card = Helper.CardHelper.StoreOperationsCard();
                    reply.Attachments.Add(card);
                    break;

                case Common.Constants.ViewTicket:
                    card = Helper.CardHelper.Ticket();
                    if (card != null)
                    {
                        reply.Attachments.Add(card);
                    }
                    else
                    {
                        reply.Text = "No tickets to show.";
                    }
                    break;

                default:
                    res = Helper.CardHelper.DefaultCard();
                    for (int i = 0; i < res.Count(); i++)
                    {
                        reply.Attachments.Add(res.ElementAt(i));
                    }
                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    //dont reply anything
                    //Attachment res1 = Helper.CardHelper.DefaultCard();
                    ////for (int i = 0; i < res.Count(); i++)
                    ////    reply.Attachments.Add(res.ElementAt(i));
                    ////reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    //reply.Attachments.Add(res1);
                    break;
                    //return;
                }

                await context.PostAsync(reply);
            }
            else if (activity.Value != null)
            {
                await HandleActions(context, activity);

                return;
            }
        }