Exemple #1
0
        /// <summary>
        /// Process time off request approval (Accept/Refuse) sent from supervisor.
        /// </summary>
        /// <param name="context">Dialog context.</param>
        /// <param name="command">Command sent to bot.</param>
        /// <returns>Task.</returns>
        private async Task SubmitTimeOffApproval(IDialogContext context, string command)
        {
            var     activity = context.Activity as Activity;
            JToken  token    = JObject.Parse(activity.Value.ToString());
            JObject tenant   = context.Activity.ChannelData as JObject;
            string  tenantId = tenant["tenant"].SelectToken("id").ToString();

            string jSessionId   = this.response?.JsessionID;
            string personNumber = (string)token.SelectToken("PersonNumber");
            string querySpan    = (string)token.SelectToken("QueryDateSpan");
            string reqId        = (string)token.SelectToken("RequestId");
            string payCode      = (string)token.SelectToken("PayCode");
            string note         = (string)token.SelectToken("note");
            string comment      = (string)token.SelectToken("Comment");

            if (!string.IsNullOrEmpty(note) && string.IsNullOrEmpty(comment))
            {
                await context.PostAsync(Resources.KronosResourceText.CommentSelectionValidation);
            }
            else
            {
                Models.ResponseEntities.TimeOff.SubmitResponse.Response response = await this.timeOffActivity.SubmitApproval(tenantId, jSessionId, reqId, personNumber, command, querySpan, comment, note);

                if (response?.Status == ApiConstants.Failure)
                {
                    if (response.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                    {
                        await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                    }
                    else
                    {
                        await context.PostAsync(Resources.KronosResourceText.UnableToProceed);
                    }
                }

                if (response?.Status == ApiConstants.Success)
                {
                    var empConversationId = await this.commonActivity.GetEmpConversationId(personNumber, tenantId, jSessionId, activity.ChannelId);

                    var status = command == Constants.ApproveTimeoff ? Resources.KronosResourceText.Approved : Resources.KronosResourceText.Refused;

                    if (empConversationId == null)
                    {
                        await context.PostAsync(Resources.KronosResourceText.EmpNotFoundForNotification);
                    }
                    else
                    {
                        await this.SendApprovalResponseNotiToEmployee(tenantId, context, status, empConversationId, note);
                    }

                    var reply = Resources.KronosResourceText.TimeOffApprovalReply;
                    reply = reply.Replace("{status}", status);
                    reply = reply.Replace("{paycode}", payCode);
                    await context.PostAsync(reply);
                }
            }

            context.Done(default(string));
        }
Exemple #2
0
        private async Task SubmitTimeOffApproval(IDialogContext context, string command)
        {
            try
            {
                var     activity = context.Activity as Activity;
                JToken  token    = JObject.Parse(activity.Value.ToString()).SelectToken("data");
                JObject tenant   = context.Activity.ChannelData as JObject;
                string  tenantId = tenant["tenant"].SelectToken("id").ToString();

                string jSessionId     = this.response?.JsessionID;
                string personNumber   = (string)token.SelectToken("PersonNumber");
                string querySpan      = (string)token.SelectToken("QueryDateSpan");
                string reqId          = (string)token.SelectToken("RequestId");
                string index          = (string)token.SelectToken("Index");
                string currentPage    = (string)token.SelectToken("CurrentPage");
                string comment        = (string)token.SelectToken("Comment");
                string note           = (string)token.SelectToken("note");
                string conversationId = (string)token.SelectToken("conversationId");
                string activityId     = (string)token.SelectToken("activityId");
                command = command.ToLowerInvariant() == Constants.TORApproveRequest.ToLowerInvariant() ? Constants.ApproveTimeoff : Constants.RefuseTimeoff;
                Models.ResponseEntities.TimeOff.SubmitResponse.Response response = await this.timeOffRequestActivity.SubmitApproval(tenantId, jSessionId, reqId, personNumber, command, querySpan, comment, note);

                if (response?.Status == ApiConstants.Failure)
                {
                    if (response.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                    {
                        await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                    }
                    else
                    {
                        await context.PostAsync(response.Error.DetailErrors.Error.FirstOrDefault().Message.Substring(9));
                    }
                }

                if (response?.Status == ApiConstants.Success)
                {
                    var empConversationId = await this.commonActivity.GetEmpConversationId(personNumber, tenantId, jSessionId, activity.ChannelId);

                    var status = command.ToLowerInvariant() == Constants.ApproveTimeoff.ToLowerInvariant() ? Constants.Approved.ToUpper() : Constants.Refused.ToUpper();

                    if (empConversationId == null)
                    {
                        await context.PostAsync(Resources.KronosResourceText.EmpNotFoundForNotification);
                    }
                    else
                    {
                        await this.SendApprovalResponseNotiToEmployee(tenantId, context, status, empConversationId, note, querySpan, reqId);
                    }

                    var pagewiseRequests = context.PrivateConversationData.GetValue <Hashtable>("PagewiseRequests");
                    var toChange         = JsonConvert.DeserializeObject <List <TimeOffResponse.GlobalTimeOffRequestItem> >(Convert.ToString(pagewiseRequests[Convert.ToString(Convert.ToInt32(currentPage) - 1)]));
                    for (int i = 0; i < toChange.Count; i++)
                    {
                        if (i == Convert.ToInt32(index))
                        {
                            toChange[i].StatusName = status;
                        }
                    }

                    pagewiseRequests[Convert.ToString(Convert.ToInt32(currentPage) - 1)] = JsonConvert.SerializeObject(toChange).ToString();
                    context.PrivateConversationData.SetValue("PagewiseRequests", pagewiseRequests);
                    var            employeesHashTable     = context.PrivateConversationData.GetValue <Hashtable>("EmployeeHashTable");
                    var            employeesRoleHashTable = context.PrivateConversationData.GetValue <Hashtable>("EmployeeRoleHashTable");
                    var            filtersHashTable       = context.PrivateConversationData.GetValue <Hashtable>("FiltersHashTable");
                    ViewTorListObj obj = new ViewTorListObj
                    {
                        Employees        = employeesHashTable,
                        Filters          = filtersHashTable,
                        EmployeesRoles   = employeesRoleHashTable,
                        TotalPages       = pagewiseRequests.Count,
                        CurrentPageCount = Convert.ToInt32(currentPage),
                    };

                    // string actionSet = "FR";
                    string actionSet = "F";
                    if (obj.TotalPages != 1)
                    {
                        if (obj.CurrentPageCount < obj.TotalPages && obj.CurrentPageCount > 1)
                        {
                            // actionSet = "FRNP";
                            actionSet = "FNP";
                        }
                        else if (obj.CurrentPageCount == 1)
                        {
                            // actionSet = "FRN";
                            actionSet = "FN";
                        }
                        else if (obj.CurrentPageCount == obj.TotalPages)
                        {
                            // actionSet = "FRP";
                            actionSet = "FP";
                        }
                    }

                    var          comments = context.PrivateConversationData.GetValue <List <Models.ResponseEntities.CommentList.Comment> >("Comments");
                    AdaptiveCard card     = new AdaptiveCard("1.0");
                    card = this.supervisorTimeOffcard.GetCard(JsonConvert.DeserializeObject <List <TimeOffResponse.GlobalTimeOffRequestItem> >(Convert.ToString(pagewiseRequests[Convert.ToString(obj.CurrentPageCount - 1)])), obj, actionSet, comments);

                    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);
                }

                context.Done(default(string));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Create time off request draft and submit it.
        /// </summary>
        /// <param name="context">Dialog context.</param>
        /// <returns>Task.</returns>
        private async Task SubmitAdvancedTimeOffRequest(IDialogContext context)
        {
            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);
            }

            var     activity = context.Activity as Activity;
            JToken  token    = JObject.Parse(activity.Value.ToString());
            JObject tenant   = context.Activity.ChannelData as JObject;
            string  tenantId = tenant["tenant"].SelectToken("id").ToString();

            var advancedObj = context.PrivateConversationData.GetValue <AdvancedTimeOff>("AdvancedRequestObj");

            advancedObj.Comment = (string)token.SelectToken("Comment");
            advancedObj.Note    = (string)token.SelectToken("note");

            if (!string.IsNullOrEmpty(advancedObj.Note) && string.IsNullOrEmpty(advancedObj.Comment))
            {
                await context.PostAsync(Resources.KronosResourceText.CommentSelectionValidation);
            }
            else
            {
                context.PrivateConversationData.SetValue("AdvancedRequestObj", advancedObj);
                DateTime.TryParse(advancedObj.sdt, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sdt);
                DateTime.TryParse(advancedObj.edt, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime edt);

                edt = edt.AddHours(23);
                edt = edt.AddMinutes(59);
                string querySpan = sdt.ToString("M/d/yyyy", CultureInfo.InvariantCulture) + "-" + edt.ToString("M/d/yyyy", CultureInfo.InvariantCulture);

                var startDate = sdt.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);
                var endDate   = edt.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);

                advancedObj.sdt = startDate;
                advancedObj.edt = endDate;

                string jSessionId   = this.response?.JsessionID;
                string personNumber = this.response?.PersonNumber;
                context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession);

                Models.ResponseEntities.TimeOff.AddResponse.Response timeOffResponse = await this.timeOffActivity.AdvancedTimeOffRequest(tenantId, jSessionId, personNumber, advancedObj);

                if (timeOffResponse?.Status == ApiConstants.Failure)
                {
                    if (timeOffResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                    {
                        await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                    }
                    else
                    {
                        await context.PostAsync(Resources.KronosResourceText.UnableToProceed);
                    }
                }

                if (timeOffResponse?.Status == ApiConstants.Success)
                {
                    Models.ResponseEntities.TimeOff.SubmitResponse.Response submitTimeOffResponse = await this.timeOffActivity.SubmitTimeOffRequest(tenantId, jSessionId, personNumber, timeOffResponse.EmployeeRequestMgm.RequestItem.GlobalTimeOffRequestItms.FirstOrDefault().Id, querySpan);

                    if (submitTimeOffResponse?.Status == ApiConstants.Failure)
                    {
                        if (submitTimeOffResponse.Error.DetailErrors.Error.FirstOrDefault().ErrorCode == "611")
                        {
                            await context.PostAsync(Resources.KronosResourceText.TimeOffRequestOverlap);
                        }
                        else
                        {
                            await context.PostAsync(Resources.KronosResourceText.UnableToProceed);
                        }
                    }

                    if (submitTimeOffResponse?.Status == ApiConstants.Success)
                    {
                        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));
                        var card = this.timeOffCard.ShowTimeOffSuccessCard(context, timeOffResponse, advancedObj);
                        var supervisorConversationId = await this.commonActivity.GetConversationId(personNumber, tenantId, superSession, activity.ChannelId);

                        var timePeriod = advancedObj.duration.ToLowerInvariant() == Constants.FullDay.ToLowerInvariant() ? Constants.FullDay : advancedObj.duration.ToLowerInvariant() == Constants.HalfDay.ToLowerInvariant() ? Constants.HalfDay : advancedObj.duration.ToLowerInvariant() == Constants.FirstHalfDay.ToLowerInvariant() ? Constants.FirstHalfDay : Constants.Hours;
                        if (advancedObj.duration.ToLowerInvariant() == Constants.Hours.ToLowerInvariant())
                        {
                            var shr   = Convert.ToInt32(advancedObj.StartTime.Split(' ')[0].Split(':')[0]);
                            var smin  = Convert.ToInt32(advancedObj.StartTime.Split(' ')[0].Split(':')[1]);
                            var ehr   = Convert.ToInt32(advancedObj.EndTime.Split(' ')[0].Split(':')[0]);
                            var emin  = Convert.ToInt32(advancedObj.EndTime.Split(' ')[0].Split(':')[1]);
                            var stime = new DateTime(2000, 1, 1, shr, smin, 0);
                            var etime = new DateTime(2000, 1, 1, ehr, emin, 0);
                            timePeriod += " (" + stime.ToString("h:mm tt", CultureInfo.InvariantCulture) + " to " + etime.ToString("h:mm tt", CultureInfo.InvariantCulture) + ")";
                        }

                        var period   = timeOffResponse.EmployeeRequestMgm.RequestItem.GlobalTimeOffRequestItms.FirstOrDefault().TimeOffPeriodsList.TimeOffPerd.FirstOrDefault();
                        var duration = period.Duration == Constants.full_day ? Constants.FullDay : period.Duration == Constants.half_day ? Constants.HalfDay : period.Duration == Constants.first_half_day ? Constants.FirstHalfDay : Constants.Hours;
                        if (supervisorConversationId != null)
                        {
                            await this.SendNotificationToSupervisor(tenantId, personNumber, timeOffResponse.EmployeeRequestMgm.RequestItem.GlobalTimeOffRequestItms.FirstOrDefault().Id, supervisorConversationId, advancedObj.DeductFrom, context, duration, advancedObj);
                        }

                        try
                        {
                            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);

                            if (supervisorConversationId == null)
                            {
                                await context.PostAsync(Resources.KronosResourceText.SupervisorNotFoundForNotification);
                            }

                            context.PrivateConversationData.RemoveValue("AdvancedRequestObj");
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                }
            }

            context.Done(default(string));
        }
