How to pass a class into another class to a codebehind?
When I debug and check the myCategoryObj in the Default.aspx page, I can see the object is in the debug. What am I doing wrong?
I know I could create the object in the Default.aspx but I should not have to I should be able to call the Business Logic Layer and ask for an object back and then fill the object and pass it back to the Business Logic Layer to be saved (insert or update).
I hope this makes sense.
Default.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SC1.Models.OBJ;
using SC1.Models.BLL;
using SC1.Models.DAL;
namespace SC1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(Object sender, EventArgs e)
{
// I know I could do this but I don't want to unless I have too.
//Category categoryObj = new Category();
CategoryBLL myCategoryBLL = new CategoryBLL();
Object myCategoryObj = myCategoryBLL.CategoryNew();
// How do I make the code below work or what am I doing wrong.
myCategoryObj.Name = "test";
string test = "";
}
}
}
CategoryBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using SC1.Models.DAL;
using SC1.Models.OBJ;
namespace SC1.Models.BLL
{
public class CategoryBLL
{
// Create a page object
Category myCategoryObject = new Category();
// Create a Data Acces Layer Object
CategoryDAL myCategoryDAL = new CategoryDAL();
public CategoryBLL()
{
}
public DataSet Select()
{
return (myCategoryDAL.Select());
}
public Object CategoryNew()
{
return myCategoryObject;
}
}
}
CategoryDAL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace SC1.Models.DAL
{
public class CategoryDAL
{
public CategoryDAL()
{
}
string connStr = ConfigurationManager.ConnectionStrings["staceys_cakesConnectionString"].ConnectionString;
// select all
public DataSet Select()
{
SqlConnection sqlConnection1 = new SqlConnection();
string SqlString = "select * from Categories";
SqlDataAdapter da = new SqlDataAdapter(SqlString, connStr);
DataSet ds = new DataSet();
da.Fill(ds, "Categories");
return (ds);
}
// save
// insert
// update
// delete
}
}
Category.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace SC1.Models.OBJ
{
public class Category
{
public int CategoryID { get; set; }
public int ParentID { get; set; }
public string Name { get; set; }
public int DisplayOrder { get; set; }
public bool Active { get; set; }
public Category(){
}
}
}