public IHttpActionResult GetAllRecipes() { try { var recipesList = RecipeManagementHelper.GetAllRecipes(); return(Ok(recipesList)); } catch (Exception e) { Console.WriteLine("Exception at RecipeManagementController", e.ToString()); return(NotFound()); } }
public IHttpActionResult Order(OrderViewModel order) { try { using (DatabaseContext dbctx = new DatabaseContext()) { var recipList = RecipeManagementHelper.GetAllRecipes(); RecipeViewModel recipe = recipList.Find(recip => recip.RecipeName == order.Recipe); if (recipe.RecipeName.Equals(order.Recipe)) { var Ingredients = recipe.Ingredients; if (OrdersManagementHelper.OrderValidation(Ingredients, order.Amount).ElementAt(0).Key.Equals("true")) { var NewIngredients = OrdersManagementHelper.ExtractIngredients(Ingredients, order.Amount); RecipeViewModel NewRecipe = new RecipeViewModel(recipe.RecipeName, NewIngredients, recipe.Actions); OrdersManagementHelper.AddOrder(order); var idOrder = dbctx.Orders.Where(ord => ord.Recipe.Equals(order.Recipe)) .Where(ord => ord.Amount.Equals(order.Amount)) .Select(column => column.ID_order) .ToList(); MethodsClass mc = new MethodsClass(); string s = RecipeManagementHelper.ParseObjectToStringForMSMQ(NewRecipe).ToString(); mc.SendMessage(s); LoggerHelper.Order(" a fost finalizata cu succes cu id-ul ", idOrder.LastOrDefault().ToString() + ". " + order.Amount + " produse <" + order.Recipe + "> au fost create cu succes."); LoggerHelper.Products(order.Amount); return(Ok("SUCCESS")); } else { LoggerHelper.Order(" a fost finalizata cu eroare.", ""); return(Ok(OrdersManagementHelper.OrderValidation(Ingredients, order.Amount))); } } else { return(NotFound()); } } } catch (InvalidOperationException e) { Console.WriteLine("Exception in OrdersManagementControllere/api/Order", e.ToString()); return(NotFound()); } }