private async Task ShowOvertimeEmployees(IDialogContext context, string tenantId, string startDate, string endDate, List <string> overtimeEmployeeList, string payPeriod, LoginResponse response)
        {
            var superUserLogonRes = await this.authenticationService.LoginSuperUser((Activity)context.Activity);

            if (superUserLogonRes?.Status == ApiConstants.Success)
            {
                context.UserData.SetValue(context.Activity.From.Id + Constants.SuperUser, superUserLogonRes.Jsession);
            }

            string personNumber = this.response?.PersonNumber;
            string isManager    = await this.authenticateUser.IsUserManager(context);

            var activity = context.Activity as Activity;
            var message  = activity.Text?.ToLowerInvariant().Trim();

            if (isManager.Equals(Constants.Yes))
            {
                Models.ResponseEntities.HyperFind.Response hyperFindResponse = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, response.JsessionID, startDate, endDate, ApiConstants.OvertimeHyperFindQuery, ApiConstants.PubilcVisibilityCode);

                if (hyperFindResponse?.Status == ApiConstants.Failure)
                {
                    // User is not logged in - Send Sign in card
                    if (hyperFindResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                    {
                        await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                    }
                    else
                    {
                        await context.PostAsync(hyperFindResponse.Error?.Message);
                    }
                }
                else
                {
                    context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession);
                    if (hyperFindResponse.HyperFindResult.Count > 0)
                    {
                        var overtimeMappingEntity = await this.azureTableStorageHelper.ExecuteQueryUsingPointQueryAsync <OvertimeMappingEntity>(Constants.ActivityChannelId, $"{tenantId}${Constants.TeamOvertimes}", AppSettings.Instance.OvertimeMappingtableName);

                        List <string> lst     = new List <string>();
                        var           emplist = hyperFindResponse.HyperFindResult.Where(w => w.PersonNumber != personNumber);

                        var tasks = emplist.Select(async emp =>
                        {
                            var showHoursWorkedResponse = await this.hoursWorkedActivity.ShowHoursWorked(tenantId, response, startDate, endDate, emp.PersonNumber);

                            // var totalHours = showPunchesResponse?.Timesheet?.DailyTotals?.DateTotals?
                            //    .Where(t => t.Totals != null && t.Totals.Total != null)
                            //    .SelectMany(x => x.Totals.Total.Where(f => f.PayCodeName.ToLowerInvariant().Contains(overtimeMappingEntity.PayCodeName.ToLowerInvariant())))
                            //    .Sum(x => Convert.ToDouble(x.AmountInTime.Replace(':', '.')));
                            var showHoursWorkedOrderedList = showHoursWorkedResponse?.Timesheet?.PeriodTotalData?.PeriodTotals?.Totals?.Total?.FindAll(x => x.PayCodeName == Constants.AllHours).Select(x => new { x.PayCodeName, x.AmountInTime }).ToList();
                            var allHours = showHoursWorkedOrderedList.FirstOrDefault(x => x.PayCodeName.Contains(Constants.AllHours))?.AmountInTime;

                            if (allHours != null)
                            {
                                var jobAssignent     = await this.jobAssignment.getJobAssignment(Convert.ToString(emp.PersonNumber), tenantId, superSession);
                                var role             = jobAssignent?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Split('/').LastOrDefault();
                                DateTime stDateTime  = default(DateTime);
                                DateTime eDateTime   = default(DateTime);
                                double assignedHours = default(double);
                                UpcomingShiftsAlias.Response scheduleResponse           = await this.upcomingShiftsActivity.ShowUpcomingShifts(tenantId, superSession, startDate, endDate, emp.PersonNumber);
                                List <UpcomingShiftsAlias.ScheduleShift> scheduleShifts = scheduleResponse?.Schedule?.ScheduleItems?.ScheduleShift?.OrderBy(x => x.StartDate).ToList();
                                if (scheduleShifts != null)
                                {
                                    foreach (var scheduleShift in scheduleShifts)
                                    {
                                        var shiftSegment = scheduleShift.ShiftSegments.FirstOrDefault();
                                        stDateTime       = DateTime.Parse($"{shiftSegment.StartDate} {shiftSegment.StartTime}", CultureInfo.InvariantCulture, DateTimeStyles.None);
                                        eDateTime        = DateTime.Parse($"{shiftSegment.EndDate} {shiftSegment.EndTime}", CultureInfo.InvariantCulture, DateTimeStyles.None);
                                        assignedHours    = assignedHours + Math.Abs(Math.Round((stDateTime - eDateTime).TotalHours, 2));
                                    }
                                }

                                // overtimeEmployeeList.Add($"{emp.FullName} - {totalHours} <br />");
                                overtimeEmployeeList.Add($"{emp.FullName} - {role} - {Convert.ToString(allHours).Replace(':', '.')}/{assignedHours}");
                            }
                        });
                        await Task.WhenAll(tasks);

                        var pagewiseOvertimes = this.GetPagewiseList(overtimeEmployeeList);
                        context.PrivateConversationData.SetValue("PagewiseOvertimes", pagewiseOvertimes);
                        var card = this.adaptiveTeamOvertimesCard.GetCard(context, payPeriod, startDate, endDate, 1);
                        if (message.Contains(Constants.PreviousWeekTeamOvertimes) || message.Contains(Constants.CurrentWeekTeamOvertimes))
                        {
                            var conversationId = context.Activity.Conversation.Id;
                            var activityId     = context.Activity.ReplyToId;
                            IConnectorClientFactory factory = new ConnectorClientFactory(Address.FromActivity(context.Activity), new MicrosoftAppCredentials(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword));
                            activity.Text  = null;
                            activity.Value = null;
                            activity.Attachments.Add(new Attachment()
                            {
                                Content     = card,
                                ContentType = "application/vnd.microsoft.card.adaptive",
                            });
                            await factory.MakeConnectorClient().Conversations.UpdateActivityAsync(conversationId, activityId, activity);
                        }
                        else
                        {
                            var reply = activity.CreateReply();
                            reply.Attachments = new List <Attachment>
                            {
                                new Attachment()
                                {
                                    Content     = card,
                                    ContentType = "application/vnd.microsoft.card.adaptive",
                                },
                            };
                            await context.PostAsync(reply);
                        }
                    }
                    else
                    {
                        var pagewiseOvertimes = this.GetPagewiseList(overtimeEmployeeList);
                        context.PrivateConversationData.SetValue("PagewiseOvertimes", pagewiseOvertimes);
                        var card = this.adaptiveTeamOvertimesCard.GetCard(context, payPeriod, startDate, endDate, 1);
                        if (message.Contains(Constants.PreviousWeekTeamOvertimes) || message.Contains(Constants.CurrentWeekTeamOvertimes))
                        {
                            var conversationId = context.Activity.Conversation.Id;
                            var activityId     = context.Activity.ReplyToId;
                            IConnectorClientFactory factory = new ConnectorClientFactory(Address.FromActivity(context.Activity), new MicrosoftAppCredentials(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword));
                            activity.Text  = null;
                            activity.Value = null;
                            activity.Attachments.Add(new Attachment()
                            {
                                Content     = card,
                                ContentType = "application/vnd.microsoft.card.adaptive",
                            });
                            await factory.MakeConnectorClient().Conversations.UpdateActivityAsync(conversationId, activityId, activity);
                        }
                        else
                        {
                            var reply = activity.CreateReply();
                            reply.Attachments = new List <Attachment>
                            {
                                new Attachment()
                                {
                                    Content     = card,
                                    ContentType = "application/vnd.microsoft.card.adaptive",
                                },
                            };
                            await context.PostAsync(reply);
                        }
                    }
                }
            }
            else if (isManager.Equals(Constants.No))
            {
                await context.PostAsync(KronosResourceText.NoPermission);
            }
        }
        /// <summary>
        /// Method is used to show present or absent employees.
        /// </summary>
        /// <param name="context">Dialog context.</param>
        /// <param name="result">Awaitable string.</param>
        /// <returns>A task.</returns>
        private async Task ShowPresentEmployees(IDialogContext context, IAwaitable <string> result)
        {
            var activity = context.Activity as Activity;

            JObject tenant   = activity.ChannelData as JObject;
            string  tenantId = tenant["tenant"].SelectToken("id").ToString();

            var personNumber = string.Empty;
            var jSession     = string.Empty;

            if (!context.UserData.TryGetValue(context.Activity.From.Id, out LoginResponse response))
            {
                response = this.response;
            }
            else
            {
                personNumber = response.PersonNumber;
                jSession     = response.JsessionID;
            }

            AppInsightsLogger.CustomEventTrace("PresentEmployeesDialog", new Dictionary <string, string>()
            {
                { "TenantId", tenantId }, { "User", context.Activity.From.Id }, { "methodName", "ShowPresentEmployees" }, { "Command", activity.Text }
            });

            List <TotaledSpan> totaledSpan = new List <TotaledSpan>();
            var    presentEmployeeList     = new SortedList <string, string>();
            var    personName = string.Empty;
            string message    = activity.Text.ToLowerInvariant().Trim();

            var startDate = activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);
            var endDate   = activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);
            var isHere    = activity.Text.ToLowerInvariant().Contains(Constants.WhoIsHere);

            switch (message)
            {
            case string command when command.Contains(Constants.presentEmpNextpage) || command.Contains(Constants.presentEmpPrevpage) || command.Contains(Constants.absentEmpPrevpage) || command.Contains(Constants.absentEmpNextpage):
                var item = command.Split('/');

                await this.PrevNext(context, Convert.ToInt32(item[2]), message);

                break;

            default:
                string isManager = await this.authenticateUser.IsUserManager(context);

                if (isManager.Equals(Constants.Yes))
                {
                    Models.ResponseEntities.HyperFind.Response hyperFindResponse = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, jSession, startDate, endDate, ApiConstants.ReportsToHyperFindQuery, ApiConstants.PersonalVisibilityCode);

                    if (hyperFindResponse?.Status == ApiConstants.Failure)
                    {
                        // User is not logged in - Send Sign in card
                        if (hyperFindResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                        {
                            await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                        }
                        else
                        {
                            await context.PostAsync(hyperFindResponse.Error?.Message);
                        }
                    }
                    else
                    {
                        var scheduleResponse = await this.upcomingShiftsActivity.ShowUpcomingShifts(tenantId, jSession, startDate, endDate, personNumber, hyperFindResponse.HyperFindResult);

                        if (scheduleResponse?.Status == ApiConstants.Failure)
                        {
                            if (scheduleResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                            {
                                await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                            }
                            else
                            {
                                await context.PostAsync(scheduleResponse.Error?.Message);
                            }
                        }
                        else
                        {
                            var scheduleShift = scheduleResponse?.Schedule?.ScheduleItems?.ScheduleShift?.GroupBy(x => x.Employee[0].PersonNumber);

                            // Employee has a shift
                            if (scheduleShift != null && scheduleShift.Any() && scheduleShift?.Count() > 0)
                            {
                                var pNumber    = string.Empty;
                                var currentDay = activity.LocalTimestamp.Value.Date;
                                endDate   = currentDay.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);
                                startDate = currentDay.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);

                                foreach (var items in scheduleShift)
                                {
                                    var startDates     = items.Select(x => x.ShiftSegments[0].StartDate).FirstOrDefault();
                                    var endDates       = items.Select(x => x.ShiftSegments.LastOrDefault().EndDate).FirstOrDefault();
                                    var startTime      = items.Select(x => x.ShiftSegments.FirstOrDefault().StartTime).FirstOrDefault();
                                    var endTime        = items.Select(x => x.ShiftSegments.LastOrDefault().EndTime).LastOrDefault();
                                    var shiftStartDate = DateTime.Parse($"{startDates} {startTime}", CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy h:mm tt", CultureInfo.InvariantCulture);
                                    var shiftEndDate   = DateTime.Parse($"{endDates} {endTime}", CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy h:mm tt", CultureInfo.InvariantCulture);

                                    pNumber = items.Key;
                                    var showPunchesResponse = await this.showPunchesActivity.ShowPunches(tenantId, jSession, pNumber, startDate, endDate);

                                    totaledSpan = showPunchesResponse?.Timesheet?.TotaledSpans?.TotaledSpan;
                                    personName  = hyperFindResponse.HyperFindResult.Find(x => x.PersonNumber == pNumber).FullName;
                                    JobAssignmentAlias.Response jobAssignmentResponse = await this.jobAssignmentActivity.getJobAssignment(pNumber, tenantId, jSession);

                                    int lastIndex = (jobAssignmentResponse != null) ? (jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath).LastIndexOf('/') : 0;
                                    if (totaledSpan.Count > 0)
                                    {
                                        if (activity.Text.ToLowerInvariant().Contains(Constants.WhoIsHere) && totaledSpan.Any(x => x.InPunch.Punch.EnteredOnDate != null))
                                        {
                                            presentEmployeeList.Add(personName, jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(lastIndex + 1));
                                        }
                                        else if (activity.Text.ToLowerInvariant().Contains(Constants.WhoIsNotHere) && totaledSpan.Any(x => x.InPunch.Punch.EnteredOnDate == null))
                                        {
                                            // absent employees
                                            presentEmployeeList.Add(personName, jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(lastIndex + 1));
                                        }
                                    }
                                }
                            }

                            var pagewiseAttendance = this.GetPagewiseList(presentEmployeeList);

                            // save data for pagination
                            if (isHere)
                            {
                                context.PrivateConversationData.SetValue("PagewisePresentAttendance", pagewiseAttendance);
                            }
                            else
                            {
                                context.PrivateConversationData.SetValue("PagewiseAbsentAttendance", pagewiseAttendance);
                            }

                            await this.presentEmployeesCard.ShowPresentEmployeesData(context, presentEmployeeList.Take(5), isHere, message, 1, presentEmployeeList.Count);
                        }
                    }
                }
                else if (isManager.Equals(Constants.No))
                {
                    await context.PostAsync(KronosResourceText.NoPermission);
                }

                break;
            }

            context.Done(string.Empty);
        }