コード例 #1
0
ファイル: ProcessDAL.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Updates section data.
        /// </summary>
        /// <param name="dto">The section DTO.</param>
        /// <param name="locDto">The section localization DTO.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception>
        public void UpdateSectionWithLocalization(SectionDto dto, SectionLocalizationDto locDto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
                @"
UPDATE [dbo].[Sections]
SET   [ProcessId]    = @p_ProcessId
     ,[Guid]         = @p_Guid
     ,[PaperclipsEnabled] = @p_PaperclipsEnabled
     ,[Position]     = @p_Position
WHERE  [Id]           = @p_Id
";

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

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_ProcessId", dto.ProcessId);
                    command.Parameters.AddWithValue("@p_Guid", dto.Guid);
                    command.Parameters.AddWithValue("@p_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_PaperclipsEnabled", dto.PaperclipsEnabled);
                    command.Parameters.AddWithValue("@p_Position", dto.Position);

                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.RecordsAffected == 0)
                        {
                            throw new DBConcurrencyException(Resources.StaleDataException);
                        }
                    }
                }
            }

            UpdateSectionLocalization(locDto);
        }
コード例 #2
0
ファイル: ProcessDAL2.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Updates the localization for process sections.
        /// </summary>
        /// <param name="dto">The localization dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        public void UpdateSectionLocalization(SectionLocalizationDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

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

                const string commandText = @"
IF EXISTS ( SELECT * 
            FROM [dbo].[SectionLocalizations] 
            WHERE [LocalizationId] = @p_localizationId and [SectionId] = @p_sectionId)
BEGIN
UPDATE  [dbo].[SectionLocalizations]
SET     [LocalizationId]    = @p_localizationId,
        [SectionId]         = @p_sectionId,
        [GuidId]            = @p_guidId,
        [Name]              = @p_name
WHERE   [LocalizationId] = @p_localizationId and [SectionId] = @p_sectionId
END

ELSE

INSERT INTO [dbo].[SectionLocalizations]
  (
    [LocalizationId],
    [SectionId],
    [Name]
  )
VALUES
  (
    @p_localizationid,
    @p_sectionId,
    @p_name)";

                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_localizationId", dto.LocalizationId);
                    command.Parameters.AddWithValue("@p_sectionId", dto.SectionId);
                    command.Parameters.AddWithValue("@p_guidId", dto.GuidId);
                    command.Parameters.AddWithValue("@p_name", dto.Name);

                    var rowsAffetcted = command.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }