Exemplo n.º 1
0
        public static bool Register(User user)
        { 
            // TODO: Register log  ekle 
            if (!UserExists(user))
            {
                string query = "Insert into [User](Fullname , Email , Username , Password , RegistrationDate, IsAdmin) Values (@fullname, @email , @username , @password , @registerdate, 0)";
                SqlCommand command = new SqlCommand(query, _connection);
                command.Parameters.AddWithValue("@fullname", user.FullName);
                command.Parameters.AddWithValue("@email", user.Email);
                command.Parameters.AddWithValue("@username", user.Username);
                command.Parameters.AddWithValue("@password", user.Password);
                command.Parameters.AddWithValue("@registerdate", user.RegistrationDate);
                int rowCount = command.ExecuteNonQuery();
                return rowCount != 0; 
            }

            return false;
        }
Exemplo n.º 2
0
 public static bool UserExists(User user)
 {
     string query = "SELECT 1 FROM [User] WHERE Username = @username or Email = @email";
     SqlCommand command = new SqlCommand(query, _connection);
     command.Parameters.AddWithValue("@username", user.Username);
     command.Parameters.AddWithValue("@email", user.Email);
     var results = command.ExecuteScalar();
     return results != null;
 }
Exemplo n.º 3
0
        public static List<User> GetUsers()
        {
            List<User> users = new List<User>();

            string query = "SELECT UserId, FullName, Username, Email, RegistrationDate, IsAdmin FROM dbo.[User]";

            SqlCommand command = new SqlCommand(query, _connection);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    User u = new User() 
                    {
                        UserId = reader.GetGuid(0),
                        FullName = reader.GetString(1),
                        Username = reader.GetString(2),
                        Email = reader.GetString(3),
                        RegistrationDate = reader.GetDateTime(4),
                        IsAdmin = reader.GetBoolean(5)
                    };

                    users.Add(u);
                }
            }

            return users;
        }