/// <summary>
        /// Swap submit card.
        /// </summary>
        /// <param name="context">dialog context.</param>
        /// <param name="obj">selected values from previous cards.</param>
        /// <param name="comment">passed note while approving.</param>
        /// <param name="status">swap shift request status.</param>
        /// <returns>basic swap request card.</returns>
        public AdaptiveCard GetSwapSubmitCard(IDialogContext context, SwapShiftObj obj, string comment, string status)
        {
            string fullPath     = HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SwapShift/Notification.json");
            var    adaptiveCard = File.ReadAllText(fullPath);

            adaptiveCard = adaptiveCard.Replace("{Info}", KronosResourceText.RequestedSwapShiftByYou + " " + obj.RequestedToName).Replace("{Title}", KronosResourceText.SwapShiftConfirmTitle);
            adaptiveCard = adaptiveCard.Replace("{LeftBar}", Constants.WhiteBar);
            adaptiveCard = adaptiveCard.Replace("{LeftDate}", obj.Emp1FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{LeftTimeSpan}", obj.Emp1FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp1ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{LeftHours}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Hours.ToString());
            adaptiveCard = adaptiveCard.Replace("{LeftMin}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Minutes.ToString());
            adaptiveCard = adaptiveCard.Replace("{LeftText}", KronosResourceText.AssignedToYou);
            adaptiveCard = adaptiveCard.Replace("{SwapIcon}", Constants.SwapIcon);
            adaptiveCard = adaptiveCard.Replace("{RightBar}", Constants.WhiteBar);
            adaptiveCard = adaptiveCard.Replace("{RightDate}", obj.Emp2FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{RightTimeSpan}", obj.Emp2FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp2ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{RightHours}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Hours.ToString());
            adaptiveCard = adaptiveCard.Replace("{RightMin}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Minutes.ToString());
            adaptiveCard = adaptiveCard.Replace("{RightText}", KronosResourceText.AssignedTo + " " + obj.RequestedToName);
            adaptiveCard = adaptiveCard.Replace("{StatusImage}", status.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant() ? Constants.PendingImg : string.Empty);
            adaptiveCard = adaptiveCard.Replace("{txt_Note}", KronosResourceText.Note).Replace("{txt_Updated}", KronosResourceText.Updated);
            adaptiveCard = adaptiveCard.Replace("{Updated}", context.Activity.LocalTimestamp.Value.DateTime.ToString("MMM dd, h:mm tt", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{Note}", comment ?? "(none)");

            var card = AdaptiveCard.FromJson(adaptiveCard).Card;

            return(card);
        }
        /// <summary>
        /// Swap confirmation card.
        /// </summary>
        /// <param name="context">dialog context.</param>
        /// <param name="obj">selected values from previous cards.</param>
        /// <returns>basic swap confirmation request card.</returns>
        public AdaptiveCard GetSwapShiftCnfCard(IDialogContext context, SwapShiftObj obj)
        {
            string fullPath     = HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SwapShift/Confirmation.json");
            var    adaptiveCard = File.ReadAllText(fullPath);

            adaptiveCard = adaptiveCard.Replace("{Info}", KronosResourceText.RequestedSwapShiftByYou + obj.RequestedToName).Replace("{Title}", KronosResourceText.SwapShiftConfirmTitle);
            adaptiveCard = adaptiveCard.Replace("{LeftBar}", Constants.WhiteBar);
            adaptiveCard = adaptiveCard.Replace("{LeftDate}", obj.Emp1FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{LeftTimeSpan}", obj.Emp1FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp1ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{LeftHours}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Hours.ToString());
            adaptiveCard = adaptiveCard.Replace("{LeftMin}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Minutes.ToString());
            adaptiveCard = adaptiveCard.Replace("{LeftText}", obj.RequestorName);
            adaptiveCard = adaptiveCard.Replace("{SwapIcon}", Constants.SwapIcon);
            adaptiveCard = adaptiveCard.Replace("{RightBar}", Constants.WhiteBar);
            adaptiveCard = adaptiveCard.Replace("{RightDate}", obj.Emp2FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{RightTimeSpan}", obj.Emp2FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp2ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
            adaptiveCard = adaptiveCard.Replace("{RightHours}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Hours.ToString());
            adaptiveCard = adaptiveCard.Replace("{RightMin}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Minutes.ToString());
            adaptiveCard = adaptiveCard.Replace("{RightText}", obj.RequestedToName);
            adaptiveCard = adaptiveCard.Replace("{StatusImage}", Constants.PendingImg);

            var card = AdaptiveCard.FromJson(adaptiveCard).Card;

            return(card);
        }
        /// <summary>
        /// Confirm swap shift submit.
        /// </summary>
        /// <param name="context">Dialog context.</param>
        /// <param name="obj">Swap shift object.</param>
        /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
        public async Task SwapShiftConfirmation(IDialogContext context, SwapShiftObj obj)
        {
            try
            {
                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();

                AdaptiveCard card = this.swapShiftCard.GetSwapShiftCnfCard(context, obj);

                IConnectorClientFactory factory = new ConnectorClientFactory(Address.FromActivity(context.Activity), new MicrosoftAppCredentials(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword));
                var conversationId = context.Activity.Conversation.Id;
                var activityId     = context.Activity.ReplyToId;

                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);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public string CreateSwapShiftDraftRequest(SwapShiftObj obj)
        {
            var requestorEmployee = new Models.RequestEntities.Hours.Employee
            {
                PersonIdentity = new Models.RequestEntities.Hours.PersonIdentity {
                    PersonNumber = obj.RequestorPersonNumber
                }
            };

            var requestedToEmployee = new Models.RequestEntities.Hours.Employee
            {
                PersonIdentity = new Models.RequestEntities.Hours.PersonIdentity {
                    PersonNumber = obj.RequestedToPersonNumber
                }
            };

            SwapShiftRequest.Request rq = new SwapShiftRequest.Request()
            {
                Action = ApiConstants.AddRequests,
                EmployeeRequestMgmt = new SwapShiftRequest.EmployeeRequestMgmt
                {
                    Employee      = requestorEmployee,
                    QueryDateSpan = obj.QueryDateSpan,
                    RequestItems  = new SwapShiftRequest.RequestItems
                    {
                        SwapShiftRequestItem = new SwapShiftRequest.SwapShiftRequestItem
                        {
                            Employee     = requestorEmployee,
                            RequestFor   = "Shift Swap Request",
                            OfferedShift = new SwapShiftRequest.OfferedShift
                            {
                                ShiftRequestItem = new SwapShiftRequest.ShiftRequestItem
                                {
                                    Employee      = requestorEmployee,
                                    EndDateTime   = obj.Emp1ToDateTime.ToString("MM/d/yyyy hh:mmtt", CultureInfo.InvariantCulture),
                                    OrgJobPath    = obj.SelectedJob,
                                    StartDateTime = obj.Emp1FromDateTime.ToString("MM/d/yyyy hh:mmtt", CultureInfo.InvariantCulture),
                                }
                            },
                            RequestedShift = new SwapShiftRequest.RequestedShift
                            {
                                ShiftRequestItem = new SwapShiftRequest.ShiftRequestItem
                                {
                                    Employee      = requestedToEmployee,
                                    EndDateTime   = obj.Emp2ToDateTime.ToString("MM/d/yyyy hh:mmtt", CultureInfo.InvariantCulture),
                                    OrgJobPath    = obj.SelectedJob,
                                    StartDateTime = obj.Emp2FromDateTime.ToString("MM/d/yyyy hh:mmtt", CultureInfo.InvariantCulture),
                                }
                            }
                        }
                    }
                }
            };

            return(rq.XmlSerialize <SwapShiftRequest.Request>());
        }
        private SwapShiftObj ParseSwapShiftToken(JToken obj)
        {
            SwapShiftObj ss = new SwapShiftObj
            {
                Emp1FromDateTime        = Convert.ToDateTime(obj.SelectToken("Emp1FromDateTime")),
                Emp1ToDateTime          = Convert.ToDateTime(obj.SelectToken("Emp1ToDateTime")),
                Emp2FromDateTime        = Convert.ToDateTime(obj.SelectToken("Emp2FromDateTime")),
                Emp2ToDateTime          = Convert.ToDateTime(obj.SelectToken("Emp2ToDateTime")),
                QueryDateSpan           = Convert.ToString(obj.SelectToken("QueryDateSpan")),
                RequestedToName         = Convert.ToString(obj.SelectToken("RequestedToName")),
                RequestedToPersonNumber = Convert.ToString(obj.SelectToken("RequestedToPersonNumber")),
                RequestId              = Convert.ToString(obj.SelectToken("RequestId")),
                RequestorName          = Convert.ToString(obj.SelectToken("RequestorName")),
                RequestorPersonNumber  = Convert.ToString(obj.SelectToken("RequestorPersonNumber")),
                SelectedAvailableShift = Convert.ToString(obj.SelectToken("SelectedAvailableShift")),
                SelectedEmployee       = Convert.ToString(obj.SelectToken("SelectedEmployee")),
                SelectedJob            = Convert.ToString(obj.SelectToken("SelectedJob")),
                SelectedLocation       = Convert.ToString(obj.SelectToken("SelectedLocation")),
                SelectedShiftToSwap    = Convert.ToString(obj.SelectToken("SelectedShiftToSwap")),
            };

            return(ss);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The method to create the Swap Shift Request in Draft state.
        /// </summary>
        /// <param name="jSession">The jSession.</param>
        /// <param name="obj">The input SwapShiftObj.</param>
        /// <param name="apiEndpoint">The Kronos API Endpoint.</param>
        /// <returns>A unit of execution that contains the response object.</returns>
        public async Task <SubmitResponse.Response> DraftSwapShiftAsync(
            string jSession,
            SwapShiftObj obj,
            string apiEndpoint)
        {
            this.telemetryClient.TrackTrace($"SwapShiftActivity - DraftSwapShiftAsync starts at: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}");

            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            try
            {
                string xmlRequest = this.CreateSwapShiftDraftRequest(obj);

                var tupleResponse = await this.apiHelper.SendSoapPostRequestAsync(
                    new Uri(apiEndpoint),
                    ApiConstants.SoapEnvOpen,
                    xmlRequest,
                    ApiConstants.SoapEnvClose,
                    jSession).ConfigureAwait(false);

                SubmitResponse.Response response = this.ProcessSwapShiftDraftResponse(tupleResponse.Item1);

                this.telemetryClient.TrackTrace($"SwapShiftActivity - DraftSwapShiftAsync ends at: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}");

                return(response);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                this.telemetryClient.TrackException(ex);
                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method will create the XML request string for a Swap Shift Request.
        /// </summary>
        /// <param name="swapShiftObj">The current swap shift object.</param>
        /// <returns>A string that represents the XML request.</returns>
        private string CreateSwapShiftDraftRequest(SwapShiftObj swapShiftObj)
        {
            this.telemetryClient.TrackTrace($"SwapShiftActivity - CreateSwapShiftDraftRequest starts: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}");

            var requestorEmployee = new Employee
            {
                PersonIdentity = new Models.RequestEntities.OpenShift.ApproveDecline.RequestManagementApproveDecline.PersonIdentity
                {
                    PersonNumber = swapShiftObj.RequestorPersonNumber,
                },
            };

            var requestedToEmployee = new Employee
            {
                PersonIdentity = new Models.RequestEntities.OpenShift.ApproveDecline.RequestManagementApproveDecline.PersonIdentity
                {
                    PersonNumber = swapShiftObj.RequestedToPersonNumber,
                },
            };

            SubmitRequest.Request rq = new SubmitRequest.Request()
            {
                Action = ApiConstants.AddRequests,
                EmployeeRequestMgmt = new EmployeeRequestMgmt
                {
                    Employee      = requestorEmployee,
                    QueryDateSpan = swapShiftObj.QueryDateSpan,
                    RequestItems  = new RequestItems
                    {
                        SwapShiftRequestItem = new SwapShiftRequestItem
                        {
                            Employee     = requestorEmployee,
                            RequestFor   = ApiConstants.SwapShiftRequest,
                            OfferedShift = new OfferedShift
                            {
                                ShiftRequestItem = new ShiftRequestItem
                                {
                                    Employee = requestorEmployee,

                                    // The Kronos is expecting only these formats to be serialized,
                                    // however we are converting the correct date format while creating actual shifts, timeoff etc.
                                    EndDateTime   = swapShiftObj.Emp1ToDateTime.ToString(ApiConstants.KronosAcceptableDateFormat, System.Globalization.CultureInfo.InvariantCulture),
                                    OrgJobPath    = swapShiftObj.SelectedJob,
                                    StartDateTime = swapShiftObj.Emp1FromDateTime.ToString(ApiConstants.KronosAcceptableDateFormat, System.Globalization.CultureInfo.InvariantCulture),
                                },
                            },
                            RequestedShift = new RequestedShift
                            {
                                ShiftRequestItem = new ShiftRequestItem
                                {
                                    Employee      = requestedToEmployee,
                                    EndDateTime   = swapShiftObj.Emp2ToDateTime.ToString(ApiConstants.KronosAcceptableDateFormat, System.Globalization.CultureInfo.InvariantCulture),
                                    OrgJobPath    = swapShiftObj.SelectedJob,
                                    StartDateTime = swapShiftObj.Emp2FromDateTime.ToString(ApiConstants.KronosAcceptableDateFormat, System.Globalization.CultureInfo.InvariantCulture),
                                },
                            },
                        },
                    },
                },
            };

            this.telemetryClient.TrackTrace($"SwapShiftActivity - CreateSwapShiftDraftRequest: {rq.XmlSerialize().ToString(CultureInfo.InvariantCulture)}");
            this.telemetryClient.TrackTrace($"SwapShiftActivity - CreateSwapShiftDraftRequest ends: {DateTime.UtcNow.ToString("O", CultureInfo.InvariantCulture)}");
            return(rq.XmlSerialize());
        }
        /// <summary>
        /// Filter shifts option based on employees and job roles.
        /// </summary>
        /// <param name="context">dialog context.</param>
        /// <param name="obj">selected values from previous cards.</param>
        /// <param name="comment">passed note while approving.</param>
        /// <param name="comments">selected comment while approving.</param>
        /// <param name="approvalType">approvaltype = Manager/Employee.</param>
        /// <returns>basic filter card card.</returns>
        public AdaptiveCard GetNotificationCard(IDialogContext context, SwapShiftObj obj, string comment, Models.ResponseEntities.CommentList.Response comments, int approvalType)
        {
            string fullPath     = HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SwapShift/ApprovalNotification.json");
            var    adaptiveCard = File.ReadAllText(fullPath);

            if (approvalType == 1)
            {
                adaptiveCard = adaptiveCard.Replace("{Title}", KronosResourceText.SwapShiftConfirmTitle);
                adaptiveCard = adaptiveCard.Replace("{Info}", obj.RequestorName + " " + KronosResourceText.RequestedShiftSwapWith);
                adaptiveCard = adaptiveCard.Replace("{LeftBar}", Constants.WhiteBar);
                adaptiveCard = adaptiveCard.Replace("{LeftDate}", obj.Emp2FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{LeftTimeSpan}", obj.Emp2FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp2ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{LeftHours}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Hours.ToString());
                adaptiveCard = adaptiveCard.Replace("{LeftMin}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Minutes.ToString());
                adaptiveCard = adaptiveCard.Replace("{LeftText}", KronosResourceText.AssignedToYou);
                adaptiveCard = adaptiveCard.Replace("{SwapIcon}", Constants.SwapIcon);
                adaptiveCard = adaptiveCard.Replace("{RightBar}", Constants.WhiteBar);
                adaptiveCard = adaptiveCard.Replace("{RightDate}", obj.Emp1FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{RightTimeSpan}", obj.Emp1FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp1ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{RightHours}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Hours.ToString());
                adaptiveCard = adaptiveCard.Replace("{RightMin}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Minutes.ToString());
                adaptiveCard = adaptiveCard.Replace("{RightText}", KronosResourceText.AssignedTo + obj.RequestorName);
                adaptiveCard = adaptiveCard.Replace("{txt_Updated}", KronosResourceText.Updated);
                adaptiveCard = adaptiveCard.Replace("{StatusImage}", Constants.PendingImg);
                adaptiveCard = adaptiveCard.Replace("{UpdatedOn}", context.Activity.LocalTimestamp.Value.DateTime.ToString("MMM dd, h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{txt_Note}", KronosResourceText.Note);
                adaptiveCard = adaptiveCard.Replace("{Comment}", string.IsNullOrEmpty(comment) ? $"({KronosResourceText.None})" : comment);
                adaptiveCard = adaptiveCard.Replace("{SwapShiftObj}", JsonConvert.SerializeObject(obj, Formatting.None));
                adaptiveCard = adaptiveCard.Replace("{ApproveCmd}", KronosResourceText.ApproveByEmp);
                adaptiveCard = adaptiveCard.Replace("{RefuseCmd}", KronosResourceText.RefuseByEmp);
            }
            else
            {
                adaptiveCard = adaptiveCard.Replace("{Title}", KronosResourceText.SwapShiftConfirmTitle);
                adaptiveCard = adaptiveCard.Replace("{Info}", obj.RequestorName + " " + KronosResourceText.RequestSwapShiftWith + " " + obj.RequestedToName + ".");
                adaptiveCard = adaptiveCard.Replace("{LeftBar}", Constants.WhiteBar);
                adaptiveCard = adaptiveCard.Replace("{LeftDate}", obj.Emp1FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{LeftTimeSpan}", obj.Emp1FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp1ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{LeftHours}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Hours.ToString());
                adaptiveCard = adaptiveCard.Replace("{LeftMin}", obj.Emp1ToDateTime.Subtract(obj.Emp1FromDateTime).Minutes.ToString());
                adaptiveCard = adaptiveCard.Replace("{LeftText}", KronosResourceText.AssignedTo + " " + obj.RequestorName);
                adaptiveCard = adaptiveCard.Replace("{SwapIcon}", Constants.SwapIcon);
                adaptiveCard = adaptiveCard.Replace("{RightBar}", Constants.WhiteBar);
                adaptiveCard = adaptiveCard.Replace("{RightDate}", obj.Emp2FromDateTime.ToString("ddd, MMM d", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{RightTimeSpan}", obj.Emp2FromDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture) + Separator + obj.Emp2ToDateTime.ToString("h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{RightHours}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Hours.ToString());
                adaptiveCard = adaptiveCard.Replace("{RightMin}", obj.Emp2ToDateTime.Subtract(obj.Emp2FromDateTime).Minutes.ToString());
                adaptiveCard = adaptiveCard.Replace("{RightText}", KronosResourceText.AssignedTo + " " + obj.RequestedToName);
                adaptiveCard = adaptiveCard.Replace("{txt_Updated}", KronosResourceText.Updated);
                adaptiveCard = adaptiveCard.Replace("{StatusImage}", Constants.PendingImg);
                adaptiveCard = adaptiveCard.Replace("{txt_Note}", KronosResourceText.Note);
                adaptiveCard = adaptiveCard.Replace("{UpdatedOn}", context.Activity.LocalTimestamp.Value.DateTime.ToString("MMM dd, h:mm tt", CultureInfo.InvariantCulture));
                adaptiveCard = adaptiveCard.Replace("{Comment}", string.IsNullOrEmpty(comment) ? $"({KronosResourceText.None})" : comment);
                adaptiveCard = adaptiveCard.Replace("{ApproveCmd}", KronosResourceText.ApproveBySupervisor);
                adaptiveCard = adaptiveCard.Replace("{RefuseCmd}", KronosResourceText.RefuseBySupervisor);
                adaptiveCard = adaptiveCard.Replace("{SwapShiftObj}", JsonConvert.SerializeObject(obj, Formatting.None));
            }

            var row = "{\"title\": \"{Text}\",\"value\": \"{Value}\"}";
            var sb  = new StringBuilder();

            for (int i = 0; i < comments.Comments.Count; i++)
            {
                if (i == 0)
                {
                    sb.Append(row.Replace("{Text}", comments.Comments[i].CommentText).Replace("{Value}", comments.Comments[i].CommentText));
                    adaptiveCard.Replace("{CommentValue}", comments.Comments[i].CommentText);
                }
                else
                {
                    sb.Append(", " + row.Replace("{Text}", comments.Comments[i].CommentText).Replace("{Value}", comments.Comments[i].CommentText));
                }
            }

            adaptiveCard = adaptiveCard.Replace("{CommentRows}", sb.ToString());
            var card = AdaptiveCard.FromJson(adaptiveCard).Card;

            return(card);
        }
        /// <summary>
        /// Send approval notifications.
        /// </summary>
        /// <param name="tenantId">Tenant Id.</param>
        /// <param name="jsession">J Session.</param>
        /// <param name="context">Dialog context.</param>
        /// <param name="conversationId">Conversation Id to which notification has to be sent.</param>
        /// <param name="note">Note entered.</param>
        /// <param name="obj">Swap shift object.</param>
        /// <param name="approvalType">Approval type: 1-Employee, 2-Supervisor.</param>
        /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
        public async Task SendApprovalNotification(string tenantId, string jsession, IDialogContext context, string conversationId, string note, SwapShiftObj obj, int approvalType)
        {
            try
            {
                var    activity = context.Activity as Activity;
                JToken token    = JObject.Parse(activity.Value.ToString());
                context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession);
                var channelData = new TeamsChannelData
                {
                    Tenant = new TenantInfo()
                    {
                        Id = tenantId,
                    },
                };

                var message = Activity.CreateMessageActivity();
                message.From = new ChannelAccount(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword);

                MicrosoftAppCredentials.TrustServiceUrl(context.Activity.ServiceUrl);
                message.ChannelData  = channelData;
                message.ChannelId    = Constants.ActivityChannelId;
                message.Conversation = new ConversationAccount(
                    conversationType: "personal",
                    id: conversationId,
                    isGroup: false);
                var comments = await this.commentsActivity.GetComments(tenantId, superSession);

                AdaptiveCard card = this.swapShiftCard.GetNotificationCard(context, obj, note, comments, approvalType);

                message.Attachments.Add(new Attachment()
                {
                    ContentType = "application/vnd.microsoft.card.adaptive",
                    Content     = card,
                });

                IConnectorClientFactory factory = new ConnectorClientFactory(Address.FromActivity(context.Activity), new MicrosoftAppCredentials(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword));
                await factory.MakeConnectorClient().Conversations.SendToConversationAsync((Activity)message);
            }
            catch (Exception)
            {
                await context.PostAsync("Something went wrong while sending notification");

                throw;
            }
        }
        private async Task ProcessCommand(IDialogContext context, IAwaitable <string> result)
        {
            var     activity = context.Activity as Activity;
            var     message  = await result;
            JObject tenant   = context.Activity.ChannelData as JObject;
            string  tenantId = tenant?["tenant"].SelectToken("id").ToString();

            AppInsightsLogger.CustomEventTrace("SwapShiftDialog", new Dictionary <string, string>()
            {
                { "TenantId", tenantId }, { "User", context.Activity.From.Id }, { "methodName", "ProcessCommand" }, { "Command", message }
            });

            if (message == Constants.SwapShift)
            {
                await this.ShowShiftSelectionCard(context, Constants.SwapShift);
            }
            else if (message == Constants.SwapShiftNext2)
            {
                JToken       token    = JObject.Parse(activity.Value.ToString());
                var          shift    = Convert.ToString(token.SelectToken("SelectedShift"));
                var          splitted = shift.Split('-');
                SwapShiftObj obj      = new SwapShiftObj();
                DateTime     shiftStart;
                DateTime     shiftEnd;
                string       startTime;
                string       endTime;
                if (splitted[2].Length == 6)
                {
                    startTime = splitted[2].Insert(4, " ");
                }
                else
                {
                    startTime = splitted[2].Insert(5, " ");
                }

                if (splitted[3].Length == 6)
                {
                    endTime = splitted[3].Insert(4, " ");
                }
                else
                {
                    endTime = splitted[3].Insert(5, " ");
                }

                DateTime.TryParse(splitted[0] + " " + startTime, CultureInfo.InvariantCulture, DateTimeStyles.None, out shiftStart);
                DateTime.TryParse(splitted[1] + " " + endTime, CultureInfo.InvariantCulture, DateTimeStyles.None, out shiftEnd);

                obj.Emp1FromDateTime      = shiftStart;
                obj.Emp1ToDateTime        = shiftEnd;
                obj.RequestorPersonNumber = splitted[4];
                obj.RequestorName         = splitted[5];
                obj.SelectedShiftToSwap   = shift;

                context.PrivateConversationData.SetValue("SwapShiftObj", obj);
                await this.ShowSearchFilterCard(context, Constants.SwapShiftNext2);
            }
            else if (message == Constants.SwapShiftNext3)
            {
                JToken token            = JObject.Parse(activity.Value.ToString());
                var    selectedLocation = Convert.ToString(token.SelectToken("SelectedLocation"));
                var    selectedJob      = Convert.ToString(token.SelectToken("SelectedJob"));
                var    selectedEmployee = Convert.ToString(token.SelectToken("SelectedEmployee"));
                var    obj = context.PrivateConversationData.GetValue <SwapShiftObj>("SwapShiftObj");
                obj.SelectedEmployee = selectedEmployee;
                obj.SelectedLocation = selectedLocation;
                obj.SelectedJob      = selectedJob;

                context.PrivateConversationData.SetValue("SwapShiftObj", obj);

                await this.ShowAvailableShiftsCard(context, Constants.SwapShiftNext3);
            }
            else if (message == Constants.SwapShiftBack1)
            {
                JToken token             = JObject.Parse(activity.Value.ToString());
                var    selectedLocation1 = Convert.ToString(token.SelectToken("SelectedLocation"));
                var    selectedJob1      = Convert.ToString(token.SelectToken("SelectedJob"));
                var    selectedEmployee1 = Convert.ToString(token.SelectToken("SelectedEmployee"));
                var    obj = context.PrivateConversationData.GetValue <SwapShiftObj>("SwapShiftObj");
                obj.SelectedEmployee = selectedEmployee1;
                obj.SelectedLocation = selectedLocation1;
                obj.SelectedJob      = selectedJob1;

                context.PrivateConversationData.SetValue("SwapShiftObj", obj);
                await this.ShowShiftSelectionCard(context, Constants.SwapShiftBack1);
            }
            else if (message == Constants.SwapShiftBack2)
            {
                JToken token = JObject.Parse(activity.Value.ToString());
                var    selectedShiftToSwap = Convert.ToString(token.SelectToken("Choice1"));
                var    obj = context.PrivateConversationData.GetValue <SwapShiftObj>("SwapShiftObj");
                obj.SelectedShiftToSwap = selectedShiftToSwap;

                context.PrivateConversationData.SetValue("SwapShiftObj", obj);
                await this.ShowSearchFilterCard(context, Constants.SwapShiftBack2);
            }
            else if (message == Constants.SwapShiftBack3)
            {
                await this.ShowAvailableShiftsCard(context, Constants.SwapShiftBack3);
            }
            else if (message == Constants.SwapShiftNext4)
            {
                JToken token = JObject.Parse(activity.Value.ToString());
                var    selectedShiftToSwap = Convert.ToString(token.SelectToken("SelectedShift"));
                var    obj = context.PrivateConversationData.GetValue <SwapShiftObj>("SwapShiftObj");
                obj.SelectedShiftToSwap = selectedShiftToSwap;
                var      splitted = selectedShiftToSwap.Split('-');
                DateTime shiftStart1;
                DateTime shiftEnd1;
                string   startTime1;
                string   endTime1;
                if (splitted[2].Length == 6)
                {
                    startTime1 = splitted[2].Insert(4, " ");
                }
                else
                {
                    startTime1 = splitted[2].Insert(5, " ");
                }

                if (splitted[3].Length == 6)
                {
                    endTime1 = splitted[3].Insert(4, " ");
                }
                else
                {
                    endTime1 = splitted[3].Insert(5, " ");
                }

                DateTime.TryParse(splitted[0] + " " + startTime1, CultureInfo.InvariantCulture, DateTimeStyles.None, out shiftStart1);
                DateTime.TryParse(splitted[1] + " " + endTime1, CultureInfo.InvariantCulture, DateTimeStyles.None, out shiftEnd1);

                obj.Emp2FromDateTime        = shiftStart1;
                obj.Emp2ToDateTime          = shiftEnd1;
                obj.RequestedToPersonNumber = splitted[4];
                obj.RequestedToName         = splitted[5];
                context.PrivateConversationData.SetValue("SwapShiftObj", obj);
                await this.SwapShiftConfirmation(context, obj);
            }
            else if (message == Constants.CancelSwapShift)
            {
                var          conversationId = context.Activity.Conversation.Id;
                var          activityId     = context.Activity.ReplyToId;
                AdaptiveCard card           = new AdaptiveCard("1.0")
                {
                    Body = new List <AdaptiveElement>
                    {
                        new AdaptiveContainer
                        {
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text = KronosResourceText.CancelSwapShift,
                                    Wrap = true,
                                },
                            },
                        },
                    },
                };
                IConnectorClientFactory factory = new ConnectorClientFactory(Address.FromActivity(context.Activity), new MicrosoftAppCredentials(AppSettings.Instance.MicrosoftAppId, AppSettings.Instance.MicrosoftAppPassword));
                context.PrivateConversationData.RemoveValue("SwapShiftObj");
                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 if (message == Constants.SubmitSwapShift)
            {
                await this.SubmitSwapShiftRequest(context);
            }
            else if (message.Contains("approve") || message.Contains("refuse"))
            {
                await this.SubmitApproval(context, message);
            }

            context.Done(default(string));
        }
Exemplo n.º 11
0
        public async Task <SwapShiftResponse.Response> DraftSwapShift(string tenantId, string jSession, SwapShiftObj obj)
        {
            try
            {
                string          xmlRequest      = CreateSwapShiftDraftRequest(obj);
                TenantMapEntity tenantMapEntity = await azureTableStorageHelper.ExecuteQueryUsingPointQueryAsync <TenantMapEntity>(Constants.ActivityChannelId, tenantId);

                var tupleResponse = await ApiHelper.Instance.SendSoapPostRequest(tenantMapEntity.EndpointUrl, ApiConstants.SoapEnvOpen, xmlRequest, ApiConstants.SoapEnvClose, jSession);

                SwapShiftResponse.Response Response = ProcessSwapShiftDraftResponse(tupleResponse.Item1);

                return(Response);
            }
            catch (Exception)
            {
                throw;
            }
        }