Example #1
0
        /// <summary>
        /// Updates the navigation item security configuration.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Data.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.</exception>
        public void UpdateNavigationItemSecurityConfiguration(NavigationItemSecurityConfigurationDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
UPDATE [dbo].[NavigationItemSecurityConfigurations]
SET
     [LastModifiedOn] = GETDATE()
    ,[NavigationItemId] = @navigationItemId
    ,[RoleId] = @roleId
    ,[CanView] = @canView
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("@navigationItemId", dto.NavigationItemId);
                    cmd.Parameters.AddWithValue("@roleId", dto.RoleId);
                    cmd.Parameters.AddWithValue("@canView", dto.CanView);

                    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 #2
0
        /// <summary>
        /// Fetches the navigation item security configurations.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="dto">The dto.</param>
        private static void FetchNavigationItemSecurityConfigurations(SqlConnection connection, NavigationItemEditDto dto)
        {
            const string Sql =
                @"
SELECT
     [Id]
    ,[RoleId]
    ,[CanView]
FROM
    [dbo].[NavigationItemSecurityConfigurations]
WHERE [NavigationItemId] = @itemId;
";

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

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    while (reader.Read())
                    {
                        var securityConfigurationDto = new NavigationItemSecurityConfigurationDto
                                                           {
                                                               Id = reader.GetInt(0),
                                                               RoleId = reader.GetInt(1),
                                                               CanView = reader.GetBoolean(2)
                                                           };

                        dto.SecurityConfigurations.Add(securityConfigurationDto);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Inserts the navigation item security configuration.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="System.ArgumentException"></exception>
        public void InsertNavigationItemSecurityConfiguration(NavigationItemSecurityConfigurationDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql = @"
INSERT INTO [dbo].[NavigationItemSecurityConfigurations]
(
     [LastModifiedOn]
    ,[NavigationItemId]
    ,[RoleId]
    ,[CanView]
)
VALUES
(
     GETDATE()
    ,@navigationItemId
    ,@roleId
    ,@canView
);

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

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

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@navigationItemId", dto.NavigationItemId);
                    cmd.Parameters.AddWithValue("@roleId", dto.RoleId);
                    cmd.Parameters.AddWithValue("@canView", dto.CanView);

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