Ejemplo n.º 1
0
        public void Delete(int id)
        {
            MatchUrls_DeleteByHelpId(id);

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.FirstTimeHelp_Delete;
                    command.Parameters.Add(new SqlParameter("@id", id));

                    connection.Open();
                    command.ExecuteNonQuery();
                }
        }
Ejemplo n.º 2
0
        public void Create(FirstTimeHelp help)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.FirstTimeHelp_Create;
                    AddParameters(help, command);

                    connection.Open();
                    help.Id = (int)command.ExecuteScalar();
                }

            MatchUrls_CreateByHelpId(help.Id, help.MatchUrls);
        }
Ejemplo n.º 3
0
        public IEnumerable <DocumentationPage> ReadAll()
        {
            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.DocumentationPage_ReadAll;

                    connection.Open();
                    var reader = command.ExecuteReader();
                    foreach (var page in HydratePages(reader))
                    {
                        yield return(page);
                    }
                }
        }
Ejemplo n.º 4
0
        public IEnumerable <Bullet> ReadAll()
        {
            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.Bullet_ReadAll;

                    connection.Open();
                    var reader = command.ExecuteReader();
                    foreach (var bullet in HydrateBullets(reader))
                    {
                        yield return(bullet);
                    }
                }
        }
Ejemplo n.º 5
0
        public IEnumerable <FirstTimeHelp> ReadAll()
        {
            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.FirstTimeHelp_ReadAll;

                    connection.Open();
                    var reader = command.ExecuteReader();
                    foreach (var help in HydratePages(reader))
                    {
                        yield return(help);
                    }
                }
        }
Ejemplo n.º 6
0
        public void DeleteExcept(List <int> pageIds)
        {
            if (null == pageIds || pageIds.Count == 0)
            {
                return;
            }

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.DocumentationPage_DeleteExcept.Replace("@pageIds", pageIds.ToCsv());

                    connection.Open();
                    command.ExecuteNonQuery();
                }
        }
Ejemplo n.º 7
0
        public void Update(FirstTimeHelp help)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.FirstTimeHelp_Update;
                    AddParameters(help, command);
                    command.Parameters.Add(new SqlParameter("@id", help.Id));

                    connection.Open();
                    command.ExecuteNonQuery();
                }

            MatchUrls_DeleteByHelpId(help.Id);
            MatchUrls_CreateByHelpId(help.Id, help.MatchUrls);
        }
Ejemplo n.º 8
0
        public List <DocumentationPage> ReadByParentId(int?parentId)
        {
            List <DocumentationPage> result = null;

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.DocumentationPage_ReadByParentId;
                    command.Parameters.Add(new SqlParameter("@parentId", (object)parentId ?? DBNull.Value));

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        result = new List <DocumentationPage>(HydratePages(reader));
                    }
                }

            return(result ?? new List <DocumentationPage>());
        }
Ejemplo n.º 9
0
        public DocumentationPage Read(int id)
        {
            DocumentationPage result = null;

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.DocumentationPage_ReadById;
                    command.Parameters.Add(new SqlParameter("@id", id));

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        result = HydratePages(reader).FirstOrDefault();
                    }
                }

            return(result);
        }
Ejemplo n.º 10
0
        public List <Bullet> ReadByPageId(int pageId)
        {
            List <Bullet> result;

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.Bullet_ReadByPageId;
                    command.Parameters.Add(new SqlParameter("@pageId", pageId));

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        result = new List <Bullet>(HydrateBullets(reader));
                    }
                }

            return(result);
        }
Ejemplo n.º 11
0
        public FirstTimeHelp ReadByUrl(string url)
        {
            FirstTimeHelp result = null;

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.FirstTimeHelp_ReadByUrl;
                    command.Parameters.Add(new SqlParameter("@url", url));

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        result = HydratePages(reader).FirstOrDefault();
                    }
                }

            return(result);
        }
Ejemplo n.º 12
0
        public UserPageSettings Read(string userName, int pageId)
        {
            UserPageSettings result = null;

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.UserPageSettings_ReadByUserAndPage;
                    command.Parameters.AddRange(new SqlParameter[] {
                        new SqlParameter("@userName", userName),
                        new SqlParameter("@pageId", pageId)
                    });

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        result = HydrateUserPageSettings(reader).FirstOrDefault();
                    }
                }

            return(result);
        }
Ejemplo n.º 13
0
        public List <DocumentationPage> ReadTableOfContents(bool includeHidden)
        {
            var result = new List <DocumentationPage>();

            using (var connection = SqlConnectionFactory.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.DocumentationPage_ReadTableOfContents;
                    command.Parameters.Add(new SqlParameter("@includeHidden", includeHidden));

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        var idOrdinal           = reader.GetOrdinal("Id");
                        var parentPageIdOrdinal = reader.GetOrdinal("ParentPageId");
                        var orderOrdinal        = reader.GetOrdinal("Order");
                        var titleOrdinal        = reader.GetOrdinal("Title");
                        var isHiddenOrdinal     = reader.GetOrdinal("IsHidden");

                        while (reader.Read())
                        {
                            result.Add(new DocumentationPage
                            {
                                Id           = reader.GetInt32(idOrdinal),
                                ParentPageId = reader.IsDBNull(parentPageIdOrdinal) ? (int?)null : reader.GetInt32(parentPageIdOrdinal),
                                Order        = reader.GetInt32(orderOrdinal),
                                Title        = reader.GetString(titleOrdinal),
                                IsHidden     = reader.GetBoolean(isHiddenOrdinal),
                            });
                        }
                    }
                }

            return(result);
        }
Ejemplo n.º 14
0
        private void MatchUrls_CreateByHelpId(int helpId, string matchUrls)
        {
            if (!string.IsNullOrEmpty(matchUrls))
            {
                var pageUrls = matchUrls.Trim().Split(' ');

                using (var connection = SqlConnectionFactory.GetConnection())
                {
                    connection.Open();
                    foreach (var pageUrl in pageUrls)
                    {
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandType = CommandType.Text;
                            command.CommandText = SqlScripts.PageUrl_Create;
                            command.Parameters.Add(new SqlParameter("@url", pageUrl.Replace('*', '%')));
                            command.Parameters.Add(new SqlParameter("@pageId", helpId));

                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }