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 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 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 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 });
        }