public Machine EditMachine(MachineModel editMachine) { var Machine = MachineUtil.CastToDbo(editMachine); var connectionStrings = Machine.ConnectionStrings; Machine.ConnectionStrings = null; var updatedMachine = _MachineRepository.Edit(Machine); if (connectionStrings != null) { foreach (var conString in connectionStrings) { if (conString.ConnectionStringId != 0) { _connectionStringRepository.Edit(conString); } else { conString.MachineId = updatedMachine.MachineId; _connectionStringRepository.Create(conString); } } } //delete all deleted connectionStrings var envsToSave = connectionStrings.Select(_ => _.ConnectionStringId); var allEnvIds = _connectionStringRepository.GetAllConStrIdsForMachine(updatedMachine.MachineId); var idsToDelete = allEnvIds.Except(envsToSave).ToList(); foreach (var id in idsToDelete) { _connectionStringRepository.Delete(id); } return(_MachineRepository.GetByMachineId(updatedMachine.MachineId)); }
public ConnectionString EditConnectionString(ConnectionStringModel editConnectionString) { var ConnectionString = ConnectionStringUtil.CastToDbo(editConnectionString); return(_ConnectionStringRepository.Edit(ConnectionString)); }