Exemple #1
0
 public bool AddOrder(string tableCode, List <RecipeModel> recipes, double allPrice)
 {
     using (var dbContextTransaction = dataContext.Database.BeginTransaction())
     {
         try
         {
             var table = dataContext.Set <DinnerTable>().FirstOrDefault(dt => dt.Code == tableCode);
             var order = new Order();
             order.Code     = Guid.NewGuid().ToString("D");
             order.AllPrice = allPrice;
             order.Status   = 1;
             List <OrderRecipe> orderRecipes = new List <OrderRecipe>();
             foreach (var recipe in recipes)
             {
                 var orderRecipe = new OrderRecipe();
                 orderRecipe.Code       = Guid.NewGuid().ToString("D");
                 orderRecipe.OrderCode  = order.Code;
                 orderRecipe.RecipeCode = recipe.code;
                 orderRecipe.type       = 1;
                 orderRecipe.Num        = recipe.num;
                 orderRecipes.Add(orderRecipe);
             }
             var orderTable = new OrderRecipe();
             orderTable.Code       = Guid.NewGuid().ToString("D");
             orderTable.Num        = 1;
             orderTable.type       = 2;
             orderTable.OrderCode  = order.Code;
             orderTable.RecipeCode = tableCode;
             orderRecipes.Add(orderTable);
             table.Status = 1;
             dataContext.Set <Order>().Add(order);
             dataContext.Set <OrderRecipe>().AddRange(orderRecipes);
             dataContext.Set <DinnerTable>().Update(table);
             dataContext.SaveChanges();
             dbContextTransaction.Commit();
             return(true);
         }
         catch (Exception e)
         {
             dbContextTransaction.Rollback();
             return(false);
         }
     }
 }
Exemple #2
0
        public ActionResult Create(VMOrder recipe)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var orr = new OrderRecipe();
                    orr.OrderID = recipe.OrderID;
                    orr.RecID   = recipe.RecID;
                    db.AddToOrderRecipe(orr);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex);
            }
            return(View(recipe));
        }
Exemple #3
0
    /// <summary>
    /// Removes unwanted ingredients based on chance, and generates a Order Recipe the player will try to match
    /// </summary>
    /// <param name="orderBaseRecipe">The base recipe the OrderRecipe will be based on</param>
    /// <returns></returns>
    private OrderRecipe CreateOrderRecipe(Recipe orderBaseRecipe)
    {
        OrderRecipe orderRecipe = new OrderRecipe();

        orderRecipe.BaseRecipe       = orderBaseRecipe;
        orderRecipe.OrderRecipePrice = OrderBaseRecipe.Price;

        for (int i = 0; i < orderBaseRecipe.Ingredients.Count; i++) // Rolls to check if a ingredient will be removed
        {
            var roll = Random.Range(1, 100);
            if (RemoveIngredients && roll < orderBaseRecipe.Ingredients[i].RemoveChance)// Roll will never be 0% or 100% => %0 safe %100 removed
            {
                var ingredient = orderBaseRecipe.Ingredients[i];
                orderRecipe.OrderRecipePrice -= ingredient.IngredientCost;
                orderRecipe.DiscaredIngredients.Add(ingredient);
            }
            else
            {
                orderRecipe.OrderIngredients.Add(orderBaseRecipe.Ingredients[i]);
            }
        }
        return(orderRecipe);
    }