示例#1
0
        public int SaveCusLink(CusLink cusLink)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                if (cusLink.Id > 0)
                {
                    cusLink.Updatedate = DateTime.Now;
                    result             = conn.Execute("update cuslink set " +
                                                      "title=@Title," +
                                                      "url=@Url," +
                                                      "catid=@Catid," +
                                                      "linktype=@LinkType," +
                                                      "updatedate=@Updatedate where id=@Id", cusLink);
                }
                else
                {
                    cusLink.Adddate = DateTime.Now;
                    result          = conn.Execute("INSERT INTO cuslink(title,url,status,catid,linktype,adddate)" +
                                                   "values(@Title,@Url,@Status,@Catid,@LinkType,@Adddate)", cusLink);
                }
            }

            return(result);
        }
示例#2
0
        public IEnumerable <Link> PagerLinkList(int size, int offset, string catid, string title, string url, out int total)
        {
            string sqlwhere = "where 1=1";

            if (!string.IsNullOrWhiteSpace(catid))
            {
                sqlwhere += $" and catid = @catid";
            }
            if (!string.IsNullOrWhiteSpace(title))
            {
                sqlwhere += $" and title like '%{title}%'";
            }
            if (!string.IsNullOrWhiteSpace(url))
            {
                sqlwhere += $" and url like '%{url}%'";
            }

            IEnumerable <Link> list;

            total = 0;
            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT * FROM link {sqlwhere} ORDER BY createtime desc LIMIT @size OFFSET @offset");
                list = conn.Query <Link>(sql, new { catid, size, offset });

                total = conn.QueryFirstOrDefault <int>($"select count(*) from link {sqlwhere}", new { catid });
            }

            return(list);
        }
示例#3
0
        public int SaveArticle(Article article)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                object exists = conn.ExecuteScalar("select id from article where Id = @Id", new { Id = article.Id });
                if (exists == null && article.AddOrEdit)
                {
                    result = conn.Execute("INSERT INTO article(id,origin,catalog,icon,title,brief,body)" +
                                          "values(@Id,@Origin,@Catalog,@Icon,@Title,@Brief,@Body)", article);
                }
                else if (exists != null && !article.AddOrEdit)
                {
                    result = conn.Execute("update article set " +
                                          "origin=@Origin," +
                                          "catalog=@Catalog," +
                                          "icon=@Icon," +
                                          "title=@Title," +
                                          "brief=@Brief," +
                                          "body=@Body where Id=@Id", article);
                }
            }

            return(result);
        }
示例#4
0
        public IEnumerable <Article> PagerArticleList(int size, int skip, string id, string title, string catalog, out int total, string fields = "*")
        {
            string sqlWhere = $"where 1=1";

            if (!string.IsNullOrWhiteSpace(id))
            {
                sqlWhere = $"where id = @id";
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(title))
                {
                    sqlWhere += $" and title like '%{title}%'";
                }
                if (!string.IsNullOrWhiteSpace(catalog))
                {
                    sqlWhere += " and catalog = @catalog";
                }
            }

            IEnumerable <Article> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT {fields} FROM article {sqlWhere} ORDER BY createTime desc LIMIT @PageSize OFFSET @Offset");
                list = conn.Query <Article>(sql, new { id, title, catalog, PageSize = size, Offset = skip });

                total = conn.QueryFirstOrDefault <int>($"select count(*) FROM article {sqlWhere}", new { id, title, catalog });
            }

            return(list);
        }
示例#5
0
        public int SaveLink(Link link)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                Guid guid = new Guid();
                if (Guid.TryParse(link.Id, out guid))
                {
                    result = conn.Execute("update link set " +
                                          "title=@Title," +
                                          "url=@Url," +
                                          "icon=@Icon," +
                                          "catid=@Catid," +
                                          "linktype=@LinkType," +
                                          "brief=@Brief where id=@Id", link);
                }
                else
                {
                    link.Id = Guid.NewGuid().ToString();
                    result  = conn.Execute("INSERT INTO link(id,icon,linktype,catid,title,url,brief)" +
                                           "values(@Id,@Icon,@LinkType,@Catid,@Title,@Url,@Brief)", link);
                }
            }

            return(result);
        }
示例#6
0
        public int DeleteLink(string id)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                result = conn.Execute("delete from link where Id = @Id", new { Id = id });
            }

            return(result);
        }
