예제 #1
0
        /// <summary>
        /// Updates field.
        /// </summary>
        /// <param name="data">The DTO object.</param>
        /// <param name="locDto">The loc dto.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void UpdateFieldWithLocalization(FieldDto data, FieldLocalizationDto locDto)
        {
            if (data == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "data"));

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

                const string CommandText =
                    @"
UPDATE [dbo].[Fields]
SET    [FieldTypeId]     = @p_FieldTypeId
      ,[IsRemoved]       = @p_IsRemoved
      ,[LastModifiedOn]  = @p_LastModifiedOn
      ,[SectionId]       = @p_SectionId
      ,[Width]           = @p_Width
      ,[RowSpan]         = @p_RowSpan
      ,[ShowInList]      = @p_ShowInList
      ,[IncludeInFilter] = @p_IncludeInFilter
      ,[UseInGlobalSearch] = @p_useInGlobalSearch
      ,[HideFromDetails] = @p_HideFromDetails
      ,[SystemName]      = @p_SystemName
      ,[Position]        = @p_Position
      ,[CopyOnSchedule]  = @p_CopyOnSchedule
      ,[DeepCopy]        = @p_DeepCopy
      ,[Guid]            = @p_Guid
      ,[SearchPosition]  = @p_SearchPosition
      ,[SearchWidth]     = @p_SearchWidth
      ,[AllowLocalizedData] = @p_AllowLocalizedData
WHERE  [Id]              = @p_Id";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", data.Id);
                    command.Parameters.AddWithValue("@p_Name", data.Name);
                    command.Parameters.AddWithValue("@p_SystemName", data.SystemName);
                    command.Parameters.AddWithValue("@p_FieldTypeId", data.FieldTypeId);
                    command.Parameters.AddWithValue("@p_IsRemoved", false);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@p_Width", data.Width);
                    command.Parameters.AddWithValue("@p_RowSpan", data.RowSpan);
                    command.Parameters.AddWithValue("@p_ShowInList", data.ShowInList);
                    command.Parameters.AddWithValue("@p_IncludeInFilter", data.IncludeInFilter);
                    command.Parameters.AddWithValue("@p_useInGlobalSearch", data.UseInGlobalSearch);
                    command.Parameters.AddWithValue("@p_HideFromDetails", data.HideFromDetails);
                    command.Parameters.AddWithValue("@p_Position", data.Position);
                    command.Parameters.AddWithValue("@p_CopyOnSchedule", data.CopyFieldValueOnCopyItem);
                    command.Parameters.AddWithValue("@p_DeepCopy", data.DeepCopy);
                    command.Parameters.AddWithValue("@p_Guid", data.Guid);
                    command.Parameters.AddWithValue("@p_SearchPosition", data.SearchPosition);
                    command.Parameters.AddWithValue("@p_SearchWidth", data.SearchWidth);
                    command.Parameters.AddWithValue("@p_AllowLocalizedData", data.AllowLocalizedData);
                    if (data.SectionId == null)
                    {
                        command.Parameters.AddWithValue("@p_SectionId", DBNull.Value);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@p_SectionId", data.SectionId);
                    }

                    command.ExecuteNonQuery();
                }
            }

            UpdateFieldLocalization(locDto);
        }
예제 #2
0
        /// <summary>
        /// Updates the localization for fields.
        /// </summary>
        /// <param name="dto">The localization dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        public void UpdateFieldLocalization(FieldLocalizationDto 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].[FieldLocalizations] 
            WHERE [LocalizationId] = @p_localizationId and [FieldId] = @p_fieldId)
BEGIN
UPDATE  [dbo].[FieldLocalizations]
SET     [LocalizationId]    = @p_localizationId,
        [FieldId]           = @p_fieldId,
        [GuidId]            = @p_guidId,
        [Name]              = @p_name
WHERE   [LocalizationId] = @p_localizationId and [FieldId] = @p_fieldId
END

ELSE

INSERT INTO [dbo].[FieldLocalizations]
  (
    [LocalizationId],
    [FieldId],
    [Name]
  )
VALUES
  (
    @p_localizationId,
    @p_fieldId,
    @p_name)";

                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_localizationId", dto.LocalizationId);
                    command.Parameters.AddWithValue("@p_fieldId", dto.FieldId);
                    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);
                    }
                }
            }
        }