Esempio n. 1
0
        private static List <Category> GetData()
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select * from category order by LABEL_TEXT";

            return(db.GetObjectList <Category>(gen.GetSelectCommandBasic()));
        }
Esempio n. 2
0
        private List <Article> GetAllData()
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select * from article order by INSERT_DATE desc";

            List <Article> sonuc = db.GetObjectList <Article>(gen.GetSelectCommandBasic());

            return(sonuc);
        }
Esempio n. 3
0
        public ActionResult AddArticle(string TITLE, string CONTENT, int[] CATEGORIES)
        {
            try
            {
                string nGuid = Guid.NewGuid().ToString("N");

                IDatabase2      db  = DatabaseFactory.GetDbObject(DbSettings.TransactionMode);
                IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

                gen.TableName = "article";

                gen.AddDataParameter("TITLE", TITLE);
                gen.AddDataParameter("TEXT", CONTENT);
                gen.AddDataParameter("INSERT_DATE", DateTime.Now);
                gen.AddDataParameter("AUTHOR", "vyigity");
                gen.AddDataParameter("ID_GUID", nGuid);

                db.ExecuteQuery(gen.GetInsertCommand());

                IQueryGenerator gen2 = QueryGeneratorFactory.GetDbObject();
                gen2.SelectText = "select ID from article where ";
                gen2.FilterText = "ID_GUID = :p1";
                gen2.AddFilterParameter("p1", nGuid);

                if (CATEGORIES != null && CATEGORIES.Length > 0)
                {
                    int id = Util.GetProperty <int>(db.GetSingleValue(gen2.GetSelectCommandBasic()));

                    foreach (int i in CATEGORIES)
                    {
                        IQueryGenerator gen3 = QueryGeneratorFactory.GetDbObject();
                        gen3.TableName = "article_category";

                        gen3.AddDataParameter("ARTICLE_ID", id);
                        gen3.AddDataParameter("CATEGORY_ID", i);

                        db.ExecuteQuery(gen3.GetInsertCommand());
                    }
                }

                db.Commit();

                ProcessView();

                return(RedirectToAction("ManageArticle"));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 4
0
        private static void FillComments(IDatabase2 db, Article article)
        {
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select * from blog.comment c where c.APPROVED = 1 and ";
            gen.FilterText = "c.article_id = :p1 ";
            gen.SelectTail = "order by c.INSERT_DATE desc";

            gen.AddFilterParameter("p1", article.ID);

            List <Comment> cList = db.GetObjectList <Comment>(gen.GetSelectCommandBasic());

            article.COMMENTS = cList;
        }
Esempio n. 5
0
        private Article GetData(int id)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select * from article where ";
            gen.FilterText = "id=:p1";

            gen.AddFilterParameter("p1", id);

            Article sonuc = db.GetObject <Article>(gen.GetSelectCommandBasic());

            return(sonuc);
        }
Esempio n. 6
0
        private static List <Comment> GetData()
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = @"select c.*, a.TITLE ARTICLE_TITLE from blog.comment c, blog.article a 

                                where

                                c.ARTICLE_ID = a.ID and

                                c.APPROVED = 0 order by INSERT_DATE desc";

            return(db.GetObjectList <Comment>(gen.GetSelectCommandBasic()));
        }
Esempio n. 7
0
        private static List <Article> GetData(string searchText)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select a.*,(select count(*) from comment c where c.article_id = a.id and c.APPROVED = 1) COMMENT_COUNT from article a where a.ACTIVE=1 and ";
            gen.FilterText = "TEXT like CONCAT('%',:p1,'%') ";
            gen.SelectTail = "order by INSERT_DATE desc";
            gen.AddFilterParameter("p1", searchText);
            List <Article> aList = db.GetObjectList <Article>(gen.GetSelectCommandBasic());

            FillCategory(db, aList);

            return(aList);
        }
Esempio n. 8
0
        private static List <Category> GetLoadedCategory(int id)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select c.* from category c, article_category ac where ";
            gen.FilterText = "c.id = ac.category_id and ac.article_id = :p1 ";
            gen.SelectTail = "order by c.LABEL_TEXT";

            gen.AddFilterParameter("p1", id);

            List <Category> aList = db.GetObjectList <Category>(gen.GetSelectCommandBasic());

            return(aList);
        }
Esempio n. 9
0
        private static List <Article> GetDataWithCategory(int id)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select a.*, (select count(*) from comment co where co.article_id = a.id and co.APPROVED = 1) COMMENT_COUNT from article a, article_category c where a.id = c.article_id and a.ACTIVE=1 and ";
            gen.FilterText = "c.category_id = :p1 order by a. INSERT_DATE desc";

            gen.AddFilterParameter("p1", id);

            List <Article> aList = db.GetObjectList <Article>(gen.GetSelectCommandBasic());

            FillCategory(db, aList);

            return(aList);
        }
Esempio n. 10
0
        private static void FillCategory(IDatabase2 db, List <Article> aList)
        {
            foreach (var arc in aList)
            {
                IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();
                gen.SelectText = "select * from category c ,article_category a where ";
                gen.FilterText = "a.category_id = c.id and  a.article_id = :p1";
                gen.SelectTail = "order by c.LABEL_TEXT";

                gen.AddFilterParameter("p1", arc.ID);

                List <Category> cList = db.GetObjectList <Category>(gen.GetSelectCommandBasic());

                arc.CATEGORIES = cList;
            }
        }
Esempio n. 11
0
        private static List <Article> GetData(int id)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select a.*, (select count(*) from comment c where c.article_id = a.id and c.APPROVED = 1) COMMENT_COUNT from article a where a.ACTIVE=1 and ";
            gen.FilterText = "a.id = :p1";

            gen.AddFilterParameter("p1", id);

            List <Article> aList = db.GetObjectList <Article>(gen.GetSelectCommandBasic());

            FillCategory(db, aList);
            FillComments(db, aList.First());

            return(aList);
        }
Esempio n. 12
0
        public ActionResult DeleteCategory(int ID)
        {
            IDatabase2 db = DatabaseFactory.GetDbObject();

            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "delete from category where ";
            gen.FilterText = "id = :p1";

            gen.AddFilterParameter("p1", ID);

            db.ExecuteQuery(gen.GetSelectCommandBasic());

            List <Category> cList = ProcessView();

            return(View("Index", cList));
        }
Esempio n. 13
0
        public bool Login(string UserName, string Password)
        {
            IDatabase2      db  = DatabaseFactory.GetDbObject();
            IQueryGenerator gen = QueryGeneratorFactory.GetDbObject();

            gen.SelectText = "select count(*) from blog.user where ";
            gen.FilterText = "USER_NAME = :p1 and PASSWORD = :p2";
            gen.AddFilterParameter("p1", UserName);
            gen.AddFilterParameter("p2", Password);

            int i = Util.GetProperty <int>(db.GetSingleValue(gen.GetSelectCommandBasic()));

            if (i > 0)
            {
                HttpContext.Current.Session["UserName"] = UserName;
                return(true);
            }

            return(false);
        }