private async Task Previous(IDialogContext context) { var activity = context.Activity as Activity; JToken token = JObject.Parse(activity.Value.ToString()); var currentPage = Convert.ToInt32(token.SelectToken("CurrentPage")); var employeesHashTable = context.PrivateConversationData.GetValue <Hashtable>("EmployeeHashTable"); var employeesRoleHashTable = context.PrivateConversationData.GetValue <Hashtable>("EmployeeRoleHashTable"); var filtersHashTable = context.PrivateConversationData.GetValue <Hashtable>("FiltersHashTable"); var pagewiseRequests = context.PrivateConversationData.GetValue <Hashtable>("PagewiseRequests"); ViewTorListObj obj = new ViewTorListObj { Employees = employeesHashTable, EmployeesRoles = employeesRoleHashTable, Filters = filtersHashTable, TotalPages = pagewiseRequests.Count, CurrentPageCount = currentPage - 1, }; // string actionSet = "FRN"; string actionSet = "FN"; if (obj.CurrentPageCount != 1) { // actionSet = "FRNP"; actionSet = "FNP"; } obj.ConversationId = context.Activity.Conversation.Id; obj.ActivityId = context.Activity.ReplyToId; var comments = context.PrivateConversationData.GetValue <List <Models.ResponseEntities.CommentList.Comment> >("Comments"); var current = JsonConvert.DeserializeObject <List <TimeOffResponse.GlobalTimeOffRequestItem> >(Convert.ToString(pagewiseRequests[(obj.CurrentPageCount - 1).ToString()])); var card = this.supervisorTimeOffcard.GetCard(current, obj, actionSet, comments); 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); context.Done(default(string)); }
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; } }
private async Task ShowTimeOffRequests(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); } try { var activity = context.Activity as Activity; JObject tenant = context.Activity.ChannelData as JObject; string tenantId = tenant["tenant"].SelectToken("id").ToString(); string jSessionId = this.response?.JsessionID; string personNumber = this.response?.PersonNumber; context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession); var employeesResult = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, jSessionId, DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), "Report", "Private"); if (employeesResult.Status == ApiConstants.Failure && employeesResult.Error.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } if (employeesResult.Status == ApiConstants.Success) { Hashtable employeesHashTable = new Hashtable(); Hashtable filtersHashTable = new Hashtable(); Hashtable employeesRoleHashTable = new Hashtable(); foreach (var item in employeesResult.HyperFindResult) { employeesHashTable.Add(item.PersonNumber, item.FullName); } if (employeesHashTable.Count > 0) { context.PrivateConversationData.SetValue("EmployeeHashTable", employeesHashTable); var response = await this.timeOffActivity.GetTimeOffRequest(tenantId, jSessionId, DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), employeesResult.HyperFindResult); var requests = response.RequestMgmt?.RequestItems?.GlobalTimeOffRequestItem; var personNumbers = (from d in requests select d.Employee.PersonIdentity.PersonNumber).Distinct().ToList(); var tasks = personNumbers.Select(async emp => { if (!employeesRoleHashTable.ContainsKey(Convert.ToString(emp))) { var jobAssignent = await this.commonActivity.GetJobAssignment(Convert.ToString(emp), tenantId, superSession); var role = jobAssignent?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Split('/').LastOrDefault(); employeesRoleHashTable.Add(Convert.ToString(emp), role); } }); await Task.WhenAll(tasks); context.PrivateConversationData.SetValue("EmployeeRoleHashTable", employeesRoleHashTable); requests = (from d in requests where d.StatusName.ToLower().Equals(Constants.Submitted.ToLower()) select d).ToList(); for (int i = 0; i < requests.Count; i++) { DateTime.TryParse(requests[i].TimeOffPeriods.TimeOffPeriod.StartDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sdt); requests[i].TimeOffPeriods.TimeOffPeriod.Sdt = sdt; } requests = requests.OrderBy(w => w.TimeOffPeriods.TimeOffPeriod.Sdt).ToList(); int totalPages = (requests?.Count > 0) ? (int)Math.Ceiling((double)requests.Count / 5) : 0; var currentPageItems = this.GetPage(requests, 0, 5); Hashtable pagewiseRequests = new Hashtable(); for (int i = 0; i < totalPages; i++) { pagewiseRequests.Add(i.ToString(), JsonConvert.SerializeObject(this.GetPage(requests, i, 5)).ToString()); } context.PrivateConversationData.SetValue("PagewiseRequests", pagewiseRequests); ViewTorListObj obj = new ViewTorListObj { Employees = employeesHashTable, EmployeesRoles = employeesRoleHashTable, Filters = filtersHashTable, TotalPages = totalPages, CurrentPageCount = 1, }; // string actionSet = "FR"; string actionSet = "F"; if (obj.CurrentPageCount < obj.TotalPages) { // actionSet = "FRN"; actionSet = "FN"; } obj.ConversationId = context.Activity.Conversation.Id; obj.ActivityId = context.Activity.ReplyToId; var comments = await this.commentsActivity.GetComments(tenantId, superSession); context.PrivateConversationData.SetValue("Comments", comments?.Comments); AdaptiveCard card = new AdaptiveCard("1.0"); if (requests.Count > 0) { var page = JsonConvert.DeserializeObject <List <TimeOffResponse.GlobalTimeOffRequestItem> >(Convert.ToString(pagewiseRequests[Convert.ToString(obj.CurrentPageCount - 1)])); card = this.supervisorTimeOffcard.GetCard(page, obj, actionSet, comments?.Comments); } else { card = this.supervisorTimeOffcard.GetCard(new List <TimeOffResponse.GlobalTimeOffRequestItem>(), obj, actionSet, comments?.Comments); } var reply = activity.CreateReply(); reply.Attachments = new List <Attachment> { new Attachment() { Content = card, ContentType = "application/vnd.microsoft.card.adaptive", }, }; await context.PostAsync(reply); } else { await context.PostAsync(KronosResourceText.NoEmployees); } } else { await context.PostAsync(KronosResourceText.NoEmployees); } context.Done(default(string)); } catch (Exception) { throw; } }
private async Task ApplyFilter(IDialogContext context, string command) { 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); } try { context.UserData.TryGetValue(context.Activity.From.Id + Constants.SuperUser, out string superSession); var activity = context.Activity as Activity; JObject tenant = context.Activity.ChannelData as JObject; string tenantId = tenant["tenant"].SelectToken("id").ToString(); string jSessionId = this.response?.JsessionID; string personNumber = this.response?.PersonNumber; JToken token = JObject.Parse(activity.Value.ToString()); var empName = Convert.ToString(token.SelectToken("EmpName")); var startDate = Convert.ToString(token.SelectToken("StartDate")); var endDate = Convert.ToString(token.SelectToken("EndDate")); var showCompletedRequests = Convert.ToString(token.SelectToken("ShowCompletedToggle")); var filters = context.PrivateConversationData.ContainsKey("FiltersHashTable") ? context.PrivateConversationData.GetValue <Hashtable>("FiltersHashTable") : new Hashtable(); if (command.ToLowerInvariant() == Constants.TORRemoveEmpName.ToLowerInvariant()) { empName = string.Empty; startDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[0] : null; endDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[1] : null; showCompletedRequests = filters.ContainsKey("ShowCompletedRequests") ? Convert.ToString(filters["ShowCompletedRequests"]) : "false"; } if (command.ToLowerInvariant() == Constants.TORRemoveDateRange.ToLowerInvariant()) { startDate = endDate = null; empName = filters.ContainsKey("EmpName") ? Convert.ToString(filters["EmpName"]) : string.Empty; } if (command.ToLowerInvariant() == Constants.TORRemoveShowCompletedRequests.ToLowerInvariant()) { empName = filters.ContainsKey("EmpName") ? Convert.ToString(filters["EmpName"]) : string.Empty; startDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[0] : null; endDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[1] : null; showCompletedRequests = "false"; } if (command.ToLowerInvariant() == Constants.TORListRefresh.ToLowerInvariant()) { empName = filters.ContainsKey("EmpName") ? Convert.ToString(filters["EmpName"]) : string.Empty; startDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[0] : null; endDate = filters.ContainsKey("DateRange") ? Convert.ToString(filters["DateRange"]).Split(';')[1] : null; showCompletedRequests = filters.ContainsKey("ShowCompletedRequests") ? Convert.ToString(filters["ShowCompletedRequests"]) : "false"; } AdaptiveCard card = new AdaptiveCard("1.0"); DateTime sdt1 = DateTime.Now; DateTime edt = DateTime.Now; if (!string.IsNullOrEmpty(startDate) && string.IsNullOrEmpty(endDate)) { await context.PostAsync(Resources.KronosResourceText.SelectEndDate); context.Done(default(string)); return; } if (string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate)) { await context.PostAsync(Resources.KronosResourceText.SelectStartDate); context.Done(default(string)); return; } var employeesResult = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, jSessionId, DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), "Report", "Private"); if (employeesResult.Status == ApiConstants.Failure && employeesResult.Error.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } if (employeesResult.Status == ApiConstants.Success) { Hashtable employeesHashTable = new Hashtable(); Hashtable employeesRoleHashTable = new Hashtable(); Hashtable filtersHashTable = new Hashtable(); List <Models.ResponseEntities.HyperFind.ResponseHyperFindResult> filteredEmployees = new List <Models.ResponseEntities.HyperFind.ResponseHyperFindResult>(); if (!string.IsNullOrEmpty(empName)) { var empSplit = empName.Split(';'); filteredEmployees = employeesResult.HyperFindResult.Where(n => empSplit.Any(m => n.FullName.ToLower().Contains(m.ToLower()))).ToList(); } else { filteredEmployees = employeesResult.HyperFindResult; } empName = string.Join(";", filteredEmployees.Select(w => w.FullName).ToArray()); filtersHashTable.Add("EmpName", empName); foreach (var item in filteredEmployees) { employeesHashTable.Add(item.PersonNumber, item.FullName); } context.PrivateConversationData.SetValue("EmployeeHashTable", employeesHashTable); if (!string.IsNullOrEmpty(startDate)) { DateTime.TryParse(startDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out sdt1); DateTime.TryParse(endDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out edt); filtersHashTable.Add("DateRange", startDate + ";" + endDate); } if (filteredEmployees.Count == 0) { await context.PostAsync(KronosResourceText.NoEmployees); } else { var response = await this.timeOffActivity.GetTimeOffRequest(tenantId, jSessionId, sdt1.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), edt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture), filteredEmployees); var requests = response.RequestMgmt?.RequestItems?.GlobalTimeOffRequestItem; requests = requests.Where(w => w.StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant() || w.StatusName.ToLowerInvariant() == Constants.Approved.ToLowerInvariant() || w.StatusName.ToLowerInvariant() == Constants.Refused.ToLowerInvariant()).ToList(); for (int i = 0; i < requests.Count; i++) { DateTime.TryParse(requests[i].TimeOffPeriods.TimeOffPeriod.StartDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sdt); requests[i].TimeOffPeriods.TimeOffPeriod.Sdt = sdt; } requests = requests.OrderBy(w => w.TimeOffPeriods.TimeOffPeriod.Sdt).ToList(); var personNumbers = (from d in requests select d.Employee.PersonIdentity.PersonNumber).Distinct().ToList(); var tasks = personNumbers.Select(async emp => { if (!employeesRoleHashTable.ContainsKey(Convert.ToString(emp))) { var jobAssignent = await this.commonActivity.GetJobAssignment(Convert.ToString(emp), tenantId, superSession); var role = jobAssignent?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Split('/').LastOrDefault(); employeesRoleHashTable.Add(Convert.ToString(emp), role); } }); await Task.WhenAll(tasks); context.PrivateConversationData.SetValue("EmployeeRoleHashTable", employeesRoleHashTable); if (!string.IsNullOrEmpty(showCompletedRequests)) { if (showCompletedRequests.ToLowerInvariant() == "true") { requests = requests.Where(w => (w.StatusName.ToLowerInvariant() == Constants.Approved.ToLowerInvariant()) || (w.StatusName.ToLowerInvariant() == Constants.Refused.ToLowerInvariant())).ToList(); } else { requests = requests.Where(w => (w.StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant())).ToList(); } filtersHashTable.Add("ShowCompletedRequests", showCompletedRequests); } else { requests = requests.Where(w => (w.StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant())).ToList(); } int totalPages = (requests?.Count > 0) ? (int)Math.Ceiling((double)requests.Count / 5) : 0; var currentPageItems = this.GetPage(requests, 0, 5); Hashtable pagewiseRequests = new Hashtable(); for (int i = 0; i < totalPages; i++) { pagewiseRequests.Add(i.ToString(), JsonConvert.SerializeObject(this.GetPage(requests, i, 5)).ToString()); } context.PrivateConversationData.SetValue("PagewiseRequests", pagewiseRequests); context.PrivateConversationData.SetValue("FiltersHashTable", filtersHashTable); ViewTorListObj obj = new ViewTorListObj { Employees = employeesHashTable, EmployeesRoles = employeesRoleHashTable, Filters = filtersHashTable, TotalPages = totalPages, CurrentPageCount = 1, }; // string actionSet = "FR"; string actionSet = "F"; if (obj.CurrentPageCount < obj.TotalPages) { // actionSet = "FRN"; actionSet = "FN"; } obj.ConversationId = context.Activity.Conversation.Id; obj.ActivityId = context.Activity.ReplyToId; var comments = context.PrivateConversationData.GetValue <List <Models.ResponseEntities.CommentList.Comment> >("Comments"); if (requests.Count > 0) { card = this.supervisorTimeOffcard.GetCard(JsonConvert.DeserializeObject <List <TimeOffResponse.GlobalTimeOffRequestItem> >(Convert.ToString(pagewiseRequests[Convert.ToString(obj.CurrentPageCount - 1)])), obj, actionSet, comments); } else { card = this.supervisorTimeOffcard.GetCard(new List <TimeOffResponse.GlobalTimeOffRequestItem>(), obj, actionSet, comments); } var conversationId = context.Activity.Conversation.Id; var activityId = context.Activity.ReplyToId; context.PrivateConversationData.SetValue("conversationId", conversationId); context.PrivateConversationData.SetValue("activityId", activityId); 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; } }
/// <summary> /// Get card for next, previous and filter action. /// </summary> /// <param name="requests">List of requests.</param> /// <param name="obj">Object containing employees, filters details.</param> /// <param name="actionSet">Actionset identifier string.</param> /// <param name="comments">List of comments (from API).</param> /// <returns>Adaptive Card.</returns> public AdaptiveCard GetCard(List <GlobalTimeOffRequestItem> requests, ViewTorListObj obj, string actionSet, List <Comments> comments) { string fullPath = HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SupervisorViewTimeOffRequests/Latest/TimeOffRequests.json"); var mainCard = File.ReadAllText(fullPath); mainCard = mainCard.Replace("{txt_CardTitle}", KronosResourceText.ManagerViewTOR_Title); if (requests.Count > 0) { mainCard = mainCard.Replace("{txt_CardInfo}", KronosResourceText.ManagerViewTOR_InfoList).Replace("{ShowRequestList}", "true").Replace("{NoTimeOffRequests}", "false").Replace("{txt_NoTimeOffRequests}", null); var requestItem = File.ReadAllText(HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SupervisorViewTimeOffRequests/Latest/RequestItem.json")); var requestItemNoAction = File.ReadAllText(HttpContext.Current.Server.MapPath("/Cards/AdaptiveCards/SupervisorViewTimeOffRequests/Latest/RequestItemNoAction.json")); StringBuilder requestsSB = new StringBuilder(); for (int i = 0; i < requests.Count; i++) { string item = string.Empty; if (requests[i].StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant()) { item = requestItem; } else { item = requestItemNoAction; } var statusImg = requests[i].StatusName.ToLowerInvariant() == Constants.Approved.ToLowerInvariant() ? Constants.ApprovedImg : requests[i].StatusName.ToLowerInvariant() == Constants.Refused.ToLowerInvariant() ? Constants.RefusedImg : requests[i].StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant() ? Constants.PendingImg : string.Empty; var employeeName = Convert.ToString(obj.Employees[requests[i].Employee.PersonIdentity.PersonNumber]); var employeeRole = Convert.ToString(obj.EmployeesRoles[requests[i].Employee.PersonIdentity.PersonNumber]); string dateRange = string.Empty; DateTime.TryParse(requests[i].TimeOffPeriods.TimeOffPeriod.StartDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime sdt); DateTime.TryParse(requests[i].TimeOffPeriods.TimeOffPeriod.EndDate, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime edt); DateTime.TryParse(requests[i].CreationDateTime, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime creationDate); edt = edt.AddHours(23); edt = edt.AddMinutes(59); var days = (int)Math.Round(edt.Subtract(sdt).TotalDays, MidpointRounding.AwayFromZero); var timeperiod = requests[i].TimeOffPeriods.TimeOffPeriod.Duration == Constants.full_day ? Constants.FullDay : requests[i].TimeOffPeriods.TimeOffPeriod.Duration == Constants.half_day ? Constants.HalfDay : requests[i].TimeOffPeriods.TimeOffPeriod.Duration == Constants.first_half_day ? Constants.FirstHalfDay : Constants.Hours; var hours = string.Empty; var comment = requests[i].Comments?.Comment?.FirstOrDefault()?.Notes?.Note?.Text; if (requests[i].TimeOffPeriods.TimeOffPeriod.Duration.ToLowerInvariant() == Constants.Hours.ToLowerInvariant()) { var start = "08-15-2019 " + requests[i].TimeOffPeriods.TimeOffPeriod.StartTime.Substring(0, 4) + " " + requests[i].TimeOffPeriods.TimeOffPeriod.StartTime.Substring(4, 2); DateTime.TryParse(start, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime startDate); var lenHr = Convert.ToDouble(requests[i].TimeOffPeriods.TimeOffPeriod.Length.Split(':')[0]); var lenMin = Convert.ToDouble(requests[i].TimeOffPeriods.TimeOffPeriod.Length.Split(':')[1]); var endDate = startDate.AddHours(lenHr).AddMinutes(lenMin); hours = $"({startDate.ToString("h:mm tt", CultureInfo.InvariantCulture)} - {endDate.ToString("h:mm tt", CultureInfo.InvariantCulture)})"; } if (requests[i].TimeOffPeriods.TimeOffPeriod.StartDate.Equals(requests[i].TimeOffPeriods.TimeOffPeriod.EndDate)) { dateRange = sdt.ToString("MMM d, yyyy", CultureInfo.InvariantCulture); } else { dateRange = $"{sdt.ToString("MMM d, yyyy", CultureInfo.InvariantCulture)} - {edt.ToString("MMM d, yyyy", CultureInfo.InvariantCulture)}"; } // replace values of request details item = item.Replace("{StatusImg}", statusImg).Replace("{Name}", employeeName).Replace("{Role}", employeeRole).Replace("{PayCode}", requests[i].TimeOffPeriods.TimeOffPeriod.PayCodeName); item = item.Replace("{DateRange}", dateRange).Replace("{TimePeriod}", timeperiod).Replace("{Note}", requests[i].Comments?.Comment?.FirstOrDefault()?.Notes?.Note?.Text); // If status is submitted, replace values for approve/refuse actions if (requests[i].StatusName.ToLowerInvariant() == Constants.Submitted.ToLowerInvariant()) { var queryDateSpan = sdt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) + "-" + edt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); item = item.Replace("{index}", i.ToString()).Replace("{RequestId}", requests[i].Id).Replace("{QueryDateSpan}", queryDateSpan).Replace("{PersonNumber}", requests[i].CreatedByUser.PersonIdentity.PersonNumber); item = item.Replace("{EmpName}", employeeName).Replace("{conversationId}", obj.ConversationId).Replace("{activityId}", obj.ActivityId); } if (i == 0) { item = item.Replace("{Seperator}", "false"); requestsSB.Append(item); } else { item = item.Replace("{Seperator}", "true"); requestsSB.Append(", " + item); } } mainCard = mainCard.Replace("{RequestList}", requestsSB.ToString()); } else { var daterange = (obj.Filters.ContainsKey("DateRange") && !string.IsNullOrEmpty(Convert.ToString(obj.Filters["DateRange"]))) ? KronosResourceText.DateRange.ToLower() : KronosResourceText.TodayTxt.ToLower(); mainCard = mainCard.Replace("{txt_CardInfo}", null).Replace("{ShowRequestList}", "false").Replace("{RequestList}", null).Replace("{NoTimeOffRequests}", "true"); mainCard = mainCard.Replace("{txt_NoTimeOffRequests}", KronosResourceText.NoTimeOffRequests.Replace("{date}", daterange)); } // for action set fullPath = HttpContext.Current.Server.MapPath($"/Cards/AdaptiveCards/SupervisorViewTimeOffRequests/Latest/Actions_{actionSet}.json"); var action = File.ReadAllText(fullPath); action = action.Replace("{txt_EmployeeName}", KronosResourceText.EnterEmployeeName).Replace("{txt_EnterEmployeeName}", KronosResourceText.EnterEmpName); action = action.Replace("{txt_StartDate}", KronosResourceText.EnterStartDate).Replace("{txt_EndDate}", KronosResourceText.EnterEndDate); action = action.Replace("{txt_ShowCompletedRequests}", KronosResourceText.ShowCompletedRequests).Replace("{txt_Apply}", KronosResourceText.Apply); if (obj.Filters.Count > 0) { action = action.Replace("{EmpName}", obj.Filters.ContainsKey("EmpName") ? Convert.ToString(obj.Filters["EmpName"]) : string.Empty); action = action.Replace("{StartDate}", obj.Filters.ContainsKey("DateRange") ? Convert.ToString(obj.Filters["DateRange"]).Split(';')[0] : string.Empty); action = action.Replace("{EndDate}", obj.Filters.ContainsKey("DateRange") ? Convert.ToString(obj.Filters["DateRange"]).Split(';')[1] : string.Empty); action = action.Replace("{ShowCompletedRequests}", obj.Filters.ContainsKey("ShowCompletedRequests") ? Convert.ToString(obj.Filters["ShowCompletedRequests"]) : "false"); } else { action = action.Replace("{EmpName}", string.Empty).Replace("{txt_StartDate}", string.Empty).Replace("{txt_ShowCompletedRequests}", "false"); } action = action.Replace("{txt_Filter}", KronosResourceText.Filter); action = action.Replace("{txt_Apply}", KronosResourceText.Apply).Replace("{FilterApplyCommand}", Constants.TORListApplyFilter); action = action.Replace("{txt_Next}", KronosResourceText.CapsNext).Replace("{NextCommand}", Constants.TORListNext); action = action.Replace("{txt_Previous}", KronosResourceText.Previous).Replace("{PreviousCommand}", Constants.TORListPrevious); mainCard = mainCard.Replace("{Actions}", action).Replace("{CurrentPage}", obj.CurrentPageCount.ToString()); var serialized = JsonConvert.SerializeObject(comments, Formatting.None, new JsonSerializerSettings() { Formatting = Formatting.None, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, StringEscapeHandling = StringEscapeHandling.EscapeHtml }); mainCard = mainCard.Replace("{Comments}", serialized); var card = AdaptiveCard.FromJson(mainCard).Card; return(card); }