示例#7
0
        public int UpdatedArticleVisited(string id)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                result = conn.Execute("update article set visited=visited+1 where id=@id", new { id });
            }

            return(result);
        }
示例#8
0
        public int UpdatedLinkVisited(string id)
        {
            int result = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                result = conn.Execute("update link set visited = visited + 1 where Id = @Id", new { Id = id });
            }

            return(result);
        }
示例#9
0
        public int LinksVisitedCount()
        {
            int total = 0;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                total = conn.QuerySingle <int>("select sum(visited) from link");
            }

            return(total);
        }
示例#10
0
        public IEnumerable <Link> ListLinkByCat(string catid)
        {
            IEnumerable <Link> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT title,id,visited,brief FROM link where catid = @catid ORDER BY visited desc");
                list = conn.Query <Link>(sql, new { catid });
            }

            return(list);
        }
示例#11
0
        public IEnumerable <Link> GetAllLink()
        {
            IEnumerable <Link> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT icon,title,id,linkType FROM link ORDER BY linkType asc,visited desc");
                list = conn.Query <Link>(sql);
            }

            return(list);
        }
示例#12
0
        public LinkCat GetLinkCat(string id)
        {
            var linkCat = new LinkCat();

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format("SELECT * FROM linkcat WHERE Id = @Id");
                linkCat = conn.QueryFirstOrDefault <LinkCat>(sql, new { Id = id });
            }

            return(linkCat);
        }
示例#13
0
        public IEnumerable <LinkCat> LinkCatList()
        {
            IEnumerable <LinkCat> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT id,catname FROM linkcat ORDER BY id desc");
                list = conn.Query <LinkCat>(sql);
            }

            return(list);
        }
示例#14
0
        public IEnumerable <CusLink> ListCusLinkByPaging(int size, int skip, string fields = "*")
        {
            IEnumerable <CusLink> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT {fields} FROM cuslink ORDER BY id desc LIMIT @PageSize OFFSET @Offset");
                list = conn.Query <CusLink>(sql, new { PageSize = size, Offset = skip });
            }

            return(list);
        }
示例#15
0
        public IEnumerable <CusLink> GetTopCusLink(int size, string fields = "*")
        {
            IEnumerable <CusLink> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format("SELECT {0} FROM cuslink ORDER BY id desc LIMIT @size", fields);
                list = conn.Query <CusLink>(sql, new { size });
            }

            return(list);
        }
示例#16
0
        public IEnumerable <Article> ListArticleByPaging(int size, int skip, string fields = "*")
        {
            IEnumerable <Article> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT {fields} FROM article ORDER BY catalog asc,createTime desc LIMIT @PageSize OFFSET @Offset");
                list = conn.Query <Article>(sql, new { PageSize = size, Offset = skip });
            }

            return(list);
        }
示例#17
0
        public Article GetArticle(string id, string fields = "*")
        {
            var article = new Article();

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format("SELECT {0} FROM article WHERE Id = @Id", fields);
                article = conn.QueryFirstOrDefault <Article>(sql, new { Id = id });
            }

            return(article);
        }
示例#18
0
        public Account GetAccount(string id, string fields = "*")
        {
            var account = new Account();

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format("SELECT {0} FROM account WHERE Id = @Id", fields);
                account = conn.QueryFirstOrDefault <Account>(sql, new { Id = id });
            }

            return(account);
        }
示例#19
0
        public Link GetLink(string id, string fields = "*")
        {
            var link = new Link();

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format("SELECT {0} FROM link WHERE Id = @Id", fields);
                link = conn.QueryFirstOrDefault <Link>(sql, new { Id = id });
            }

            return(link);
        }
示例#20
0
        public Account GetLogin(string userid, string password, string fields = "*")
        {
            Account account;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT * FROM account where userid=@userid and password=@password");
                account = conn.QueryFirstOrDefault <Account>(sql, new { userid, password });
            }

            return(account);
        }
示例#21
0
        public IEnumerable <Account> PagerAccountList(int size, int skip, string username, out int total, string fields = "*")
        {
            IEnumerable <Account> list;

            using (IDbConnection conn = SqlHelpers.CreateDbConnection(_connection))
            {
                string sql = string.Format($"SELECT {fields} FROM account ORDER BY id desc LIMIT @PageSize OFFSET @Offset");
                list = conn.Query <Account>(sql, new { PageSize = size, Offset = skip });

                total = conn.QueryFirstOrDefault <int>($"select count(*) FROM account");
            }

            return(list);
        }