Ejemplo n.º 1
0
        public static void SetCategories2Manga(int iMangaId, Category[] lCategories)
        {
            if (connection != null)
            {
                SQLiteTransaction oTransaction = connection.BeginTransaction();

                bool bFailed = false;

                foreach (Category oCategory in lCategories)
                {
                    var oBuilder = new StringBuilder();
                    oBuilder.AppendLine("REPLACE INTO Categories2Manga ");
                    oBuilder.AppendLine("(iMangaId, CategoryId)");
                    oBuilder.AppendLine("VALUES");
                    oBuilder.AppendLine(
                        $"({iMangaId},{oCategory.CategoryId})");

                    var oCmd = new SQLiteCommand(oBuilder.ToString(), connection);

                    if (oCmd.ExecuteNonQuery() != 1)
                    {
                        oTransaction.Rollback();
                        bFailed = true;
                        break;
                    }
                }

                if (!bFailed)
                    oTransaction.Commit();

                oTransaction.Dispose();
            }
        }
Ejemplo n.º 2
0
        public static List<Category> GetAllCategories()
        {
            var lResult = new List<Category>();

            var oBuilder = new StringBuilder();
            oBuilder.AppendLine("SELECT ");
            oBuilder.AppendLine("CategoryId, Name, sDesc ");
            oBuilder.AppendLine("FROM ");
            oBuilder.AppendLine("Categories");

            if (connection != null)
            {
                var oCmd = new SQLiteCommand(oBuilder.ToString(), connection);
                using (var oReader = oCmd.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        var oCategory = new Category(oReader.GetInt32(oReader.GetOrdinal("CategoryId")), oReader["sTitle"]?.ToString())
                        {
                            Description = oReader["sDesc"]?.ToString()
                        };

                        lResult.Add(oCategory);
                    }
                }
            }

            return lResult;
        }
Ejemplo n.º 3
0
        public static bool SetCategory(Category oCategory)
        {
            var oBuilder = new StringBuilder();
            oBuilder.AppendLine("REPLACE INTO Categories ");
            oBuilder.AppendLine("(iCategory, Name,sDesc)");
            oBuilder.AppendLine("VALUES");
            oBuilder.AppendLine(
                $"({oCategory.CategoryId},{oCategory.Name},{oCategory.Description})");

            if (connection != null)
            {
                var oCmd = new SQLiteCommand(oBuilder.ToString(), connection);
                return oCmd.ExecuteNonQuery() == 1;
            }

            return false;
        }