Exemplo n.º 1
0
        override public bool signUp(Model.User user, Views.SignUp view) // Sending instance of View to make changes, will return true if successful
        {
            bool insertSuccessul = false;

            connection.Open();

            SqlCommand insertCommand = new SqlCommand(insertStoredProcedure, connection);

            insertCommand.CommandType = System.Data.CommandType.StoredProcedure;

            insertCommand.Parameters.Add(new SqlParameter("@email", user.getEmail()));
            insertCommand.Parameters.Add(new SqlParameter("@status", user.getUserStatus()));
            insertCommand.Parameters.Add(new SqlParameter("@password", user.getPassword()));
            insertCommand.Parameters.Add(new SqlParameter("@firstName", user.getFirstName()));
            insertCommand.Parameters.Add(new SqlParameter("@lastName", user.getLastname()));
            insertCommand.Parameters.Add(new SqlParameter("@mobile", user.getMobileNumber()));

            // creating output parameter
            SqlParameter returnedUserID = insertCommand.Parameters.Add("@userID", System.Data.SqlDbType.UniqueIdentifier, 0, "userID");

            returnedUserID.Direction = System.Data.ParameterDirection.Output;



            try
            {
                if (insertCommand.ExecuteNonQuery() > 0)                              // returns number of rows affected
                {
                    user.setID(insertCommand.Parameters["@userID"].Value.ToString()); // retreiving output value
                    view.signUpSuccessful();
                    view.setWelcomeTitle("Welcome " + user.getFirstName());
                }

                else
                {
                    view.signUpFailed();
                }
            }



            catch (Exception es)
            {
                view.signUpFailed();
            }



            connection.Close();


            return(insertSuccessul);
        }
Exemplo n.º 2
0
        public override void joinApartment(string id, string code, Views.SignUp view)
        {
            List <string> flatsNumbers = new List <string>();
            string        flatQuer     = "SELECT " + TABLE_FLATS.KEY_FLAT_NUMBER + " FROM " + Util.VIEWS.FLATS_VIEW +
                                         " WHERE " + TABLE_FLATS.KEY_APPARTMENT_ID + " = '" + id + "' AND " + TABLE_BUILDING.KEY_CODE + " = '" + code + "'";

            connection.Open();
            using (SqlCommand flatsCommand = new SqlCommand(flatQuer, connection))
            {
                using (SqlDataReader reader = flatsCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        flatsNumbers.Add((reader[0].ToString()));
                    }
                }
            }

            view.joinApartmentSuccessful(flatsNumbers);
        }
Exemplo n.º 3
0
        override public void signIn(Model.User user, Views.SignUp view, string enteredEmail, string enteredPassword, Model.Building apartment)
        {
            bool   passwordMatched = false;
            string selectAllQuery  = "SELECT userID, userFirstName, userLastName, userStatus, userMobileNumber, apartmentID FROM " + TABLE_NAME + " WHERE userEmail = '" + enteredEmail + "'";


            connection.Open();
            string selectQuery = "SELECT password FROM " + TABLE_NAME + " WHERE userEmail = '" + enteredEmail + "'";

            using (SqlCommand command = new SqlCommand(selectQuery, connection)) // getting password against entered email
            {
                using (SqlDataReader dr = command.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        passwordMatched = enteredPassword == Model.User.encodePassword(dr["password"].ToString()); // if password matches
                    }
                    else
                    {
                        view.logInInFailed(false);
                        return;
                    }
                }
            }

            if (passwordMatched)
            {
                using (SqlCommand getUserCommand = new SqlCommand(selectAllQuery, connection))
                {
                    using (SqlDataReader dr2 = getUserCommand.ExecuteReader())
                    {
                        while (dr2.Read())
                        {
                            bool isAdmin;
                            if (dr2["userStatus"].ToString() == "Admin")
                            {
                                isAdmin = true;
                            }

                            else
                            {
                                isAdmin = false;
                            }

                            user.setAllValues(dr2["userID"].ToString(), dr2["userFirstName"].ToString(), dr2["userLastName"].ToString(), enteredEmail, enteredPassword, isAdmin, dr2["userMobileNumber"].ToString());

                            if (dr2["apartmentID"].ToString() != "") // user have already joined/created a building
                            {
                                user.setApartmentID(dr2["apartmentID"].ToString());
                            }

                            else // user have to join or create a building first
                            {
                                view.signUpSuccessful(isAdmin);
                                return;
                            }
                        }
                    }
                }

                if (user.getApartmentID() != null) // getting apartment details
                {
                    string selectApartmentQuery = "SELECT * FROM tbl_Buildings WHERE apartmentID = " + "'" + Guid.Parse(user.getApartmentID()) + "'";
                    using (SqlCommand getApartmentCommand = new SqlCommand(selectApartmentQuery, connection))
                    {
                        using (SqlDataReader apartmentReader = getApartmentCommand.ExecuteReader())
                        {
                            while (apartmentReader.Read())
                            {
                                //  int  l = (Int32)apartmentReader["flatsPerFloor"];
                                apartment.setAllValues(user.getApartmentID(), apartmentReader["apartmentName"].ToString(), (Int32)apartmentReader["numberOfFloors"], (Int32)apartmentReader["flatsPerFloor"], apartmentReader["code"].ToString(), user, 0, (int)apartmentReader["balance"]);
                            }
                        }
                    }

                    connection.Close();
                    this.getAllFlats(apartment);
                    Model.Flat adminFlat = getAdminFlat(apartment, user);
                    //apartment.makeAdmin(adminFlat.getFlatNumber());
                    user.setFlat(adminFlat);
                }

                else
                {
                    apartment = null;
                }

                view.logInSuccessful();
            }

            else // password incorrect
            {
                view.logInInFailed(true);
            }
        }
Exemplo n.º 4
0
 virtual public void createBuilding(Model.Building building, Views.SignUp view, Model.User user, int adminFlat
                                    )
 {
 }
Exemplo n.º 5
0
 virtual public void signIn(Model.User user, Views.SignUp view, string enteredEmail, string enteredPassword, Model.Building apartment)
 {
 }
Exemplo n.º 6
0
 virtual public bool signUp(Model.User user, Views.SignUp view)
 {
     return(false);
 }
Exemplo n.º 7
0
 virtual public void joinApartment(string id, string code, Views.SignUp view)
 {
 }