コード例 #1
0
        /// <summary>
        /// 保存一条数据
        /// </summary>
        public void SaveData <T>(T dbObj, object keyValue) where T : class
        {
            Type   type      = typeof(T);
            string tableName = type.Name;
            string keyName   = _keyMap[type];

            if (_autoBox.SelectCount(string.Format("from {0} where {1} == ?", tableName, keyName), keyValue) <= 0)
            {
                _autoBox.Insert(tableName, dbObj);
            }
            else
            {
                _autoBox.Update(tableName, dbObj);
            }
        }
コード例 #2
0
        public LoginCommandResult Execute(LoginCommand loginCommand)
        {
            var hashedPassword = Hasher.GetMd5Hash(loginCommand.Password);

            if (_db.SelectCount("from " + DBTableNames.Authors) == 0)
            {
                _db.Insert(DBTableNames.Authors, new Author
                {
                    Email          = "*****@*****.**",
                    DisplayName    = "mzblog",
                    Roles          = new[] { "admin" },
                    HashedPassword = Hasher.GetMd5Hash("mzblog")
                });
            }
            var author = from u in _db.Select <Author>("from " + DBTableNames.Authors)
                         where u.Email == loginCommand.Email && u.HashedPassword == hashedPassword
                         select u;

            if (author.Count() > 0)
            {
                return new LoginCommandResult()
                       {
                           Author = author.FirstOrDefault()
                       }
            }
            ;

            return(new LoginCommandResult(trrorMessage: "用户名或密码不正确")
            {
            });
        }
    }
コード例 #3
0
        public AllStatisticsViewModel Project(AllStatisticsBindingModel input)
        {
            var postCount = _db.SelectCount("from " + DBTableNames.BlogPosts);

            if (postCount == 0)
            {
                return(new AllStatisticsViewModel());
            }

            var stat = new AllStatisticsViewModel
            {
                PostsCount    = postCount,
                CommentsCount = _db.SelectCount("from " + DBTableNames.BlogComments)
            };

            stat.TagsCount = (int)_db.SelectCount("from " + DBTableNames.Tags);

            return(stat);
        }