Beispiel #1
0
        public IList<LocalizationDto> FetchLocalizationList()
        {
            var result = new List<LocalizationDto>();
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                var commandText = string.Format(CultureInfo.InvariantCulture, 
                    @"
SELECT  loc.[Id],
        loc.[LocalName],
        loc.[EnglishName],
        loc.[CultureName],
        loc.[IconId],
        loc.[IsRightToLeft],
        loc.[IsDefault]
FROM    [dbo].[Localizations] loc
ORDER BY loc.EnglishName");
                using (var cmd = new SqlCommand(commandText, connection))
                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    while (reader.Read())
                    {
                        var dto = new LocalizationDto
                        {
                            Id = reader.GetInt32(0),
                            LocalName = reader.GetString(1),
                            EnglishName = reader.GetString(2),
                            CultureName = reader.GetString(3),
                            IconId = reader.GetInt32(4),
                            IsRightToLeft = reader.GetBoolean(5),
                            IsDefault = reader.GetBoolean(6)
                        };

                        result.Add(dto);
                    }
            }

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// Inserts the localization.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        public void InsertLocalization(LocalizationDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string commandText = @"
IF EXISTS ( SELECT *
            FROM [dbo].[Localizations] 
            WHERE Id = @p_Id)
BEGIN
UPDATE [dbo].[Localizations]
SET    [LocalName]      = @p_LocalName,
       [EnglishName]    = @p_EnglishName,
       [CultureName]    = @p_CultureName,
       [IconId]         = @p_IconId,
       [IsRightToLeft]  = @p_IsRightToLeft,
       [IsDefault]      = @p_IsDefault
WHERE  [Id]             = @p_Id

SELECT @p_Id;
END

ELSE

INSERT INTO [dbo].[Localizations]
  (
    [LocalName],
    [EnglishName],
    [CultureName],
    [IconId],
    [IsRightToLeft],
    [IsDefault]
  )
VALUES
  (
    @p_LocalName,
    @p_EnglishName,
    @p_CultureName,
    @p_IconId,
    @p_IsRightToLeft,
    @p_IsDefault
  );
SELECT [Id]
FROM [dbo].[Localizations]
WHERE Id = SCOPE_IDENTITY();";
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }

                using (var command = new SqlCommand(commandText, cn))
                {
                    command.Parameters.AddWithValue("@p_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_LocalName", dto.LocalName);
                    command.Parameters.AddWithValue("@p_EnglishName", dto.EnglishName);
                    command.Parameters.AddWithValue("@p_CultureName", dto.CultureName);
                    command.Parameters.AddWithValue("@p_IconId", dto.IconId);
                    command.Parameters.AddWithValue("@p_IsRightToLeft", dto.IsRightToLeft);
                    command.Parameters.AddWithValue("@p_IsDefault", dto.IsDefault);

                    dto.Id = (int)command.ExecuteScalar();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Fetches the localization information.
        /// </summary>
        /// <param name="id">The unique identifier.</param>
        /// <returns>LocalizationDto.</returns>
        public LocalizationDto FetchLocalizationInfo(int id)
        {
            var result = new LocalizationDto();
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                const string commandText = @"
SELECT  loc.[Id],
        loc.[LocalName],
        loc.[EnglishName],
        loc.[CultureName],
        loc.[IconId],
        loc.[IsRightToLeft]
FROM    [dbo].[Localizations] loc
WHERE   loc.Id = @p_id
ORDER BY loc.EnglishName";
                using (var cmd = new SqlCommand(commandText, connection))
                {
                    cmd.Parameters.AddWithValue("@p_id", id);
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            result = new LocalizationDto
                            {
                                Id = reader.GetInt32(0),
                                LocalName = reader.GetString(1),
                                EnglishName = reader.GetString(2),
                                CultureName = reader.GetString(3),
                                IconId = reader.GetInt32(4),
                                IsRightToLeft = reader.GetBoolean(5)
                            };
                        }
                    }
                }
            }

            return result;
        }
Beispiel #4
0
        /// <summary>
        /// Updates the localization.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        public void UpdateLocalization(LocalizationDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string commandText =
                @"
UPDATE [dbo].[Localizations]
SET    [LocalName]      = @p_LocalName,
       [EnglishName]    = @p_EnglishName,
       [CultureName]    = @p_CultureName,
       [IconId]         = @p_IconId,
       [IsRightToLeft]  = @p_IsRightToLeft,
       [IsDefault]      = @p_IsDefault
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_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_LocalName", dto.LocalName);
                    command.Parameters.AddWithValue("@p_EnglishName", dto.EnglishName);
                    command.Parameters.AddWithValue("@p_CultureName", dto.CultureName);
                    command.Parameters.AddWithValue("@p_IconId", dto.IconId);
                    command.Parameters.AddWithValue("@p_IsRightToLeft", dto.IsRightToLeft);
                    command.Parameters.AddWithValue("@p_IsDefault", dto.IsDefault);
                    command.ExecuteNonQuery();
                }
            }
        }