private void attach_ActionPropertyTypes(ActionPropertyType entity)
 {
     this.SendPropertyChanging("ActionPropertyTypes");
     entity.RbUnit = this;
 }
 private void detach_ActionPropertyTypes(ActionPropertyType entity)
 {
     this.SendPropertyChanging("ActionPropertyTypes");
     entity.RbUserProfile = null;
 }
        private static void verifyStationarBedProfile(IBackgroundContext context, 
            List<Event> allEvents, 
            VistaMedDataContext dataContext, ActionType moveActType,
            ActionPropertyType bedPropType, string eventKindName)
        {
            var eventTypes = from c in dataContext.VistaMed.EventTypes
                             where c.RbMedicalAidType != null
                                   && c.RbMedicalAidType.Name == eventKindName
                             select c;

            var stationarEvents = from e in allEvents
                                  where eventTypes.Contains(e.EventType)
                                  select e;

            // мероприятия "Движение"
            var moveActions = from e in stationarEvents
                              from c in e.Actions
                              where !c.Deleted && c.ActionType == moveActType
                              select new {Event = e, Action = c};

            // выборка свойств "койка"
            var actProp = from c in moveActions
                          from p in c.Action.ActionProperties
                          where p.ActionPropertyType == bedPropType && !p.Deleted
                          select new { Event = c.Event, Action = c.Action, BedProp = p };

            // выборка значений "койка"
            var actBed = (from c in actProp
                          join bedTypedProp in dataContext.VistaMed.ActionPropertyHospitalBeds on c.BedProp.Id equals bedTypedProp.Id
                          select new { c.Event, c.Action, Bed = bedTypedProp.OrgStructureHospitalBed }).ToList();

            Func<RbHospitalBedProfile, bool> comparator;
            if(eventKindName.Contains("Дневной"))
                comparator = x => x.Name.Contains(" ДС");
            else
                comparator = x => !x.Name.Contains(" ДС");

            var wrongBeds = from c in actBed
                           where c.Bed.RbHospitalBedProfile != null && !comparator(c.Bed.RbHospitalBedProfile)
                           select c;

            var errors = new List<string>();

            foreach (var wrongBed in wrongBeds)
            {
                errors.Add(string.Format(@"{0}. Неверный тип койки {1}", wrongBed.Event,
                    wrongBed.Bed.RbHospitalBedProfile.Name));
            }

            if (errors.Count > 0)
            {
                context.ReportError(@"""{0}""", eventKindName);
                errors.ForEach(x => context.ReportProgress(@"    -> {0}", x));
            }
        }