public bool Evaluate( CustomBentoBox customBentoBox ) { double inspectionResult; switch (InspectionType) { case InspectorType.DishTypeIncluded : return customBentoBox.CustomBentoBoxItems.Select(i => i.Dish).Count(i => i.DishTypeId == QueryPredicate) > 0; case InspectorType.DishTypeNotIncluded : return customBentoBox.CustomBentoBoxItems.Select(i => i.Dish).Count(i => i.DishTypeId == QueryPredicate) == 0; case InspectorType.DishIncluded: return customBentoBox.CustomBentoBoxItems.Select(i => i.Dish).Count(i => i.DishId == QueryPredicate) > 0; case InspectorType.DishNotIncluded: return customBentoBox.CustomBentoBoxItems.Select(i => i.Dish).Count(i => i.DishId == QueryPredicate) == 0; case InspectorType.CountOfDishType: inspectionResult = customBentoBox.CustomBentoBoxItems.Select(i => i.Dish).Count(i => i.DishTypeId == QueryPredicate || QueryPredicate == 0); break; default: return false; } switch (ComparisonLogicalOperator) { case LogicalOperator.LessThan: return inspectionResult < CompareToValue; case LogicalOperator.LessThanOrEqualTo: return inspectionResult <= CompareToValue; case LogicalOperator.EqualTo: return inspectionResult == CompareToValue; case LogicalOperator.GreaterThan: return inspectionResult > CompareToValue; case LogicalOperator.GreaterThanOrEqualTo: return inspectionResult >= CompareToValue; default: return false; } }
public void ProcessRule(CustomBentoBox customBentoBox) { Errors = new List<string>(); ErrorOperators = new List<LogicalOperator>(); foreach (var warningRule in WarningRepository.WarningRules[customBentoBox.BentoBox.BentoBoxType]) { if (!warningRule.Evaluate(customBentoBox)) { Errors.Add(warningRule.Message); ErrorOperators.Add(warningRule.ComparisonLogicalOperator); } } }
public ActionResult AddToCart(FormCollection values) { int customBentoBoxId = Convert.ToInt32( values["customBentoBoxId"] ); string encodedRecipe = values["recipe"]; string customBentoBoxName = values["customBentoBoxName"]; CustomBentoBox customBentoBox; if (customBentoBoxId == 0) { customBentoBox = new CustomBentoBox(); var recipe = CustomBentoBox.DecodeRecipe(encodedRecipe); customBentoBox.BentoBoxId = recipe.BentoBoxId; customBentoBox.CustomBentoBoxName = customBentoBoxName; customBentoBox.AddToCustomBentoBox(recipe.DishIds); db.CustomBentoBoxes.AddObject(customBentoBox); db.SaveChanges(); } else { customBentoBox = db.CustomBentoBoxes.Single(i => i.CustomBentoBoxId == customBentoBoxId); if (customBentoBox != null) { var recipe = CustomBentoBox.DecodeRecipe(encodedRecipe); customBentoBox.ReplaceRecipe(recipe.DishIds); } else { return HttpNotFound(); } } if (ModelState.IsValid) { var shoppingCart = ShoppingCartHelper.GetCart(HttpContext); shoppingCart.AddToCart( customBentoBox); return RedirectToAction("Edit", "ShoppingCart"); } return RedirectToAction("Create"); }
public ActionResult AddToCurrentBox(string encodedRecipe, int dishId) { // Retrieve the album from the database var addedDish = db.Dishes.Single(i => i.DishId == dishId); // Add it to the shopping cart var customBentoBox = new CustomBentoBox(encodedRecipe); var isAdded = customBentoBox.AddToCustomBentoBox(addedDish); var processor = new Processor(); processor.ProcessRule(customBentoBox); if (!processor.CanAddDish) { // need to remove the current dish! customBentoBox.RemoveFromCustomBentoBox(addedDish); } if (isAdded == false) { processor.AddDuplicationMessage(); } var mainCourses = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.MainCourse select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var sideDishes = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.SideDish select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var others = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.Drink select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var warningMsg = processor.Errors; encodedRecipe = customBentoBox.EncodedRecipe; var unitPrice = customBentoBox.BentoBox.UnitPrice +customBentoBox.CustomBentoBoxItems.Sum(i => i.Dish.DishIncrementalPrice * i.Quantity); return Json(new { encodedRecipe = encodedRecipe, currentItems = new { mainCourses = new { dishes = mainCourses, count = customBentoBox.BentoBox.NumOfEntree } , sideDishes = new { dishes = sideDishes, count = 1 } , others = new { dishes = others, count = 1 } }, warningMsg = warningMsg , isValid = isAdded && processor.CanAddDish, unitPrice = unitPrice }); }
public ActionResult RemoveFromCurrentBox(string encodedRecipe, int dishId) { // Retrieve the album from the database var removedDish = db.Dishes.Single(i => i.DishId == dishId); // Add it to the shopping cart var customBentoBox = new CustomBentoBox(encodedRecipe); customBentoBox.RemoveFromCustomBentoBox(removedDish); var processor = new Processor(); processor.ProcessRule(customBentoBox); var mainCourses = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.MainCourse select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var sideDishes = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.SideDish select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var others = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.Drink select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var unitPrice = customBentoBox.BentoBox.UnitPrice + customBentoBox.CustomBentoBoxItems.Sum(i => i.Dish.DishIncrementalPrice * i.Quantity); var warningMsg = processor.Errors; encodedRecipe = customBentoBox.EncodedRecipe; return Json(new { encodedRecipe = encodedRecipe, currentItems = new { mainCourses = mainCourses, sideDishes = sideDishes, others = others }, warningMsg = warningMsg, unitPrice = unitPrice }); }
public ActionResult IsBentoBoxErrorFree(string encodedRecipe) { CustomBentoBox customBentoBox = new CustomBentoBox(encodedRecipe); // check if error free var processor = new Processor(); processor.ProcessRule(customBentoBox); var mainCourses = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.MainCourse select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var sideDishes = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.SideDish select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var others = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.Drink select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var warningMsg = processor.Errors; encodedRecipe = customBentoBox.EncodedRecipe; var unitPrice = customBentoBox.BentoBox.UnitPrice + customBentoBox.CustomBentoBoxItems.Sum(i => i.Dish.DishIncrementalPrice * i.Quantity); return Json(new { encodedRecipe = encodedRecipe, currentItems = new { mainCourses = new { dishes = mainCourses, count = customBentoBox.BentoBox.NumOfEntree }, sideDishes = new { dishes = sideDishes, count = 1 }, others = new { dishes = others, count = 1 } }, warningMsg = warningMsg, isValid = processor.Errors.Count == 0, unitPrice = unitPrice }); }
public ActionResult Create(CustomBentoBox custombentobox) { if (ModelState.IsValid) { var shoppingCart = ShoppingCartHelper.GetCart(this); shoppingCart.AddToCart(custombentobox); db.SaveChanges(); return RedirectToAction("Edit", "ShoppingCart"); } ViewBag.BentoBoxId = new SelectList(db.BentoBoxes, "BentoBoxId", "BentoBoxName", custombentobox.BentoBoxId); return View(custombentobox); }
// // GET: /CustomBentoBox/Create public ActionResult Create(int customBentoBoxId = 0, int bentoBoxId = 1) { SiteMenuHelper.Instance.CurrentSiteMenu = SiteMenu.Create; CustomBentoBox customBentoBox; if (customBentoBoxId == 0) { customBentoBox = new CustomBentoBox() { BentoBoxId = bentoBoxId, CustomBentoBoxName = "", BentoBox = db.BentoBoxes.Single(i=>i.BentoBoxId == bentoBoxId) }; } else { customBentoBox = db.CustomBentoBoxes.Single(i => i.CustomBentoBoxId == customBentoBoxId); ViewData["recipe"] = customBentoBox.EncodedRecipe; } var bentoBoxType = db.BentoBoxes.Single(i => i.BentoBoxId == customBentoBox.BentoBoxId); var bentoBoxViewModel = new CustomBentoBoxViewModel(); bentoBoxViewModel.RestaurantName = customBentoBox.BentoBox.Restaurant.RestaurantName; bentoBoxViewModel.CurrentCustomBentoBox = customBentoBox; bentoBoxViewModel.AvailableDishes = new Dictionary<DishType, List<Dish>>(); var availableDishTypes = CustomBentoBoxHelper.BentoBoxTypeDishTypeMappings[bentoBoxType.BentoBoxType]; foreach (var dishType in availableDishTypes) { bentoBoxViewModel.AvailableDishes.Add(dishType, db.Dishes.Where(i => i.DishTypeId == (int)dishType && i.DishStatusId == (int)DishStatusLevel.Available && i.RestaurantId == customBentoBox.BentoBox.RestaurantId).ToList()); } return View(bentoBoxViewModel); }
public ActionResult ChangeQuantity(string encodedRecipe, int dishId, int dishQuantity) { var dish = db.Dishes.Single(i => i.DishId == dishId); var customBentoBox = new CustomBentoBox(encodedRecipe); customBentoBox.ChangeQuantity(dish, dishQuantity); var processor = new Processor(); processor.ProcessRule(customBentoBox); var mainCourses = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.MainCourse select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var sideDishes = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.SideDish select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var others = from item in customBentoBox.CustomBentoBoxItems where item.Dish.DishTypeId == (int)DishType.Drink select new { dishId = item.DishId, dishImageUrl = item.Dish.DishImageUrl, dishName = item.Dish.DishName, customBentoBoxId = customBentoBox.CustomBentoBoxId }; var unitPrice = customBentoBox.BentoBox.UnitPrice + customBentoBox.CustomBentoBoxItems.Sum(i => i.Dish.DishIncrementalPrice * i.Quantity); var warningMsg = processor.Errors; encodedRecipe = customBentoBox.EncodedRecipe; return Json(new { encodedRecipe = encodedRecipe, currentItems = new { mainCourses = mainCourses, sideDishes = sideDishes, others = others }, warningMsg = warningMsg, unitPrice = unitPrice }); }
private string RenderCustomBentoBox(CustomBentoBox customBentoBox) { var sb = new StringBuilder(); var dishes = customBentoBox.CustomBentoBoxItems.Select(i=>i.Dish); sb.Append("<ul>"); foreach (var dish in dishes) { sb.Append(string.Format("<li><img src='{0}'></li>", dish.DishImageUrl)); } sb.Append("</ul"); return sb.ToString(); }
/// <summary> /// Create a new CustomBentoBox object. /// </summary> /// <param name="customBentoBoxId">Initial value of the CustomBentoBoxId property.</param> /// <param name="customBentoBoxName">Initial value of the CustomBentoBoxName property.</param> /// <param name="bentoBoxId">Initial value of the BentoBoxId property.</param> public static CustomBentoBox CreateCustomBentoBox(global::System.Int32 customBentoBoxId, global::System.String customBentoBoxName, global::System.Int32 bentoBoxId) { CustomBentoBox customBentoBox = new CustomBentoBox(); customBentoBox.CustomBentoBoxId = customBentoBoxId; customBentoBox.CustomBentoBoxName = customBentoBoxName; customBentoBox.BentoBoxId = bentoBoxId; return customBentoBox; }
/// <summary> /// Deprecated Method for adding a new object to the CustomBentoBoxes EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomBentoBoxes(CustomBentoBox customBentoBox) { base.AddObject("CustomBentoBoxes", customBentoBox); }