示例#1
0
        internal static List <Participant> GetAllParticipantsFromDB()
        {
            List <Participant> participants = new List <Participant>();
            string             connection   = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                participants = db.Query <Participant>().ToList();
            }
            return(participants);
        }
示例#2
0
        internal static List <Blog> GetNewest3BlogsFromDB()
        {
            List <Blog> blogs      = new List <Blog>();
            string      connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                blogs = db.Query <Blog>("SELECT TOP 3 * FROM appadmin.Blogs ORDER BY CreatedOn DESC").ToList();
            }
            return(blogs);
        }
示例#3
0
        internal static LastInsertId PopulateBlogs(Blog blog)
        {
            LastInsertId retVal;
            string       connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                retVal = db.Insert <Blog>(blog);
            }
            return(retVal);
        }
示例#4
0
        internal static Article FindArticleById(int id)
        {
            Article retVal     = new Article();
            string  connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                retVal = db.Query <Article>(a => a.ID == id).FirstOrDefault();
            }
            return(retVal);
        }
示例#5
0
        internal static Workshop FindWorkshopByLabName(String name)
        {
            Workshop retVal     = null;
            string   connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                retVal = db.Query <Workshop>(w => w.Name == name).FirstOrDefault();
            }
            return(retVal);
        }
示例#6
0
        internal static List <T> FindObjectsByType <T>(String query) where T : class
        {
            List <T> retVal;
            string   connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                retVal = db.Query <T>(query).ToList();
            }
            return(retVal);
        }
示例#7
0
        internal static void CreateTable <T>() where T : class
        {
            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                //First time run only - the below will create table of a given class
                //If CreationOptions is set to DropIt, the below will recreate the table
                var builder = db.DatabaseTools().GetCreateTableBuilder <T>();
                builder.ExecuteDDL();
            }
        }
示例#8
0
        internal static List <Cooperator> FindCooperatorsByType(String type)
        {
            List <Cooperator> retVal;
            string            connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                retVal = db.Query <Cooperator>(c => c.Type == type).ToList();
            }

            return(retVal);
        }
示例#9
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            SqlFuDao.ConnectionStringIs(ConfigurationManager.ConnectionStrings["mainConnString"].ConnectionString, DbEngine.SQLite);
            Instances.RegisterTransient <LocationChoice>();
            Instances.RegisterTransient <MainWindow>();

            if (Settings.Default.Airport.IsNullOrEmpty())
            {
                Instances.Get <LocationChoice>().Show();
            }
            else
            {
                Instances.Get <MainWindow>().Show();
            }
        }
示例#10
0
        internal static List <Tag> GetTagsForBlog(Blog blog)
        {
            List <Tag> tags = new List <Tag>();

            String sql   = @"SELECT t.TagName, t.TagURL
FROM appadmin.Tags t
INNER JOIN appadmin.BlogTags bt ON t.ID = bt.TagID
WHERE bt.BlogID = {0}";
            String query = String.Format(sql, blog.ID);

            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                tags = db.Query <Tag>(query).ToList();
            }

            return(tags);
        }
示例#11
0
        internal static void CreateBlogTagsLinkerTable()
        {
            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            using (DbConnection db = SqlFuDao.GetConnection())
            {
                var builder = db.DatabaseTools().GetCreateTableBuilder("BlogTags", IfTableExists.Ignore);
                builder.Columns
                .Add("BlogID", DbType.Int32, isNullable: false, autoIncrement: false)
                .Add("TagID", DbType.Int32, isNullable: false, autoIncrement: false);

                builder.Constraints.AddPrimaryKeyOn("BlogID,TagID", "PK_BlogTags");
                builder.Constraints["PK_BlogTags"].IfDatabaseIs(DbEngine.SqlServer)
                .PrimaryKeyOptions(SqlServerOptions.PrimaryKeyIs.Clustered());
                builder.Indexes.AddIndexOn("TagID,BlogID", isUnique: true, indexName: "UX_BlogTags");

                builder.ExecuteDDL();
            }
        }
示例#12
0
        internal static Blog FindBlogByTagName(string tagName)
        {
            Blog   retVal      = null;
            string hashTagName = string.Empty;

            if (!String.IsNullOrEmpty(tagName))
            {
                hashTagName = tagName;
                if (!tagName.StartsWith("#"))
                {
                    hashTagName = "#" + tagName;
                }
            }

            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBContext"].ConnectionString;

            SqlFuDao.ConnectionStringIs(connection, DbEngine.SqlServer);
            Tag tag;

            using (DbConnection db = SqlFuDao.GetConnection())
            {
                if (tagName.Equals(hashTagName, StringComparison.InvariantCulture))
                {
                    tag = db.Query <Tag>(t => t.TagName == tagName).FirstOrDefault();
                }
                else
                {
                    tag = db.Query <Tag>(t => t.TagName == tagName || t.TagName == hashTagName).FirstOrDefault();
                }
                if (tag != null)
                {
                    retVal = db.Query <Blog>(b => b.Tags.Contains(tag)).FirstOrDefault();
                }
            }
            return(retVal);
        }
示例#13
0
 static Config()
 {
     SqlFuDao.OnException = (cmd, ex) => Console.WriteLine("\nSql:{1}\nException:\n\t\t{0}", ex, cmd.FormatCommand());
     SqlFuDao.OnCommand   = cmd => Console.WriteLine(cmd.FormatCommand());
     SqlFuDao.ConnectionStringIs(Connex, DbEngine.SqlServer);
 }