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); }
public Level UpdateLevel(Level level) { _Trace.TraceEvent(TraceEventType.Verbose, -1, "UpdateLevel"); CriticalResultsEntityManager manager = new CriticalResultsEntityManager(); LevelEntity entity = manager.UpdateLevel(level.Uuid, level.Name, level.Description, level.ShortDescription, level.ColorValue, level.EscalationTimeout, level.DueTimeout, level.DirectContactRequired); if (level.Transports != null) { List<TransportLevelEntity> transportsToRemove = new List<TransportLevelEntity>(); transportsToRemove.AddRange(entity.TransportLevels); foreach(TransportLevelEntity tle in transportsToRemove) { if (!tle.TransportReference.IsLoaded) { tle.TransportReference.Load(); } manager.RemoveTransportFromLevel(level.Uuid, tle.Transport.Name); } foreach (Transport t in level.Transports) { bool mandatory = false; foreach (Transport mT in level.MandatoryTransports) { if (t.Name == mT.Name) { mandatory = true; } } manager.CreateTransportLevelEntity(level.Uuid, t.Name, mandatory); } } return new Level(entity); }