示例#1
0
	void SendInfoAsJson(RSOResponse response)
	{
		string strJson = JsonConvert.SerializeObject(response);
		Response.ContentType = "application/json; charset=utf-8";
		Response.Write(strJson);
		Response.End();
	}
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        RSORequest  request;
        RSOResponse response = new RSOResponse();

        response.error = String.Empty;

        // 1. Deserialize the incoming Json.
        try
        {
            request = GetRequestInfo();
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();

            // Return the results as Json.
            SendInfoAsJson(response);

            return;
        }

        // Do stuff here.
        //Retrieve all Student Organizations at this student's university
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        try
        {
            connection.Open();

            response.rsos = new List <string>();
            string     sql     = String.Format("SELECT * FROM StudentOrg WHERE uniID=@un");
            SqlCommand command = new SqlCommand(sql, connection);
            command.Parameters.Add(new SqlParameter("@un", request.uniID));
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                response.rsos.Add(Convert.ToString(reader["name"]));
            }
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        SendInfoAsJson(response);
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        RSORequest  request;
        RSOResponse response   = new RSOResponse();
        User        idStorage  = new User();
        int         rsoID      = -1;
        string      adminEmail = String.Empty;

        response.error = String.Empty;

        // Need passed in store id and number of requested results.
        // 1. Deserialize the incoming Json.
        try
        {
            request = GetRequestInfo();
            if (request.name == null || request.description == null || request.member1 == null || request.member2 == null ||
                request.member3 == null || request.member4 == null || request.member5 == null)
            {
                response.error = "RSO not created";
                SendInfoAsJson(response);

                return;
            }
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();

            // Return the results as Json.
            SendInfoAsJson(response);

            return;
        }

        // Do stuff here.
        //Ensure the Student Organization isn't already taken
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        try
        {
            connection.Open();

            string     sql     = String.Format("SELECT * FROM StudentOrg WHERE name=@so AND uniID=@un");
            SqlCommand command = new SqlCommand(sql, connection);
            command.Parameters.Add(new SqlParameter("@so", request.name));
            command.Parameters.Add(new SqlParameter("@un", request.uniID));
            SqlDataReader reader = command.ExecuteReader();
            if (reader.Read())
            {
                response.error = "1";
            }

            if (response.error != "")
            {
                SendInfoAsJson(response);
                return;
            }
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        //Retrieve the student IDs based on the e-mails provided
        try
        {
            connection.Open();

            string     sql      = String.Format("SELECT * FROM EventUser WHERE email=@e1 OR email=@e2 OR email=@e3 OR email=@e4 OR email=@e5 OR userID=@ui AND uniID=@un");
            SqlCommand command2 = new SqlCommand(sql, connection);
            command2.Parameters.Add(new SqlParameter("@e1", request.member1));
            command2.Parameters.Add(new SqlParameter("@e2", request.member2));
            command2.Parameters.Add(new SqlParameter("@e3", request.member3));
            command2.Parameters.Add(new SqlParameter("@e4", request.member4));
            command2.Parameters.Add(new SqlParameter("@e5", request.member5));
            command2.Parameters.Add(new SqlParameter("@ui", request.admin));
            command2.Parameters.Add(new SqlParameter("@un", request.uniID));
            SqlDataReader reader2 = command2.ExecuteReader();
            while (reader2.Read())
            {
                string matchEmail;
                int    thisID;
                matchEmail = Convert.ToString(reader2["email"]);
                thisID     = Convert.ToInt32(reader2["userID"]);
                if (matchEmail.Equals(request.member1))
                {
                    idStorage.member1ID = thisID;
                }
                else if (matchEmail.Equals(request.member2))
                {
                    idStorage.member2ID = thisID;
                }
                else if (matchEmail.Equals(request.member3))
                {
                    idStorage.member3ID = thisID;
                }
                else if (matchEmail.Equals(request.member4))
                {
                    idStorage.member4ID = thisID;
                }
                else if (matchEmail.Equals(request.member5))
                {
                    idStorage.member5ID = thisID;
                }
                else if (request.admin == thisID)
                {
                    adminEmail = matchEmail;
                }
            }
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }


        //Create the student organization in the database
        try
        {
            connection.Open();

            string     sql      = String.Format("INSERT into StudentOrg (name, description, admin, uniID) VALUES ('{0}','{1}','{2}', '{3}')", request.name, request.description, request.admin, request.uniID);
            SqlCommand command3 = new SqlCommand(sql, connection);
            command3.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        //Retrieve what ID we gave the RSO
        try
        {
            connection.Open();

            string     sql      = String.Format("SELECT * FROM StudentOrg WHERE name=@on AND uniID=@un");
            SqlCommand command5 = new SqlCommand(sql, connection);
            command5.Parameters.Add(new SqlParameter("@on", request.name));
            command5.Parameters.Add(new SqlParameter("@un", request.uniID));
            SqlDataReader reader5 = command5.ExecuteReader();
            if (reader5.Read())
            {
                rsoID = Convert.ToInt32(reader5["rsoID"]);
            }
            else
            {
                response.error = "Failed to retrieve Student Organization id.";
            }
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        //Assign the students to the rso
        try
        {
            connection.Open();

            string sql = String.Format("INSERT into rsoToUsers (rsoID, userID, groupMember, userEmail) VALUES ('{0}', '{1}', '{2}', '{3}'), ('{4}', '{5}', '{6}', '{7}'), ('{8}', '{9}', '{10}', '{11}'), ('{12}', '{13}', '{14}', '{15}'), ('{16}', '{17}', '{18}', '{19}'), ('{20}', '{21}', '{22}', '{23}')", rsoID, request.admin, 1, adminEmail, rsoID, idStorage.member1ID, 1, request.member1, rsoID, idStorage.member2ID, 1, request.member2, rsoID, idStorage.member3ID, 1, request.member3, rsoID, idStorage.member4ID, 1, request.member4,
                                       rsoID, idStorage.member5ID, 1, request.member5);
            SqlCommand command6 = new SqlCommand(sql, connection);
            command6.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            response.error = ex.Message.ToString();
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }

        response.message = "Successfully registered Student Organization!";

        SendInfoAsJson(response);
    }
示例#4
0
	protected void Page_Load(object sender, EventArgs e)
	{
		RSORequest request;
		RSOResponse response = new RSOResponse();
		string email = String.Empty;
		int rsoID = -1;
		response.error = String.Empty;

		// Need passed in store id and number of requested results.
		// 1. Deserialize the incoming Json.
		try
		{
			request = GetRequestInfo();
		}
		catch (Exception ex)
		{
			response.error = ex.Message.ToString();

			// Return the results as Json.
			SendInfoAsJson(response);

			return;
		}

		// Do stuff here.
		//Get the User's email
		SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
		try
		{
			connection.Open();
			
			string sql = String.Format("SELECT * FROM EventUser WHERE userID=@un");
			SqlCommand command = new SqlCommand( sql, connection );
			command.Parameters.Add(new SqlParameter("@un", request.userID));
			SqlDataReader reader = command.ExecuteReader();
			if( reader.Read() )
			{
				email = Convert.ToString( reader["email"] );
			}
			
			if( response.error != "")
			{
				SendInfoAsJson(response);
				return;
			}
		}
		catch (Exception ex)
		{
			response.error = ex.Message.ToString();
		}
		finally
		{
			if (connection.State == ConnectionState.Open)
			{
				connection.Close();
			}
		}

		//Get the rso's ID
		try
		{
			connection.Open();
			
			string sql = String.Format("SELECT * FROM StudentOrg WHERE name=@rs");
			SqlCommand command2 = new SqlCommand( sql, connection );
			command2.Parameters.Add(new SqlParameter("@rs", request.rsoName));
			SqlDataReader reader2 = command2.ExecuteReader();
			if( reader2.Read() )
			{
				rsoID = Convert.ToInt32( reader2["rsoID"] );
			}
			
			if( response.error != "")
			{
				SendInfoAsJson(response);
				return;
			}
		}
		catch (Exception ex)
		{
			response.error = ex.Message.ToString();
		}
		finally
		{
			if (connection.State == ConnectionState.Open)
			{
				connection.Close();
			}
		}

		//Add this user to the rsoToUsers table but not as a full member yet
		try
		{
			connection.Open();
			
			string sql = String.Format("INSERT into rsoToUsers (rsoID, userID, groupMember, userEmail) VALUES ('{0}', '{1}', '{2}', '{3}')", rsoID, request.userID, 0, email);
			SqlCommand command3 = new SqlCommand( sql, connection );
			command3.ExecuteNonQuery();
		}
		catch (Exception ex)
		{
			response.error = ex.Message.ToString();
		}
		finally
		{
			if (connection.State == ConnectionState.Open)
			{
				connection.Close();
			}
		}
		
		response.message = "Request sent!";
		
		SendInfoAsJson(response);
	}