Ejemplo n.º 1
0
        public bool AddUser(CruizeUser user)
        {
            user.Password = PasswordHash(user.Email, user.Password);

            if (user.Email.Contains("@easj.dk") || user.Email.Contains("@edu.easj.dk") ||
                user.Email.Contains("@zealand.dk"))
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    using (SqlCommand sql = new SqlCommand(AddUserSQL, connection))
                    {
                        sql.Parameters.AddWithValue("@FN", user.FirstName);
                        sql.Parameters.AddWithValue("@LN", user.LastName);
                        sql.Parameters.AddWithValue("@E", user.Email);
                        sql.Parameters.AddWithValue("@P", user.Password);
                        sql.Parameters.AddWithValue("@AD", user.Address);
                        sql.Parameters.AddWithValue("@ZC", user.Zipcode);

                        int rows = sql.ExecuteNonQuery();

                        if (rows == 1)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public List <CruizeUser> GetAllUsers()
        {
            List <CruizeUser> liste = new List <CruizeUser>();

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                using (SqlCommand sql = new SqlCommand("select * from CruizeUser", conn))
                {
                    SqlDataReader reader = sql.ExecuteReader();
                    while (reader.Read())
                    {
                        CruizeUser u = new CruizeUser();
                        u.UserId    = reader.GetInt32(0);
                        u.FirstName = reader.GetString(1);
                        u.LastName  = reader.GetString(2);
                        u.Password  = reader.GetString(3);
                        u.Email     = reader.GetString(4);
                        u.Address   = reader.GetString(5);
                        u.Zipcode   = reader.GetInt32(6);
                        liste.Add(u);
                    }
                }
            }
            return(liste);
        }
        public void OnPost()
        {
            List <CruizeUser> users     = _userService.GetAllUsers();
            string            userEmail = Request.Form["Email".ToLower()];
            bool userStatus             = false;

            foreach (BannedUser bannedUser in _reportService.BannedUsers())
            {
                if (userEmail == bannedUser.BannedEmail)
                {
                    EmailError = "This user has been banned from the application";
                    return;
                }
            }

            if (ModelState.IsValid)
            {
                if (!userEmail.Contains("@easj.dk") && !userEmail.Contains("@edu.easj.dk") && !userEmail.Contains("@zealand.dk"))
                {
                    EmailError = "You have to use a Zealand email";
                    return;
                }
                foreach (CruizeUser Cruizer in users)
                {
                    if (Cruizer.Email.ToLower() == Request.Form["Email".ToLower()])
                    {
                        EmailError = "A user with this email already exists";
                        return;
                    }
                }
                if (Request.Form["userStatus"] == "driver")
                {
                    userStatus = true;
                }
            }

            CruizeUser cruizer = new CruizeUser();

            cruizer.FirstName = Request.Form["First Name"];
            cruizer.LastName  = Request.Form["Last Name"];
            cruizer.Address   = Request.Form["Address"];
            cruizer.Email     = Request.Form["Email"];
            cruizer.Password  = Request.Form["Password"];
            cruizer.Zipcode   = Convert.ToInt32(Request.Form["Zipcode"]);

            _userService.AddUser(cruizer);
            SuccesCreate = "You have been created as a user";

            if (userStatus == true)
            {
                _userService.AddDriver(cruizer);
            }
        }
Ejemplo n.º 4
0
        public void BeforeTest()
        {
            service = new UserService();

            user = new CruizeUser
            {
                FirstName = "Carl",
                LastName  = "Schwennesen",
                Address   = "CarlSchwennesenvej 3",
                Email     = "*****@*****.**",
                Password  = "******",
                Zipcode   = 2300
            };
        }
Ejemplo n.º 5
0
        private CruizeUser MakeUser(SqlDataReader reader)
        {
            CruizeUser user = new CruizeUser
            {
                UserId    = Convert.ToInt32(reader["UserID"]),
                FirstName = Convert.ToString(reader["FirstName"]),
                LastName  = Convert.ToString(reader["LastName"]),
                Email     = Convert.ToString(reader["Email"]),
                Password  = Convert.ToString(reader["Password"]),
                Address   = Convert.ToString(reader["Address"]),
                Zipcode   = Convert.ToInt32(reader["ZipCode"]),
            };

            return(user);
        }
Ejemplo n.º 6
0
        public bool AddDriver(CruizeUser user)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                using (SqlCommand sql = new SqlCommand(AddDriverSQL, connection))
                {
                    sql.Parameters.AddWithValue("@UID", GetUserId(user.Email));

                    int rows = sql.ExecuteNonQuery();

                    if (rows == 1)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public List <CruizeUser> GetAllPassengerUsers(int routeid)
        {
            List <CruizeUser> pliste = new List <CruizeUser>();


            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                using (SqlCommand sql = new SqlCommand("SELECT * FROM Passenger WHERE RouteID = @RID", conn))
                {
                    sql.Parameters.AddWithValue("@RID", routeid);
                    SqlDataReader reader = sql.ExecuteReader();
                    while (reader.Read())
                    {
                        int        userid = Convert.ToInt32(reader["UserID"]);
                        CruizeUser p      = _userService.GetOneUser(userid);
                        pliste.Add(p);
                    }
                }
            }
            return(pliste);
        }
Ejemplo n.º 8
0
 public void BeforeTest()
 {
     user = new CruizeUser();
 }
Ejemplo n.º 9
0
        public CruizeUser GetReportedUser(int id)
        {
            CruizeUser reportedUser = _userService.GetOneUser(id);

            return(reportedUser);
        }
Ejemplo n.º 10
0
 public bool UpdateUser(int id, CruizeUser user)
 {
     throw new NotImplementedException();
 }