private ShopFormViewModel Compose(Shop shop, Dictionary <int, string> categories, List <FoodItemViewModel> foodItems, UserShopRatingInformation rating) { var model = new ShopFormViewModel(); var shopModel = new ShopInformation(); PropertyCopier <Shop, ShopInformation> .Copy(shop, shopModel); model.Info = shopModel; model.UserRating = rating; model.FoodItems = GetFoodItemsPerCategory(categories, foodItems); return(model); }
private ShopFormViewModel ComposeToShopFormEntity(MySqlDataReader reader, bool allowRating) { var shop = new Shop(); var categories = new List <FoodItemCategories>(); var shopCategoriesWithAliases = new List <ShopFoodItemCategories>(); var shopRating = new UserShopRatingInformation(); shopRating.isAllowed = allowRating; while (reader.Read()) { shop = CreateInstance <Shop>(reader); } reader.NextResult(); var ingredients = GetIngredients(reader).ToList(); reader.NextResult(); var foodItems = GetFoodItems(reader, ingredients).ToList(); reader.NextResult(); while (reader.Read()) { var category = CreateInstance <FoodItemCategories>(reader); categories.Add(category); } reader.NextResult(); while (reader.Read()) { var shopCategory = CreateInstance <ShopFoodItemCategories>(reader); shopCategoriesWithAliases.Add(shopCategory); } if (allowRating) { reader.NextResult(); while (reader.Read()) { var userRating = CreateInstance <ShopRatings>(reader); if (Enum.IsDefined(typeof(Rating), userRating.Rating)) { shopRating.StarRating = (Rating)userRating.Rating; } else { shopRating.StarRating = Rating.None; } } } var shopCategoriesActual = new Dictionary <int, string>(); foreach (var category in categories) { var alias = shopCategoriesWithAliases.Where(x => x.CategoryId == category.CategoryId).Select(y => y.CategoryAlias).FirstOrDefault(); if (alias != null && alias != string.Empty) { category.FoodType = alias; } shopCategoriesActual.Add(category.CategoryId, category.FoodType); } return(Compose(shop, shopCategoriesActual, foodItems.ToList(), shopRating)); }