public void InsertOrUpdateEnvironment(EnvironmentDto environment) { DeleteEnvironment(environment.EnvironmentName); _environments.Add(environment); }
public void InsertOrUpdateEnvironment(EnvironmentDto environment) { _log.Info(m => m("Updating '{0}' environment", environment.EnvironmentName)); using (var context = _contextFactory.Create(_repositoryName)) { using (var command = _commandFactory.CreateStoredProcedure("sp_InsertUpdateEnvironment")) { command.AddParameter("environmentName", environment.EnvironmentName); command.AddParameter("version", environment.Version); context.ExecuteNonQuery(command); } using (var command = _commandFactory.CreateStoredProcedure("sp_DeleteEnvironmentMachines")) { command.AddParameter("environmentName", environment.EnvironmentName); context.ExecuteNonQuery(command); } if (environment.Machines != null && environment.Machines.Count > 0) { using (var command = _commandFactory.CreateStoredProcedure("sp_InsertEnvironmentMachine")) { command.AddParameter("environmentName", environment.EnvironmentName); command.AddParameter("environmentVersion", environment.Version); var machineName = command.AddParameter("machineName", SqlDbType.NVarChar, ParameterDirection.Input); foreach (var machine in environment.Machines) { machineName.Value = machine.Name; context.ExecuteNonQuery(command); } } } using (var command = _commandFactory.CreateStoredProcedure("sp_DeleteEnvironmentSecurity")) { command.AddParameter("environmentName", environment.EnvironmentName); context.ExecuteNonQuery(command); } if (environment.SecurityRules != null && environment.SecurityRules.Count > 0) { using (var command = _commandFactory.CreateStoredProcedure("sp_InsertEnvironmentSecurity")) { command.AddParameter("environmentName", environment.EnvironmentName); command.AddParameter("environmentVersion", environment.Version); var startIp = command.AddParameter("startIp", SqlDbType.NVarChar, ParameterDirection.Input); var endIp = command.AddParameter("endIp", SqlDbType.NVarChar, ParameterDirection.Input); foreach (var securityRule in environment.SecurityRules) { startIp.Value = securityRule.AllowedIpStart; endIp.Value = securityRule.AllowedIpEnd; context.ExecuteNonQuery(command); } } } } }
public void InsertOrUpdateEnvironment(EnvironmentDto environment) { CheckForUpdate(); _environments.RemoveAll(e => string.Equals(e.EnvironmentName, environment.EnvironmentName, StringComparison.InvariantCultureIgnoreCase)); _environments.Add(environment); SaveChanges(); }