コード例 #1
0
        public Link Add(Link link)
        {
            using (var connection = connectionFactory.CreateConnection())
            {
                helperService.ExequtePlain(connection,
                                           "INSERT INTO links(UserId, Url, Redirects, CreationDate)" +
                                           "VALUES($userId, $url, 0, CURRENT_TIMESTAMP)",
                                           new Parameter("userId", link.UserId),
                                           new Parameter("url", link.Url));

                link.Id = helperService.GetScalar <long>(connection, "SELECT last_insert_rowid()");
                return(link);
            }
        }
コード例 #2
0
        public User Register(string username, string password)
        {
            using (var connection = connectionFactory.CreateConnection())
            {
                var salt         = CreateSalt();
                var passwordHash = Sha256(Sha256(password) + salt);

                helperService.ExequtePlain(connection,
                                           "INSERT INTO users(Username, Password, Salt, CreationDate)" +
                                           "VALUES($username, $password, $salt, CURRENT_TIMESTAMP)",
                                           new Parameter("username", username),
                                           new Parameter("password", passwordHash),
                                           new Parameter("salt", salt));

                return(new User
                {
                    Id = helperService.GetScalar <long>(connection, "SELECT last_insert_rowid()"),
                    Username = username
                });
            }
        }