public ServiceUpdatedEventArgs(ServiceType serviceType, Service service) { ServiceType = serviceType; Service = service; }
public void UpdateServiceAndType(ServiceType serviceType, Service service) { if (serviceType == null && service == null) return; using (IDbConnection connection = CreateConnection()) { using (IDbTransaction transaction = connection.BeginTransaction()) { IDbCommand command = connection.CreateCommand(); command.Transaction = transaction; if (serviceType != null) { #region SQL statement command.CommandText = @" IF NOT EXISTS (SELECT TOP(1) [service_type_id] FROM [dbo].[service_type] WHERE [service_type_id] = @service_type_id) INSERT INTO [dbo].[service_type] ([service_type_id] ,[name]) VALUES (@service_type_id ,@service_type_name) ELSE UPDATE [dbo].[service_type] SET [name] = @service_type_name WHERE [service_type_id] = @service_type_id "; #endregion addParameter(command, "@service_type_id", serviceType.ServiceTypeId); addParameter(command, "@service_type_name", serviceType.Name); command.ExecuteNonQuery(); } if (service != null) { #region SQL statement command.CommandText = @" IF NOT EXISTS (SELECT TOP(1) [service_id] FROM [dbo].[service] WHERE [service_id] = @service_id) INSERT INTO [dbo].[service] ([service_id] ,[service_type_id] ,[name]) VALUES (@service_id ,@service_type_id ,@service_name) ELSE UPDATE [dbo].[service] SET [name] = @service_name ,[service_type_id] = @service_type_id WHERE [service_id] = @service_id "; #endregion command.Parameters.Clear(); addParameter(command, "@service_type_id", service.ServiceTypeId); addParameter(command, "@service_id", service.ServiceId); addParameter(command, "@service_name", service.Name); command.ExecuteNonQuery(); } transaction.Commit(); } } }
private List<ServiceType> GetServiceTypes(TreeListNodes nodes) { List<ServiceType> result = new List<ServiceType>(); foreach (TreeListNode listNode in nodes) { if (listNode.Nodes.Count > 0) result.AddRange(GetServiceTypes(listNode.Nodes)); ServiceTree service = GetServiceByNode(listNode); if (service == null || service.ParentId != Guid.Empty) continue; ServiceType s = new ServiceType(); s.ServiceTypeId = service.ServiceId; s.Name = service.Name; result.Add(s); } return result; }