Exemplo n.º 1
0
        /// <summary>
        /// Set quality session information for the current context.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="httpContext"></param>
        public static void SetSessionInformation(UserContext.UserContextInfo context)
        {
            if (context == null || context.ItemId == null)
            {
                ClearSessionInformation();
                return;
            }

            var db = new ProviderPortalEntities();

            switch (context.ContextName)
            {
            case UserContext.UserContextName.Provider:
            {
                // Update the score if it doesn't exist
                if (db.QualityScores.All(x => x.ProviderId != context.ItemId.Value))
                {
                    db.up_ProviderUpdateQualityScore(context.ItemId.Value, true);
                }
                var info = db.QualityScores
                           .Where(x => x.ProviderId == context.ItemId.Value)
                           .Select(x => new
                    {
                        Score = x.AutoAggregateQualityRating,
                        UpdatedDateTimeUtc = x.ModifiedDateTimeUtc,
                        SfaFunded          = x.Provider.SFAFunded,
                        DfeFunded          = x.Provider.DFE1619Funded,
                        ProviderType       = x.Provider.ProviderType != null ? x.Provider.ProviderType.ProviderTypeName : String.Empty,
                        LastCalculated     = x.CalculatedDateTimeUtc
                    }).FirstOrDefault();
                DateTime?lastAllDataUpToDateTimeUtc = null;
                Provider provider = db.Providers.Find(context.ItemId.Value);
                if (provider != null)
                {
                    lastAllDataUpToDateTimeUtc = provider.LastAllDataUpToDateTimeUtc;
                }
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderLastActivity] =
                    info == null ? lastAllDataUpToDateTimeUtc : lastAllDataUpToDateTimeUtc.HasValue ? ProvisionDataCurrent.GetLatestDate(lastAllDataUpToDateTimeUtc.Value, info.UpdatedDateTimeUtc.HasValue ? info.UpdatedDateTimeUtc.Value : DateTime.MinValue) : info.UpdatedDateTimeUtc;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderLastProvisionUpdate] =
                    info == null ? null : info.UpdatedDateTimeUtc;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderQualityScore] =
                    info == null ? 0.0m : info.Score.Value / 100m;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderIsSfaFunded] =
                    info != null && info.SfaFunded;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderIsDfe1619Funded] =
                    info != null && info.DfeFunded;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderType]             = info != null ? info.ProviderType : String.Empty;
                HttpContext.Current.Session[Constants.SessionFieldNames.ProviderQALastCalculated] = info == null ? (DateTime?)null : info.LastCalculated;
                break;
            }

            case UserContext.UserContextName.Organisation:
            {
                // Update the score if it doesn't exist
                if (db.OrganisationQualityScores.All(x => x.OrganisationId != context.ItemId.Value))
                {
                    db.up_OrganisationUpdateQualityScore(context.ItemId.Value);
                }
                var info = db.OrganisationQualityScores
                           .Where(x => x.OrganisationId == context.ItemId.Value)
                           .Select(x => new
                    {
                        EarliestModifiedDateTimeUtc = x.EarliestModifiedDateTimeUtc,
                        SfaFunded =
                            x.Organisation.OrganisationProviders.Any(
                                y => y.IsAccepted && !y.IsRejected && y.Provider.SFAFunded),
                        DfeFunded =
                            x.Organisation.OrganisationProviders.Any(
                                y => y.IsAccepted && !y.IsRejected && y.Provider.DFE1619Funded)
                    }).FirstOrDefault();
                HttpContext.Current.Session[Constants.SessionFieldNames.OrganisationLastActivity] =
                    info == null ? null : info.EarliestModifiedDateTimeUtc;
                HttpContext.Current.Session[Constants.SessionFieldNames.OrganisationIsSfaFunded] =
                    info != null && info.SfaFunded;
                HttpContext.Current.Session[Constants.SessionFieldNames.OrganisationIsDfe1619Funded] =
                    info != null && info.DfeFunded;
                break;
            }

            default:
            {
                ClearSessionInformation();
                break;
            }
            }
        }