Exemplo n.º 1
0
        public static void SetEventType(ObjectContext context, EventV2 source, Event theEvent)
        {
            try
            {
                //ignore null values
                if (source.EventTypes == null)
                    return;

                var types = context.CreateObjectSet<EventType>();
                var eventTypes = new List<EventType>();

                foreach (var typeName in source.EventTypes.Select(e => e.Name))
                {
                    var eventType = types.Where(i => i.Name == typeName).FirstOrDefault();

                    //Ensure eventType exists
                    if (eventType == null)
                    {
                        //type doesn't exist, create a new type
                        eventType = new EventType()
                        {
                            Name = typeName,
                            IsEnabled = true
                        };
                        types.AddObject(eventType);
                    }
                    eventTypes.Add(eventType);
                }
                UpdateEventType(theEvent, eventTypes, context);
            }
            catch (Exception ex)
            {
                throw new BusinessException("Error processing the event type for event '" + theEvent.Title + "' - " + ex.Message, ex);
            }
        }
        public void FilterByType()
        {
            //setup
            var type1 = new EventType { Id = 1 };
            var type2 = new EventType { Id = 2 };
            var event1 = new Event { Id = 1 };
            var event2 = new Event { Id = 2 };
            event1.EventTypeAssociations.Add(new EventTypeAssociation { EventType = type1, EventTypeId = type1.Id });
            _objectSet.Add(event1);
            event2.EventTypeAssociations.Add(new EventTypeAssociation { EventType = type2, EventTypeId = type2.Id });
            _objectSet.Add(event2);
            _objectSet.Add(new Event { Id = 3 });

            //act
            var filtered = _objectSet.AsQueryable().FilterByType(1);

            //assert
            AssertIncluded(filtered, 1);
            AssertExcluded(filtered, 2, 3);
        }