コード例 #1
0
        public void UpdateInitiativeMetaTags(InitiativeContext context,
                                             string[] selectedMetaTags, Initiative initiativeToUpdate)
        {
            if (selectedMetaTags == null)
            {
                initiativeToUpdate.InitiativeMetaTag = new List <InitiativeMetaTag>();
                return;
            }

            var selectedMetaTagsHS = new HashSet <string>(selectedMetaTags);
            var initiativeMetaTags = new HashSet <int>
                                         (initiativeToUpdate.InitiativeMetaTag.Select(c => c.MetaTag.MetaTagId));

            foreach (var metaTag in context.MetaTag)
            {
                // This is the add a meta tag condition from UI
                if (selectedMetaTagsHS.Contains(metaTag.MetaTagId.ToString()))
                {
                    if (!initiativeMetaTags.Contains(metaTag.MetaTagId))
                    {
                        initiativeToUpdate.InitiativeMetaTag.Add
                        (
                            new InitiativeMetaTag
                        {
                            InitiativeId = initiativeToUpdate.InitiativeId,
                            MetaTagId    = metaTag.MetaTagId
                        });
                    }
                }
                else
                {
                    //This is the delete a meta tag conditon
                    if (initiativeMetaTags.Contains(metaTag.MetaTagId))
                    {
                        InitiativeMetaTag metaTagToRemove
                            = initiativeToUpdate
                              .InitiativeMetaTag
                              .SingleOrDefault(i => i.MetaTagId == metaTag.MetaTagId);
                        context.Remove(metaTagToRemove);
                    }
                }
            }
        }
コード例 #2
0
        public void UpdateInitiativeBusiness(InitiativeContext context,
                                             string[] selectedBusiness, Initiative initiativeToUpdate)
        {
            if (selectedBusiness == null)
            {
                initiativeToUpdate.InitiativeBusiness = new List <InitiativeBusiness>();
                return;
            }

            var selectedBusinessHS = new HashSet <string>(selectedBusiness);
            var initiativeBusiness = new HashSet <int>
                                         (initiativeToUpdate.InitiativeBusiness.Select(c => c.Business.BusinessId));

            foreach (var business in context.Business)
            {
                // This is the add a meta tag condition from UI
                if (selectedBusinessHS.Contains(business.BusinessId.ToString()))
                {
                    if (!initiativeBusiness.Contains(business.BusinessId))
                    {
                        initiativeToUpdate.InitiativeBusiness.Add
                        (
                            new InitiativeBusiness
                        {
                            InitiativeId = initiativeToUpdate.InitiativeId,
                            BusinessId   = business.BusinessId
                        });
                    }
                }
                else
                {
                    //This is the delete a meta tag conditon
                    if (initiativeBusiness.Contains(business.BusinessId))
                    {
                        InitiativeBusiness businessToRemove
                            = initiativeToUpdate
                              .InitiativeBusiness
                              .SingleOrDefault(i => i.BusinessId == business.BusinessId);
                        context.Remove(businessToRemove);
                    }
                }
            }
        }
コード例 #3
0
        public void UpdateInitiativeFacility(InitiativeContext context,
                                             string[] selectedFacility, Initiative initiativeToUpdate)
        {
            if (selectedFacility == null)
            {
                initiativeToUpdate.InitiativeFacility = new List <InitiativeFacility>();
                return;
            }

            var selectedFacilityHS  = new HashSet <string>(selectedFacility);
            var initiativeFacilitys = new HashSet <int>
                                          (initiativeToUpdate.InitiativeFacility.Select(c => c.Facility.FacilityId));

            foreach (var facility in context.Facility)
            {
                // This is the add a meta tag condition from UI
                if (selectedFacilityHS.Contains(facility.FacilityId.ToString()))
                {
                    if (!initiativeFacilitys.Contains(facility.FacilityId))
                    {
                        initiativeToUpdate.InitiativeFacility.Add
                        (
                            new InitiativeFacility
                        {
                            InitiativeId = initiativeToUpdate.InitiativeId,
                            FacilityId   = facility.FacilityId
                        });
                    }
                }
                else
                {
                    //This is the delete a meta tag conditon
                    if (initiativeFacilitys.Contains(facility.FacilityId))
                    {
                        InitiativeFacility facilityToRemove
                            = initiativeToUpdate
                              .InitiativeFacility
                              .SingleOrDefault(i => i.FacilityId == facility.FacilityId);
                        context.Remove(facilityToRemove);
                    }
                }
            }
        }