Example #1
0
        /// <summary>
        /// Возвращает список дочерних папок
        /// </summary>
        /// <param name="userId">идентификатор пользователя</param>
        /// <param name="siteId">идентификатор родителя</param>
        /// <param name="folderId">идентификатор папки</param>
        /// <param name="permissionLevel">уровень доступа</param>
        /// <param name="countOnly">признак, разрешающий вернуть только количество записей</param>
        /// <param name="totalRecords">количество записей</param>
        /// <returns>список дочерних папок</returns>
        public List <SiteFolderDAL> GetChildSiteFoldersList(int userId, int siteId, int?folderId, int permissionLevel, bool countOnly, out int totalRecords)
        {
            var articleList = new List <SiteFolderDAL>();

            totalRecords = -1;

            object[] parameters =
            {
                new SqlParameter {
                    ParameterName = "user_id", DbType = DbType.Decimal, Value = userId
                },
                new SqlParameter {
                    ParameterName = "parent_entity_id", DbType = DbType.Decimal, Value = siteId
                },
                new SqlParameter {
                    ParameterName = "is_site", DbType = DbType.Boolean, Value = true
                },
                new SqlParameter {
                    ParameterName = "parent_folder_id", DbType = DbType.Decimal, IsNullable = true, Value = folderId
                },
                new SqlParameter {
                    ParameterName = "permission_level", DbType = DbType.Decimal, Value = permissionLevel
                },
                new SqlParameter {
                    ParameterName = "count_only", DbType = DbType.Int32, Value = countOnly
                },
                new SqlParameter {
                    ParameterName = "total_records", Direction = ParameterDirection.InputOutput, DbType = DbType.Int32, Value = totalRecords
                }
            };

            using (var dbCommand = this.CreateStoreCommand("qp_get_folders_tree", CommandType.StoredProcedure, parameters))
            {
                using (dbCommand.Connection.CreateConnectionScope())
                {
                    using (var reader = dbCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            IDataRecord record = reader;
                            var         folder = _siteFolderMaterializer.Materialize(record);
                            if (folder != null)
                            {
                                folder.Bind(SiteFolderSet);

                                var modifier = _modifierMaterializer.Materialize(record);
                                modifier?.Bind(UserSet);
                                articleList.Add(folder);
                            }
                        }
                    }

                    totalRecords = (int)dbCommand.Parameters["total_records"].Value;
                }
            }

            return(articleList);
        }
Example #2
0
        /// <summary>
        /// Возвращает информацию о пользователя по его логину и паролю
        /// </summary>
        /// <param name="login">логин</param>
        /// <param name="password">пароль</param>
        /// <param name="useNtLogin">разрешает Windows-аутентификацию</param>
        /// <param name="checkAdminAccess">включает проверку наличия прав администратора</param>
        /// <returns>информация о пользователе</returns>
        public UserDAL Authenticate(string login, string password, bool useNtLogin, bool checkAdminAccess)
        {
            UserDAL user;

            object[] parameters =
            {
                new SqlParameter {
                    ParameterName = "login", DbType = DbType.String, Size = 255, Value = login
                },
                new SqlParameter {
                    ParameterName = "password", DbType = DbType.String, Size = 20, Value = password ?? string.Empty
                },
                new SqlParameter {
                    ParameterName = "use_nt_login", DbType = DbType.Boolean, Value = useNtLogin
                },
                new SqlParameter {
                    ParameterName = "check_admin_access", DbType = DbType.Boolean, Value = checkAdminAccess
                }
            };

            using (var dbCommand = this.CreateStoreCommand("qp_authenticate", CommandType.StoredProcedure, parameters))
            {
                user = _userMaterializer
                       .Materialize(dbCommand)
                       .Bind(UserSet)
                       .SingleOrDefault();
            }

            return(user);
        }
