Пример #1
0
 public void ReplaceRecipe(string dishIds)
 {
     var oldRecipe = new List<int>();
     oldRecipe.AddRange(CustomBentoBoxItems.Select(i => i.DishId));
     foreach (var dishIdVal in dishIds.Split(','))
     {
         int dishId;
         int quantity = 1;
         var parts = dishIdVal.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
         if (parts.Length == 2)
         {
             int.TryParse(parts[1], out quantity);
         }
         if (parts.Length > 0)
         {
             if (int.TryParse(parts[0], out dishId))
             {
                 var dish = db.Dishes.Single(i => i.DishId == dishId);
                 ChangeQuantity(dish, quantity);
                 if( db.CustomBentoBoxItems.Count(i => i.DishId == dishId && i.CustomBentoBoxId == CustomBentoBoxId) == 0) {
                     var dbCustomBentoBoxItem = new CustomBentoBoxItem
                         {
                             DishId = dish.DishId,
                             Quantity = quantity,
                             CustomBentoBoxId = CustomBentoBoxId
                         };
                     db.CustomBentoBoxItems.AddObject(dbCustomBentoBoxItem);
                 }
                 else {
                     var dbCustomBentoBoxItem = db.CustomBentoBoxItems.Single(i=>i.DishId == dishId && i.CustomBentoBoxId == CustomBentoBoxId);
                     dbCustomBentoBoxItem.Quantity = quantity;
                     db.CustomBentoBoxItems.ApplyCurrentValues(dbCustomBentoBoxItem);
                 }
                 db.SaveChanges();
                 oldRecipe.Remove(dish.DishId);
             }
         }
     }
     foreach (var dishId in oldRecipe)
     {
         var dbCustomBentoBoxItem = db.CustomBentoBoxItems.Single(i => i.DishId == dishId && i.CustomBentoBoxId == CustomBentoBoxId);
         db.CustomBentoBoxItems.DeleteObject(dbCustomBentoBoxItem);
         db.SaveChanges();
         var customBentoBoxItem = CustomBentoBoxItems.Single(i => i.DishId == dishId);
         CustomBentoBoxItems.Remove(customBentoBoxItem);
     }
 }
Пример #2
0
        public void ChangeQuantity(Dish dish, int quantity)
        {
            var customBentoBoxItem = CustomBentoBoxItems.SingleOrDefault(i => i.DishId == dish.DishId);

            if (customBentoBoxItem == null)
            {
                customBentoBoxItem = new CustomBentoBoxItem
                {
                    DishId = dish.DishId,
                    Quantity = quantity
                };

                CustomBentoBoxItems.Add(customBentoBoxItem);
            }
            else
            {
                customBentoBoxItem.Quantity = quantity;
            }
        }
Пример #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the CustomBentoBoxItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomBentoBoxItems(CustomBentoBoxItem customBentoBoxItem)
 {
     base.AddObject("CustomBentoBoxItems", customBentoBoxItem);
 }
Пример #4
0
        public bool AddToCustomBentoBox(Dish dish)
        {
            var customBentoBoxItem =  CustomBentoBoxItems.SingleOrDefault(i=>i.DishId == dish.DishId);

            if (customBentoBoxItem == null)
            {
                customBentoBoxItem = new CustomBentoBoxItem
                {
                    DishId = dish.DishId,
                    Quantity = 1
                };
                CustomBentoBoxItems.Add(customBentoBoxItem);
                return true;
            }
            return false;
        }
Пример #5
0
 /// <summary>
 /// Create a new CustomBentoBoxItem object.
 /// </summary>
 /// <param name="customBentoBoxItemId">Initial value of the CustomBentoBoxItemId property.</param>
 /// <param name="customBentoBoxId">Initial value of the CustomBentoBoxId property.</param>
 /// <param name="dishId">Initial value of the DishId property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 public static CustomBentoBoxItem CreateCustomBentoBoxItem(global::System.Int32 customBentoBoxItemId, global::System.Int32 customBentoBoxId, global::System.Int32 dishId, global::System.Int32 quantity)
 {
     CustomBentoBoxItem customBentoBoxItem = new CustomBentoBoxItem();
     customBentoBoxItem.CustomBentoBoxItemId = customBentoBoxItemId;
     customBentoBoxItem.CustomBentoBoxId = customBentoBoxId;
     customBentoBoxItem.DishId = dishId;
     customBentoBoxItem.Quantity = quantity;
     return customBentoBoxItem;
 }