public GetRestaurantById ( string id, string lang = DefaultLang ) : |
||
id | string | |
lang | string | |
return |
public static IEnumerable<RestaurantModel> CalculateHealthState(this IEnumerable<RestaurantModel> restaurants) { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); int green, yellow, red; green = yellow = red = 0; if (restaurants != null) { foreach (RestaurantModel rest in restaurants) { if (rest != null) { var tempRest = m_serviceLayer.GetRestaurantById(rest.Id); if(tempRest.Menu.MenuParts != null) { foreach (MenuPartModel menuPart in tempRest.Menu.MenuParts) { if (menuPart.Dishes != null && menuPart.Dishes.Count > 0) foreach (DishModel dish in menuPart.Dishes) { if (dish.NutritionFacts.TotalCarbohydrate < 20){ green++; } else { if (dish.NutritionFacts.TotalCarbohydrate < 40) { yellow++; } else { red++; } } } } } } int max = Math.Max(green, Math.Max(yellow, red)); if (max == red) rest.CarbsLevel = 0; if (max == yellow) rest.CarbsLevel = 1; if (max == green) rest.CarbsLevel = 2; green = yellow = red = 0; } } return restaurants; }
public static MealViewModel ToMealViewModel(this Meal meal) { MealViewModel returnvalue = null; if (meal != null) { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); var restaurnat = m_serviceLayer.GetRestaurantById(meal.RestaurantId); if (restaurnat != null) { List<DishModel> dishes = new List<DishModel>(); List<PortionModel> portionsModel = new List<PortionModel>(); if (meal.Portions != null) { foreach (var dish in meal.Portions) { DishModel dishVM = dish.PrtionFrom.ToDishModel(restaurnat.Id, dish.MenuPartId); dishes.Add(dishVM); PortionModel portion = dish.ToPortionModel(restaurnat.Id, dish.MenuPartId); portionsModel.Add(portion); } } returnvalue = new MealViewModel() { CreatedAt = meal.CreatedAt, RestaurantId = restaurnat.Id, RestaurantName = restaurnat.Name, City = restaurnat.Adress.City, Street = restaurnat.Adress.Street, Dishes = dishes, Portions = portionsModel }; if (meal.CarbAmount != null) returnvalue.CarbAmount = meal.CarbAmount; } } return returnvalue; }
public static Meal ToMeal(this List<PortionModel> portionsModel) { Meal returnvalue = null; if (portionsModel != null) { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); var restaurnat = m_serviceLayer.GetRestaurantById(portionsModel[0].PortionFrom.RestaurantId); if (restaurnat != null) { double totalCarbs = 0; List<Portion> portions = new List<Portion>(); foreach (var portionModel in portionsModel) { Portion portion = portionModel.ToPortion(); portions.Add(portion); totalCarbs += portionModel.CarbAmount; } returnvalue = new Meal() { CreatedAt = DateTime.UtcNow, RestaurantId = restaurnat.Id, Name = restaurnat.Name, Portions = portions, CarbAmount = totalCarbs }; } } return returnvalue; }
public static CouponTypeModel ToCouponTypeModel(this CouponType coupon) { try { log.InfoFormat("[ToCouponTypeModel] coupon.Id={0}, coupon.Description={1}.", coupon.Id.ToString(), coupon.Description); IServicesLayer m_serviceLayer = new ServiceLayerImpl(); CouponTypeModel returnValue = new CouponTypeModel() { Id = coupon.Id.ToString(), Description = coupon.Description, ValidFrom = coupon.ValidFrom, ValidUntil = coupon.ValidUntil }; if (coupon.RestaurantsIDs != null && coupon.RestaurantsIDs.Count > 0) { returnValue.RestaurantID = coupon.RestaurantsIDs[0].ToString(); var tempRest = m_serviceLayer.GetRestaurantById(returnValue.RestaurantID); if (tempRest != null) returnValue.LogoUrl = (tempRest.LocalUrl != null) ? tempRest.LocalUrl : tempRest.LogoUrl; //returnValue.LogoUrl = "/Restaurant/GetImage/" + returnValue.RestaurantID; } if (coupon.LocationsList != null && coupon.LocationsList.Count > 0) { returnValue.Location = new LocationModel(coupon.LocationsList[0]); } else { returnValue.Location = new LocationModel(0, 0); if (returnValue.Description.IndexOf("Nelly's Kitchen") > 0) returnValue.Location = new LocationModel(32.051, 34.755); if (returnValue.Description.IndexOf("BG99") > 0) returnValue.Location = new LocationModel(32.016652, 34.738724); if (returnValue.Description.IndexOf("קולומבוס") > 0) returnValue.Location = new LocationModel(32.161, 34.81); if (returnValue.Description.IndexOf("Red Burger Bar") > 0) returnValue.Location = new LocationModel(32.33, 34.85); if (returnValue.Description.IndexOf("Palamida") > 0) returnValue.Location = new LocationModel(32.084638, 34.803035); } return returnValue; } catch (Exception e) { log.ErrorFormat("[ToCouponTypeModel] Exception={0}.", e.ToString()); return null; } }