public void SetAnySimulationUsers(int simulationId, List <SimulationUserModel> simulationUsers, BridgeCareContext db) { if (!db.Simulations.Any(s => s.SIMULATIONID == simulationId)) { throw new RowNotInTableException($"No scenario found with id {simulationId}."); } var simulation = db.Simulations.Include(s => s.USERS).Single(s => s.SIMULATIONID == simulationId); foreach (var user in simulation.USERS.ToArray()) { SimulationUserEntity.DeleteEntry(user, db); } simulation.USERS = simulationUsers.Select(user => new SimulationUserEntity(simulationId, user)).ToList(); db.SaveChanges(); }
public void SetPermittedSimulationUsers(int simulationId, List <SimulationUserModel> simulationUsers, BridgeCareContext db, string username) { if (!db.Simulations.Any(s => s.SIMULATIONID == simulationId)) { throw new RowNotInTableException($"No scenario found with id {simulationId}."); } if (!db.Simulations.Include(s => s.USERS).First(s => s.SIMULATIONID == simulationId).UserCanModify(username)) { throw new UnauthorizedAccessException($"User {username} cannot modify scenario {simulationId}."); } var simulation = db.Simulations.Include(s => s.USERS).Single(s => s.SIMULATIONID == simulationId); foreach (var user in simulation.USERS.ToArray()) { SimulationUserEntity.DeleteEntry(user, db); } simulation.USERS = simulationUsers.Select(user => new SimulationUserEntity(simulationId, user)).ToList(); db.SaveChanges(); }
public void UpdateSimulationUser(SimulationUserEntity entity) { entity.USERNAME = Username; entity.CAN_MODIFY = CanModify; }
public SimulationUserModel(SimulationUserEntity simulationUserEntity) { Id = simulationUserEntity.ID_.ToString(); Username = simulationUserEntity.USERNAME; CanModify = simulationUserEntity.CAN_MODIFY; }