Example #3
0
        public void ThenEachCategoryContainsData()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand    command    = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetAllCategories";

            // Operator
            connection.OpenIfNot();
            IDataReader             queryResult          = command.ExecuteReader();
            Materializer <Category> categoryMaterializer = new Materializer <Category>(queryResult);
            List <Category>         categories           = new List <Category>();

            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            foreach (Category cat in categories)
            {
                AssertPropertiesAreNotNull(cat.GetType(), cat);
            }
        }
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override TEntity ExecuteCommand(DbOperationContext context,
                                                  DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader <TEntity>(reader => {
                if (reader.Read())
                {
                    return Materializer.Materialize(reader);
                }

                return default(TEntity);
            }));
        }
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override IEnumerable <TEntity> ExecuteCommand(DbOperationContext context,
                                                                DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader(reader => {
                List <TEntity> collection = new List <TEntity>(BufferSize);
                while (reader.Read())
                {
                    collection.Add(Materializer.Materialize(reader));
                }

                return collection;
            }));
        }
Example #6
0
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override IEnumerable <TEntity> ExecuteCommand(DbOperationContext context,
                                                                DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader(reader => {
                List <TEntity> collection = new List <TEntity>(BufferSize);
                int count = 0;

                while (reader.Read())
                {
                    collection.Add(Materializer.Materialize(reader));
                }

                if (reader.NextResult() && reader.Read())
                {
                    count = reader.GetValue <int>(0);
                }

                return collection.ToSubset(count);
            }));
        }
        public void ThenCollectionOfCategoriesReturned()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand command = connection.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetAllCategories";

            // Operator
            connection.OpenIfNot();
            IDataReader queryResult = command.ExecuteReader();
            Materializer<Category> categoryMaterializer = new Materializer<Category>(queryResult);
            List<Category> categories = new List<Category>();
            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            Assert.IsTrue(categories.Any());
        }
Example #8
0
        public void ThenEmptyCategoryCollectionIsReturned()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand command = connection.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetCategory";
            command.Parameters.AddWithValue("Id", SomeCategoryId);

            // Operator
            connection.OpenIfNot();
            IDataReader queryResult = command.ExecuteReader();
            Materializer<Category> categoryMaterializer = new Materializer<Category>(queryResult);
            List<Category> categories = new List<Category>();
            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            Assert.IsTrue(categories.Count() == 0);
        }
Example #9
0
        public void ThenCollectionOfCategoriesReturned()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand    command    = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetAllCategories";

            // Operator
            connection.OpenIfNot();
            IDataReader             queryResult          = command.ExecuteReader();
            Materializer <Category> categoryMaterializer = new Materializer <Category>(queryResult);
            List <Category>         categories           = new List <Category>();

            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            Assert.IsTrue(categories.Any());
        }
        public void ThenEachCategoryContainsData()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand command = connection.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetAllCategories";

            // Operator
            connection.OpenIfNot();
            IDataReader queryResult = command.ExecuteReader();
            Materializer<Category> categoryMaterializer = new Materializer<Category>(queryResult);
            List<Category> categories = new List<Category>();
            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            foreach (Category cat in categories)
            {
                AssertPropertiesAreNotNull(cat.GetType(), cat);
            }
        }
Example #11
0
        public void ThenEmptyCategoryCollectionIsReturned()
        {
            // Build
            SqlConnection connection = (SqlConnection)DbConnectionFactory.Get().CreateIfNotExists("name=DefaultConnection");
            SqlCommand    command    = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.GetCategory";
            command.Parameters.AddWithValue("Id", SomeCategoryId);

            // Operator
            connection.OpenIfNot();
            IDataReader             queryResult          = command.ExecuteReader();
            Materializer <Category> categoryMaterializer = new Materializer <Category>(queryResult);
            List <Category>         categories           = new List <Category>();

            while (queryResult.Read())
            {
                categories.Add(categoryMaterializer.Materialize(queryResult));
            }

            // Check
            Assert.IsTrue(categories.Count() == 0);
        }