22のカテゴリのリストがあり、カテゴリごとに約8つのmenuItemがありますが、ビューモデルはリストの最後のアイテムのみになります。問題がどこにあるのかわからない。
この時点で、問題はビューモデルの設定方法にあると確信していますが、問題がどこにあるのかわかりません。
ViewModels:_
public class MenuViewModel
public List<CategoryViewModel> CategoryList { get; set; }
public class CategoryViewModel
{
public int CategoryID { get; set; }
public string CategoryTitle { get; set; }
public List<MenuItemViewModel> MenuItemList { get; set; }
}
public class MenuItemViewModel
{
public string Title { get; set; }
public string Note { get; set; }
public string Description { get; set; }
public List<PriceViewModel> PriceList { get; set; }
}
public class PriceViewModel
{
public decimal PriceValueRegularLunch { get; set; }
public decimal PriceValueSmallLunch { get; set; }
public decimal PriceValueLargeLunch { get; set; }
public decimal PriceValueRegularDinner { get; set; }
public decimal PriceValueSmallDinner { get; set; }
public decimal PriceValueLargeDinner { get; set; }
public decimal PriceValueRegularTakeOut { get; set; }
public decimal PriceValueSmallTakeOut { get; set; }
public decimal PriceValueLargeTakeOut { get; set; }
}
private MenuViewModel LoadViewModel(int menuNameID)
{
List<Category> returnedCategories = GetAllMenuDataModel.GetAllMenuItemsByCategory(menuNameID);
MenuViewModel vmMenu = new MenuViewModel();
PriceViewModel vmPrices = new PriceViewModel();
foreach (Category category in returnedCategories)
{
CategoryViewModel vmCategory = new CategoryViewModel
{
CategoryID = category.categoryId,
CategoryTitle = category.categoryTitle
};
foreach (MenuItem menuItem in category.MenuItems)
{
MenuItemViewModel vmMenuItem = new MenuItemViewModel
{
Title = menuItem.itemTitle,
Description = menuItem.itemDescription,
Note = menuItem.itemNote
};
foreach (Price price in menuItem.Prices)
{
switch (price.MealType.mealName.ToLower())
{
case "lunch":
if (price.ServingSize.sizeName == "Regular")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Small")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Large")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
break;
case "dinner":
if (price.ServingSize.sizeName == "Regular")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Small")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Large")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
break;
case "takeOut":
if (price.ServingSize.sizeName == "Regular")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Small")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
if (price.ServingSize.sizeName == "Large")
{
vmPrices.PriceValueLargeLunch = price.priceValue;
}
break;
}
vmMenuItem.PriceList = new List<PriceViewModel> { vmPrices };
}
vmCategory.MenuItemList = new List<MenuItemViewModel> { vmMenuItem };
}
vmMenu.CategoryList = new List<CategoryViewModel> { vmCategory };
}
return vmMenu;
}