Esempio n. 1
0
        /// <summary>
        /// Updates cross ref required step.
        /// </summary>
        /// <param name="buildDto">The build DTO.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception>
        public void UpdateCrossRefRequiredStep(CrossRefRequiredStepDto buildDto)
        {
            if (buildDto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "buildDto"));

            const string CmdText =
                @"
UPDATE
     [dbo].[CrossRefRequredFieldStep]
SET
     [CrossRefProcessId]        = @crossRefProcessId
    ,[FieldId]                  = @fieldId
    ,[DisplayFieldName]         = @displayFieldName
    ,[AllowMultiple]            = @allowMultiple
    ,[EditViaSpreadsheet]       = @editViaSpreadsheet
    ,[LinkFieldSystemName]      = @linkFieldSystemName
    ,[MultiCrAllowLinkUnlink]   = @multiCrAllowLinkUnlink
    ,[MultiCrAllowAddNew]       = @multiCrAllowAddNew
    ,[IsOwner]                  = @isOwner
    ,[AllowRecentVersion]       = @allowRecentVersion
WHERE
     [Id] = @stepId";

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

                using (var cmd = new SqlCommand(CmdText, cn))
                {
                    cmd.Parameters.AddWithValue("@stepId", buildDto.Id);
                    cmd.Parameters.AddWithValue("@crossRefProcessId", AdoHelper.NullCheck(buildDto.CrossRefProcessId));
                    cmd.Parameters.AddWithValue("@fieldId", buildDto.FieldId);
                    cmd.Parameters.AddWithValue("@displayFieldName", AdoHelper.NullCheck(buildDto.DisplayFieldName));
                    cmd.Parameters.AddWithValue("@allowMultiple", buildDto.AllowMultiple);
                    cmd.Parameters.AddWithValue("@editViaSpreadsheet", buildDto.EditViaSpreadsheet);
                    cmd.Parameters.AddWithValue("@linkFieldSystemName", AdoHelper.NullCheck(buildDto.LinkFieldSystemName));
                    cmd.Parameters.AddWithValue("@multiCrAllowLinkUnlink", buildDto.MultiCrAllowLinkUnlink);
                    cmd.Parameters.AddWithValue("@multiCrAllowAddNew", buildDto.MultiCrAllowAddNew);
                    cmd.Parameters.AddWithValue("@isOwner", buildDto.IsOwner);
                    cmd.Parameters.AddWithValue("@allowRecentVersion", buildDto.AllowRecentVersion);

                    var rowsAffetcted = cmd.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves cross ref required step.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="isPublishedCopy">The is published copy.</param>
        /// <returns>The <see cref="CrossRefRequiredStepDto" />.</returns>
        public CrossRefRequiredStepDto FetchCrossRefRequiredStep(string processName, string fieldName, bool isPublishedCopy = false)
        {
            const string CmdText =
                @"
DECLARE @fieldId AS INT

SELECT @fieldId = f.Id
FROM
    [dbo].[Processes] p
    INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id
    INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id
WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName;

EXEC [dbo].[GetCrossRefRequiredStep] @FieldId = @fieldId;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                using (var cmd = new SqlCommand(CmdText, ctx.Connection))
                {
                    cmd.Parameters.AddWithValue("@processName", processName);
                    cmd.Parameters.AddWithValue("@fieldName", fieldName);
                    cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            var dto = new CrossRefRequiredStepDto
                                          {
                                              Id = reader.GetInt32(0),
                                              CrossRefProcessId = reader.GetNullableInt(1),
                                              FieldId = reader.GetInt32(2),
                                              DisplayFieldName = reader.GetString(3),
                                              AllowMultiple = reader.GetBoolean(4),
                                              EditViaSpreadsheet = reader.GetBoolean(5),
                                              MultiCrAllowLinkUnlink = reader.GetBoolean(6),
                                              MultiCrAllowAddNew = reader.GetBoolean(7),
                                              IsOwner = reader.GetBoolean(8),
                                              AllowRecentVersion = reader.GetBoolean(9),
                                              LinkFieldSystemName = reader.GetString(10)
                                          };

                            if (reader.NextResult())
                            {
                                while (reader.Read())
                                {
                                    var df = new CrossReferenceDisplayFieldDto
                                                 {
                                                     Id = reader.GetInt32(0),
                                                     DisplayName = reader.GetString(1),
                                                     FullPath = reader.GetString(2),
                                                     Order = reader.GetDouble(3),
                                                     FieldGuid = reader.GetGuid(4)
                                                 };

                                    dto.DisplayFields.Add(df);
                                }
                            }

                            return dto;
                        }
                    }
                }
            }

            return null;
        }
Esempio n. 3
0
        /// <summary>
        /// Inserts cross ref required step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException">
        /// Cross-reference process id is 0
        /// or
        /// Cross-reference field id is 0
        /// </exception>
        /// <exception cref="ArgumentNullException">The input DTO is null.</exception>
        public void InsertCrossRefRequiredStep(CrossRefRequiredStepDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            if (dto.CrossRefProcessId == 0 || dto.FieldId == 0)
            {
                if (dto.CrossRefProcessId == 0)
                {
                    throw new ArgumentException("Cross-reference process id is 0");
                }

                throw new ArgumentException("Cross-reference field id is 0");
            }

            const string CmdText =
                @"
INSERT INTO [dbo].[CrossRefRequredFieldStep]
(
     [CrossRefProcessId]
    ,[FieldId]
    ,[DisplayFieldName]
    ,[AllowMultiple]
    ,[EditViaSpreadsheet]
    ,[LinkFieldSystemName]
    ,[MultiCrAllowLinkUnlink]
    ,[MultiCrAllowAddNew]
    ,[IsOwner]
    ,[AllowRecentVersion]
)
VALUES
(
     @crossRefProcessId
    ,@fieldId
    ,@displayFieldName
    ,@allowMultiple
    ,@editViaSpreadsheet
    ,@linkFieldSystemName
    ,@multiCrAllowLinkUnlink
    ,@multiCrAllowAddNew
    ,@isOwner
    ,@allowRecentVersion
);
SELECT [Id]
FROM   [dbo].[CrossRefRequredFieldStep]
WHERE  [Id] = SCOPE_IDENTITY()";

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

                using (var cmd = new SqlCommand(CmdText, cn))
                {
                    cmd.Parameters.AddWithValue("@crossRefProcessId", AdoHelper.NullCheck(dto.CrossRefProcessId));
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);
                    cmd.Parameters.AddWithValue("@displayFieldName", AdoHelper.NullCheck(dto.DisplayFieldName));
                    cmd.Parameters.AddWithValue("@allowMultiple", dto.AllowMultiple);
                    cmd.Parameters.AddWithValue("@editViaSpreadsheet", dto.EditViaSpreadsheet);
                    cmd.Parameters.AddWithValue("@linkFieldSystemName", AdoHelper.NullCheck(dto.LinkFieldSystemName));
                    cmd.Parameters.AddWithValue("@multiCrAllowLinkUnlink", dto.MultiCrAllowLinkUnlink);
                    cmd.Parameters.AddWithValue("@multiCrAllowAddNew", dto.MultiCrAllowAddNew);
                    cmd.Parameters.AddWithValue("@isOwner", dto.IsOwner);
                    cmd.Parameters.AddWithValue("@allowRecentVersion", dto.AllowRecentVersion);

                    dto.Id = (int)cmd.ExecuteScalar();
                }
            }
        }