示例#1
0
        public void Seed()
        {
            using (var connection = dataConnectionFactory.CreateConnection())
            {
                connection.Open();

                if (!helperService.IsTableExists(connection, "links"))
                {
                    helperService.ExequtePlain(connection,
                                               "CREATE TABLE links (" +
                                               "UserId INT," +
                                               "Url TEXT," +
                                               "Redirects INT," +
                                               "CreationDate INT" +
                                               ")");
                }

                if (!helperService.IsTableExists(connection, "users"))
                {
                    helperService.ExequtePlain(connection,
                                               "CREATE TABLE users (" +
                                               "Username TEXT UNIQUE," +
                                               "Password TEXT," +
                                               "Salt TEXT," +
                                               "CreationDate INT" +
                                               ")");
                }
            }
        }
示例#2
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);
            }
        }
示例#3
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
                });
            }
        }