Shari_1 0 Newbie Poster

Hello. I'm having some troubles with my code and was just wondering if you could give me a hand.

I'm working on a MVC project using data access layer (DAL, BLL, Model). So, I want to list some categories. When I click on a category, I want to list all the items related to that category. That's where my problem starts, I can list the categories, but I'm having troubles listing the items within the selected category. I was wondering if anyone could help me solving this issue?

Here's my code:

// From my MODEL project
public class Item {
    public int itemID {get; set;}
    public string itemName {get; set;}
    public string catName {get; set;}
}

public class Category {
    public int catID {get; set;}
    public string catName {get; set;}
}



// From my database model (DBModel) in DAL project
public class DbItem {
    public int itemID {get; set;}
    public string itemName {get; set;}

    public virtual DbCategory category {get; set;}
}

public class DbCategory {
    public int catID {get; set;}
    public string catName {get; set;}

    public List<Item> items {get; set;}
}



// My ItemDAL class in DAL project
public List<Item> GetItems(string category) {
    using (var db = new databaseContext()) {
        List<Item> items = (from i in db.Items
                            where i.category.equals(category)
                            select new Item() {
                               // some code
                            }).ToList();
        return items;
    }
}



// From my BLL project
public List<Item> GetItems(string category) {
    List<Item> items = itemDAL.GetItems(category);
    return items;
}



// From my Item controller
public ActionResult ListItems(string category) {
    List<Item> items = itemBLL.GetItems(category);
    return View(items);
}



// My VIEW page
// top of the page
@model Project.DAL.DbCategory

// using for loop to list the items. 

I know there's a lot of mistakes. I'm not supposed to return a list of items when using @Model Project.DAL.DbCategory, but I'm not making it work. In my DAL class, the comparation between i.category won't compare with the category parameter. I'm not able to figure out the logic here, I want a list of items, but I can only list these items using @model Project.DAL.DbCategory since DbCategory does have a List<Item> variable.

Does anyone see how I can solve this problem?

This example is inspired by the MusicStore MVC Project out online, but trying to use DAL, BLL and Model. I previously used:

public ActionResult ListItems(string category)
{
        var itemList = db.Categories.Include("Items").Single(k => k.catName == category);
        return View(itemList);
}

But I can't access the database using the controller, I have to use DLL!

Edit: I just found out that the last code I put returns ONE category but with all the products inside. Is there someway I can write that line with one of my methods above?