Esempio n. 1
0
        /// <summary>
        /// Get the Checkr packages and update the list on the server.
        /// </summary>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns>True/False value of whether the request was successfully sent or not.</returns>
        public static bool UpdatePackages(List <string> errorMessages)
        {
            GetPackagesResponse getPackagesResponse;

            if (!CheckrApiUtility.GetPackages(out getPackagesResponse, errorMessages))
            {
                return(false);
            }

            List <string> packages;

            using (var rockContext = new RockContext())
            {
                var definedType = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.BACKGROUND_CHECK_TYPES.AsGuid());

                DefinedValueService definedValueService = new DefinedValueService(rockContext);
                packages = definedValueService
                           .GetByDefinedTypeGuid(Rock.SystemGuid.DefinedType.BACKGROUND_CHECK_TYPES.AsGuid())
                           .Where(v => v.ForeignId == 2)
                           .ToList()
                           .Select(v => { v.LoadAttributes(rockContext); return(v.GetAttributeValue("PMMPackageName").ToString()); }) // v => v.Value.Substring( CheckrConstants.TYPENAME_PREFIX.Length ) )
                           .ToList();

                foreach (var packageRestResponse in getPackagesResponse.Data)
                {
                    string packageName = packageRestResponse.Slug;
                    if (!packages.Contains(packageName))
                    {
                        DefinedValue definedValue = null;

                        definedValue = new DefinedValue();
                        definedValue.DefinedTypeId = definedType.Id;
                        definedValue.ForeignId     = 2;
                        definedValueService.Add(definedValue);

                        definedValue.Value = CheckrConstants.CHECKR_TYPENAME_PREFIX + packageName.Replace('_', ' ').FixCase();

                        definedValue.Description = packageRestResponse.Name == "Educatio Report" ? "Education Report" : packageRestResponse.Name;
                        rockContext.SaveChanges();

                        definedValue.LoadAttributes(rockContext);

                        definedValue.SetAttributeValue("PMMPackageName", packageName);
                        definedValue.SetAttributeValue("DefaultCounty", string.Empty);
                        definedValue.SetAttributeValue("SendHomeCounty", "False");
                        definedValue.SetAttributeValue("DefaultState", string.Empty);
                        definedValue.SetAttributeValue("SendHomeState", "False");
                        definedValue.SetAttributeValue("MVRJurisdiction", string.Empty);
                        definedValue.SetAttributeValue("SendHomeStateMVR", "False");
                        definedValue.SaveAttributeValues(rockContext);
                    }
                }
            }

            DefinedValueCache.Clear();
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Saves the tag, caller is responsible for validation.
 /// </summary>
 private void SaveTag()
 {
     if (hfTagId.Value == string.Empty)
     {
         SaveNewTag();
     }
     else
     {
         UpdateExistingTag(hfTagId.ValueAsInt());
         DefinedValueCache.Clear();
     }
 }