public Level CreateLevel(Level level) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "CreateLevel"); CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); LevelEntity entity = manager.CreateLevel(level.Name, level.Description, level.ShortDescription, level.ColorValue, level.EscalationTimeout, level.DueTimeout, level.DirectContactRequired); if (level.Transports != null) { foreach(Transport t in level.Transports){ bool mandatory = false; foreach(Transport mT in level.MandatoryTransports) { if(mT.Name == t.Name) { mandatory = true; } } manager.CreateTransportLevelEntity(entity.Uuid, t.Name, mandatory); } UserEntity[] ues = manager.GetAllUsers(); entity.TransportLevels.Load(); foreach (UserEntity ue in ues) { ue.UserTransports.Load(); foreach (UserTransportEntity te in ue.UserTransports) { foreach (TransportLevelEntity t in entity.TransportLevels) { if (te.Transport != null) { if (t.Transport.Name == te.Transport.Name) { te.Levels.Add(entity); } } } } } manager.SaveChanges(); } return new Level(entity); }