Example #1
0
 private static void FetchConnectionSetting(SqlConnection connection, EDCConnectionEditDto editDto)
 {
     editDto.Connection = ConnectionsSetupDal.FetchConnectionSetup(connection, editDto.ConnectionSetupId);
 }
Example #2
0
        public void InsertExternalConnectionEdit(EDCConnectionEditDto dto)
        {
            if (dto == null)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
INSERT INTO [dbo].[EDCConnections]
(
     [GuidId]
    ,[LastModifiedOn]
    ,[EDCId]
    ,[ConnectionSetupId]
    ,[FirstExpression]   
)
VALUES
(
     @guid
    ,GETDATE()
    ,@edcId  
    ,@connectionSetupId
    ,@firstExpression  
);

SELECT [Id]
FROM   [dbo].[EDCConnections]
WHERE  [Id] = SCOPE_IDENTITY()
";

            try
            {
                using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
                {
                    var cn = ctx.Connection;

                    using (var cmd = new SqlCommand(Sql, cn))
                    {
                        cmd.Parameters.AddWithValue("@guid", dto.Guid);
                        cmd.Parameters.AddWithValue("@edcId", dto.EDCId);
                        cmd.Parameters.AddWithValue("@connectionSetupId", dto.ConnectionSetupId);
                        cmd.Parameters.AddWithValue("@firstExpression", dto.FirstExpression);
                        dto.Id = (int)cmd.ExecuteScalar();
                    }
                }
            }

            catch (Exception ex)
            {
                throw new ArgumentException(ex.Data.ToString());
            }
        }
Example #3
0
        public void UpdateExternalConnectionEdit(EDCConnectionEditDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
UPDATE [dbo].[EDCConnections]
SET
     [GuidId] = @guid
    ,[LastModifiedOn] = GETDATE()
    ,[EDCId] = @eDCId 
    ,[ConnectionSetupId] = @connectionSetupId  
    ,[FirstExpression] = @firstExpression   
WHERE [Id] = @id;
";
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@id", dto.Id);

                    cmd.Parameters.AddWithValue("@guid", dto.Guid);
                    cmd.Parameters.AddWithValue("@eDCId", dto.EDCId);
                    cmd.Parameters.AddWithValue("@connectionSetupId", dto.ConnectionSetupId);
                    cmd.Parameters.AddWithValue("@firstExpression", dto.FirstExpression);

                    var rowsAffetcted = cmd.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                        throw new DBConcurrencyException(
                            "The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }
            }
        }
Example #4
0
        private static void FetchEDCConnectionList(SqlConnection connection, EDCEditDto dto)
        {
            const string Sql =
               @"
SELECT
     [Id]
    ,[GuidId]   
    ,[EDCId]
    ,[ConnectionSetupId]
    ,[FirstExpression] 
FROM
    [dbo].[EDCConnections]
WHERE [EDCId] = @edcId;
";
            using (var cmd = new SqlCommand(Sql, connection))
            {
                cmd.Parameters.AddWithValue("@edcId", dto.Id);

                var result = new List<EDCConnectionEditDto>();

                try
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var param = new EDCConnectionEditDto
                            {
                                Id = reader.GetInt(0),
                                Guid = reader.GetGuid(1),
                                EDCId = reader.GetInt32(2),
                                ConnectionSetupId = reader.GetInt32(3),
                                FirstExpression = reader.GetString(4)
                            };

                            result.Add(param);
                        }

                        foreach (var editDto in result)
                        {
                            editDto.Connection = new ConnectionSettingsDto();
                            FetchConnectionSetting(connection, editDto);
                        }

                        dto.ConnectionList.AddRange(result);
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Data.ToString());
                }
            }
        }