public async Task <List <FeedActivity> > GetFeedActivities(string upn, string tenantGroupName, string tenant, string startDate, string endDate, string outcome = null)
        {
            _logger.LogInformation($"Make api call to get feed activities of user {upn} within tenant {tenant} within tenant group {tenantGroupName}");
            string token = Request.Headers["Authorization"];

            return(await _diagnozeService.GetFeedActivities(token, upn, tenantGroupName, tenant, startDate, endDate, outcome).ConfigureAwait(false));
        }
        public async Task <IActionResult> Index(DiagonizePageViewModel data)
        {
            var viewData = new DiagonizePageViewModel();

            if (ModelState.IsValid)
            {
                tenantGroupName = HttpContext.Session.Get <string>("SelectedTenantGroupName");
                tenant          = HttpContext.Session.Get <string>("SelectedTenantName");
                if (string.IsNullOrEmpty(tenantGroupName) || string.IsNullOrEmpty(tenant))
                {
                    return(RedirectToAction("Error", "Home", new ErrorDetails()
                    {
                        StatusCode = (int)HttpStatusCode.Forbidden, Message = "Invalid tenant group name or tenant name."
                    }));
                }
                else
                {
                    var refreshtoken = await HttpContext.GetTokenAsync("refresh_token").ConfigureAwait(false);

                    accessToken = _commonService.GetAccessTokenWVD(refreshtoken); //await HttpContext.GetTokenAsync("access_token");
                    string startDate, endDate = "";
                    if (data.DiagonizeQuery.StartDate == null)
                    {
                        startDate = $"{DateTime.Now.ToUniversalTime().AddDays(-7).ToString("yyyy-MM-dd")}T00:00:00Z";
                        endDate   = $"{DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd")}T00:00:00Z";
                    }
                    else
                    {
                        startDate = data.DiagonizeQuery.StartDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); //+"T00:00:00Z";
                        endDate   = data.DiagonizeQuery.EndDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");   //+"T00: 00:00Z";
                    }



                    string activityoutcome = data.DiagonizeQuery.ActivityOutcome.ToString();
                    if (data.DiagonizeQuery.ActivityType == ActivityType.Management)
                    {
                        _logger.LogInformation($"Service call to get management activity details for selected tenant group {tenantGroupName} and tenant {tenant}");
                        //call from service layer
                        viewData.ManagementActivity = await _diagnozeService.GetManagementActivities(accessToken, data.DiagonizeQuery.UPN, tenantGroupName, tenant, startDate, endDate, activityoutcome).ConfigureAwait(false);

                        if (viewData.ManagementActivity?.Count > 0 && viewData.ManagementActivity[0].ErrorDetails != null)
                        {
                            _logger.LogError($"Error Occured : {viewData.ManagementActivity[0].ErrorDetails.Message}");
                            return(RedirectToAction("Error", "Home", new ErrorDetails()
                            {
                                StatusCode = (int)viewData.ManagementActivity[0].ErrorDetails.StatusCode, Message = "Access Denied!You are not authorized.Please contact system administrator"
                            }));
                        }
                        viewData.ActivityType = viewData.ManagementActivity?.Count() > 0 ? ActivityType.Management : ActivityType.None;
                    }
                    else if (data.DiagonizeQuery.ActivityType == ActivityType.Connection)
                    {
                        _logger.LogInformation($"Service Call  to get connection activity details for selected tenant group {tenantGroupName} and tenant {tenant}");

                        //call from service layer
                        viewData.ConnectionActivity = await _diagnozeService.GetConnectionActivities(accessToken, data.DiagonizeQuery.UPN, tenantGroupName, tenant, startDate, endDate, activityoutcome).ConfigureAwait(false);

                        if (viewData.ConnectionActivity?.Count > 0 && viewData.ConnectionActivity[0].ErrorDetails != null)
                        {
                            _logger.LogError($"Error Occured : {viewData.ConnectionActivity[0].ErrorDetails.Message}");
                            return(RedirectToAction("Error", "Home", new ErrorDetails()
                            {
                                StatusCode = (int)viewData.ConnectionActivity[0].ErrorDetails.StatusCode, Message = "Access Denied!You are not authorized.Please contact system administrator"
                            }));
                        }

                        viewData.ActivityType = viewData.ConnectionActivity?.Count() > 0 ? ActivityType.Connection : ActivityType.None;
                    }
                    else if (data.DiagonizeQuery.ActivityType == ActivityType.Feed)
                    {
                        _logger.LogInformation($"Service call to get feed activity details for selected tenant group {tenantGroupName} and tenant {tenant}");

                        viewData.FeedActivity = await _diagnozeService.GetFeedActivities(accessToken, data.DiagonizeQuery.UPN, tenantGroupName, tenant, startDate, endDate, activityoutcome).ConfigureAwait(false);

                        if (viewData.FeedActivity?.Count > 0 && viewData.FeedActivity[0].ErrorDetails != null)
                        {
                            _logger.LogError($"Error Occured : {viewData.FeedActivity[0].ErrorDetails.Message}");
                            return(RedirectToAction("Error", "Home", new ErrorDetails()
                            {
                                StatusCode = (int)viewData.FeedActivity[0].ErrorDetails.StatusCode, Message = viewData.FeedActivity[0].ErrorDetails.Message
                            }));
                        }
                        viewData.ActivityType = viewData.FeedActivity?.Count() > 0 ? ActivityType.Feed : ActivityType.None;
                    }
                }
            }
            HttpContext.Session.Set <DiagonizeQuery>("SearchQuery", data.DiagonizeQuery);
            viewData.DiagonizeQuery = data.DiagonizeQuery;
            return(View("SearchResults", viewData));
        }