Exemple #4
0
        /// <summary>
        /// Create time off request draft and submit it.
        /// </summary>
        /// <param name="context">Dialog context.</param>
        /// <returns>Task.</returns>
        private async Task SubmitTimeOffRequest(IDialogContext context)
        {
            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);
            }

            var     activity = context.Activity as Activity;
            JToken  token    = JObject.Parse(activity.Value.ToString());
            JObject tenant   = context.Activity.ChannelData as JObject;
            string  tenantId = tenant["tenant"].SelectToken("id").ToString();

            DateTime.TryParse((string)token.SelectToken("sdt"), CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sdt);
            DateTime.TryParse((string)token.SelectToken("edt"), CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime edt);
            string querySpan = sdt.ToString("M/d/yyyy", CultureInfo.InvariantCulture) + "-" + edt.ToString("M/d/yyyy", CultureInfo.InvariantCulture);

            edt = edt.AddHours(23);
            edt = edt.AddMinutes(59);
            var startDate = sdt.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);
            var endDate   = edt.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture);

            string jSessionId   = this.response?.JsessionID;
            string personNumber = this.response?.PersonNumber;

            context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession);
            Models.ResponseEntities.TimeOff.AddResponse.Response timeOffResponse = await this.timeOffActivity.TimeOffRequest(tenantId, jSessionId, startDate, endDate, personNumber, (string)token.SelectToken("reason"));

            if (timeOffResponse?.Status == ApiConstants.Failure)
            {
                if (timeOffResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError)
                {
                    await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity);
                }
            }

            if (timeOffResponse?.Status == ApiConstants.Success)
            {
                Models.ResponseEntities.TimeOff.SubmitResponse.Response submitTimeOffResponse = await this.timeOffActivity.SubmitTimeOffRequest(tenantId, jSessionId, personNumber, timeOffResponse.EmployeeRequestMgm.RequestItem.GlobalTimeOffRequestItms.FirstOrDefault().Id, querySpan);

                if (submitTimeOffResponse?.Status == ApiConstants.Failure)
                {
                    if (submitTimeOffResponse?.Error.DetailErrors.Error.FirstOrDefault().ErrorCode == "611")
                    {
                        await context.PostAsync(Resources.KronosResourceText.TimeOffRequestOverlap);
                    }
                    else
                    {
                        await context.PostAsync(Resources.KronosResourceText.UnableToProceed);
                    }
                }

                if (submitTimeOffResponse?.Status == ApiConstants.Success)
                {
                    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));
                    var card = this.timeOffCard.ShowTimeOffSuccessCard(context, timeOffResponse, null);

                    var supervisorConversationId = await this.commonActivity.GetConversationId(personNumber, tenantId, superSession, activity.ChannelId);

                    if (supervisorConversationId != null)
                    {
                        await this.SendNotificationToSupervisor(tenantId, personNumber, timeOffResponse.EmployeeRequestMgm.RequestItem.GlobalTimeOffRequestItms.FirstOrDefault().Id, supervisorConversationId, (string)token.SelectToken("reason"), context, "Full Day", null);
                    }

                    try
                    {
                        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);

                        if (supervisorConversationId == null)
                        {
                            await context.PostAsync(Resources.KronosResourceText.SupervisorNotFoundForNotification);
                        }
                    }
                    catch (Exception)
                    {
                        return;
                    }
                    finally
                    {
                        context.PrivateConversationData.RemoveValue("AdvancedRequestObj");
                    }
                }
            }

            context.Done(default(string));
        }