protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (_profileRepository == null) _profileRepository = new ProfileRepository();
            if (_coreDataRepository == null) _coreDataRepository = new CoreDataRepository();
            if (_lookUpsRepository == null) _lookUpsRepository = new LookUpsRepository();

            base.OnActionExecuting(filterContext);
        }
        private IList<GroupingMetadata> ReloadGridDomains(string selectedProfile, ProfileRepository profileRepository)
        {
            var model = new ProfileMembers
                {
                    UrlKey = selectedProfile,
                    Profile = CommonUtilities.GetProfile(selectedProfile, 1, -1, profileRepository)
                };

            return model.Profile.GroupingMetadatas;
        }
 public ProfilesAndIndicatorsController(ProfileRepository profileRepository, LookUpsRepository lookUpsRepository, CoreDataRepository coreDataRepository)
 {
     _profileRepository = profileRepository;
     _lookUpsRepository = lookUpsRepository;
     _coreDataRepository = coreDataRepository;
 }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            _profileRepository = new ProfileRepository();

            base.OnActionExecuting(filterContext);
        }
 public void Init()
 {
     _profileRepository = new ProfileRepository();
 }
 public void Init()
 {
     _coreDataRepository = new CoreDataRepository();
     _lookUpsRepository = new LookUpsRepository();
     _profileRepository = new ProfileRepository();
 }
 /// <summary>
 /// Required for when action methods called from other controllers
 /// </summary>
 private void EnsureProfileRepositoryDefined()
 {
     if (_profileRepository == null)
     {
         _profileRepository = new ProfileRepository();
     }
 }
 public ProfileBuilder(ProfileRepository profileRepository)
 {
     _profileRepository = profileRepository;
 }
 public void TestInitialize()
 {
     _profileRepository = new ProfileRepository();
     _profilesReader = ReaderFactory.GetProfilesReader();
 }
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     _profileRepository = new ProfileRepository();
     _lookUpsRepository = new LookUpsRepository();
 }
 public IndicatorOwnerChanger(ProfilesReader profilesReader, 
     ProfileRepository profileRepository)
 {
     _profilesReader = profilesReader;
     _profileRepository = profileRepository;
 }
 public static void RemoveEmptyOverrides(int indicatorId, int? profileId, IList<IndicatorMetadataTextProperty> properties, ProfileRepository profileRepository)
 {
     //Clean-up - Remove any overridden Indicator Metadata records where all text property fields are null
     if (!Reader.GetIndicatorTextValues(indicatorId, properties, profileId).ToList().Any(x => x.HasSpecificValue()))
     {
         profileRepository.DeleteOverriddenMetaDataTextValues(indicatorId, (int)profileId);
     }
 }
        public static void UpdateIndicatorTextValues(int indicatorId, int? groupId, string userMTVChanges,
            IList<IndicatorMetadataTextProperty> properties, DateTime timeOfChange, string userName, int? profileId, ProfileRepository profileRepository)
        {
            var items = new IndicatorMetadataTextParser().Parse(userMTVChanges);

            foreach (var item in items)
            {
                IndicatorMetadataTextProperty property = properties.First(x => x.PropertyId == item.PropertyId);

                // Get properties + existing values
                IndicatorText indicatorText = Reader.GetIndicatorTextValues(indicatorId,
                        new List<IndicatorMetadataTextProperty> { property },
                        profileId).First();

                // Figure out whether to update generic or specific
                int? profileIdForProperty = null;
                if ((item.IsOverridden || indicatorText.HasSpecificValue()) && groupId.HasValue)
                {
                    profileIdForProperty = profileId;
                }

                // Text that is being replaced
                string oldText;
                if (item.IsOverridden)
                {
                    // The user is overriding the generic value for the first time
                    oldText = null;
                }
                else if (indicatorText.HasSpecificValue())
                {
                    // The user is modifying an existing specific value
                    oldText = indicatorText.ValueSpecific;
                }
                else
                {
                    // User has changed the generic value
                    oldText = indicatorText.ValueGeneric;
                }

                // Save to change log 
                profileRepository.LogPropertyChange(property.PropertyId, oldText, indicatorId, profileIdForProperty, userName,
                                              timeOfChange);

                var indicatorAlreadyOverridden = profileRepository.DoesOverriddenIndicatorMetaDataRecordAlreadyExist(indicatorId, profileId);

                var text = item.Text;
                if (indicatorAlreadyOverridden && indicatorText.HasSpecificValue())
                {
                    if (text == indicatorText.ValueSpecific || text == indicatorText.ValueGeneric)
                    {
                        text = null;
                    }
                    profileRepository.UpdateProperty(property, text, indicatorId, profileIdForProperty);
                }
                else
                {
                    if (!indicatorAlreadyOverridden && item.IsOverridden)
                    {
                        profileRepository.CreateNewOverriddenIndicator(property, text, indicatorId, profileId);
                    }
                    else
                    {
                        if (text == indicatorText.ValueSpecific || text == indicatorText.ValueGeneric)
                        {
                            text = null;
                        }
                        profileRepository.UpdateProperty(property, text, indicatorId, profileIdForProperty);
                    }
                }
            }

            RemoveEmptyOverrides(indicatorId, groupId, properties, profileRepository);
        }
        public static void CreateNewIndicatorTextValues(string selectedDomain, string userMTVChanges,
            IList<IndicatorMetadataTextProperty> properties, int nextIndicatorId, string userName, ProfileRepository profileRepository)
        {
            var items = new IndicatorMetadataTextParser().Parse(userMTVChanges);

            var allPropertiesToAdd = new List<IndicatorMetadataTextProperty>();

            foreach (var item in items)
            {
                IndicatorMetadataTextProperty property = properties.First(x => x.PropertyId == item.PropertyId);
                property.Text = item.Text;
                allPropertiesToAdd.Add(property);

                // Save to change log 
                profileRepository.LogPropertyChange(property.PropertyId, null, nextIndicatorId, Convert.ToInt32(selectedDomain), userName, DateTime.Now);
            }

            profileRepository.CreateIndicator(allPropertiesToAdd, nextIndicatorId);
        }
 public static Profile GetProfile(string urlKey, int selectedDomainNumber, int areaType, ProfileRepository profileRepository)
 {
     return new ProfileBuilder(profileRepository).Build(urlKey, selectedDomainNumber, areaType);
 }
        public static IEnumerable<SelectListItem> GetOrderedListOfDomainsWithGroupId(ProfileMembers domains, SelectListItem defaultProfile, ProfileRepository profileRepository)
        {
            if (defaultProfile != null)
                domains.Profile = GetProfile(defaultProfile.Value, 0, -1, profileRepository);

            var listOfDomains = new SelectList(domains.Profile.GroupingMetadatas.OrderBy(g => g.Sequence), "GroupId", "GroupName");
            var selectedDomain = new SelectList(listOfDomains, "Value", "Key", listOfDomains.FirstOrDefault().Value).SelectedValue.ToString();
            return listOfDomains.Select(x => new SelectListItem { Selected = (x.Value == selectedDomain), Text = x.Text, Value = x.Value }); ;
        }