public void Save(Recipe newRecipe) { TextWriter writer = null; RecipeList recipeList = null; try { // See if recipes exists var serializer = new XmlSerializer(typeof(RecipeList)); if (File.Exists(path)) // Load the recipe list if it exists { using (var fileStream = File.OpenRead(path)) { recipeList = (RecipeList)serializer.Deserialize(fileStream); } } else { recipeList = new RecipeList(); } // Add recipe to the list recipeList.Recipes.Add(newRecipe); writer = new StreamWriter(path, append: false); serializer.Serialize(writer, recipeList); } finally { if (writer != null) { writer.Close(); } } }
/// <summary> /// Recipe追加用 /// TODO: SqlBulkInsert 対応したほうがいいかも。複数行同時追加があるようであれば /// </summary> /// <param name="recipeList"></param> /// <returns></returns> private int InsertRecipe(RecipeList recipeList) { // Initialize the return value to zero and create a StringWriter to display results. int affectedCountOfRows = 0; try { // Create the TransactionScope to execute the commands, guaranteeing // that both commands can commit or roll back as a single unit of work. using (var scope = new TransactionScope()) { recipeList.Recipes.ForEach(f => BaseLoggerContext.Recipes.Add(f)); BaseLoggerContext.SaveChanges(); // The Complete method commits the transaction. If an exception has been thrown, // Complete is not called and the transaction is rolled back. scope.Complete(); } } catch (TransactionAbortedException ex) { Log.Error("TransactionAbortedException Message: {0}", ex.Message); } catch (ApplicationException ex) { Log.Error("ApplicationException Message: {0}", ex.Message); } catch (Exception ex) { Log.Error(ex, "Exception at InsertRecipe"); } // Display messages. return(affectedCountOfRows); }
private RecipeList SearchRecipes(string input) { var DownloadLink = ""; foreach (string health in this.Health) { if (input.Contains(health)) { DownloadLink += "&health=" + health.Trim(); input = input.Replace(health, " "); } } foreach (string rmword in this.Removable) { input = input.Replace(rmword, " "); } input = input.Replace(" ", " ").Trim().Replace(" ", "+"); DownloadLink += "&q=" + input; using (var client = new WebClient()) { var recipeJson = client.DownloadString("https://api.edamam.com/search?app_id=084c75ba&app_key=dc0c53baf15766be071aa494ecd8fae6&to=5" + DownloadLink); RecipeList recipeList = JsonSerializer.Deserialize <RecipeList>(recipeJson, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); return(recipeList); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); recipes = (RecipeList)e.Parameter; selectedRecipe = recipes.getSelected(); detailSection.SelectedItem = detailSection.MenuItems[0]; contentFrame.Navigate(typeof(DetailPage), selectedRecipe); if (isNarrow()) { IList <PageStackEntry> backStack = Frame.BackStack; int backStackCount = backStack.Count; if (backStackCount > 0) { PageStackEntry masterPageEntry = backStack[backStackCount - 1]; backStack.RemoveAt(backStackCount - 1); PageStackEntry modifiedEntry = new PageStackEntry( masterPageEntry.SourcePageType, recipes, masterPageEntry.NavigationTransitionInfo ); backStack.Add(modifiedEntry); } // Show back button NavigationView currShell = AppShell.currentShell; currShell.IsBackButtonVisible = NavigationViewBackButtonVisible.Visible; currShell.IsBackEnabled = true; } }
private void Start() { buttonComponent = GetComponent <Button>(); buttonComponent.onClick.AddListener(HandleClick); label = transform.GetChild(0).GetComponent <Text>(); recipeList = transform.parent.parent.parent.GetComponent <RecipeList>(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); int index = -1; if (e.Parameter == null) { recipes = App.recipes; int numRecipes = recipes.getRecipeList().Count; if (numRecipes > 0) { index = 0; } } else { recipes = (RecipeList)e.Parameter; index = recipes.getSelectedIndex(); } this.recipeListView.ItemsSource = recipes.Recipes; if (index < 0) { detailFrame.Visibility = Visibility.Collapsed; } recipeListView.SelectedIndex = index; updateLayoutFromState(AdaptiveStates.CurrentState, null); Debug.WriteLine(index); showDetailView(index); }
public IActionResult Delete(int Id) { if (Id < RecipeList.GetRecipeList().Count&& Id >= 0) { RecipeList.Remove(Id); } return(RedirectToAction(nameof(Index))); }
public IActionResult Details(int Id) { if (Id >= RecipeList.GetRecipeList().Count || Id < 0) { RedirectToAction(nameof(Index)); } return(View(RecipeList.GetRecipeList()[Id])); }
public IActionResult Index(string searchPattern) { if (searchPattern == null || searchPattern.Trim() == "") { return(View(RecipeList.GetRecipeList())); } return(View(RecipeList.GetFilteredRecipeList(searchPattern))); }
public IActionResult Edit(int?id) { if (id == null || id >= RecipeList.GetRecipeList().Count) { return(NotFound()); } return(View(RecipeList.GetRecipeList()[id.Value])); }
public async Task <RecipeList> SearchRecipesAsync(string searchTerm, int numberOfRecipes, bool[] health) { var DownloadLink = ""; DownloadLink += numberOfRecipes; if (health.Contains(true)) { if (health[0]) { DownloadLink += "&health=vegetarian"; } if (health[1]) { DownloadLink += "&health=vegan"; } if (health[2]) { DownloadLink += "&health=peanut-free"; } if (health[3]) { DownloadLink += "&health=tree-nut-free"; } if (health[4]) { DownloadLink += "&health=sugar-conscious"; } if (health[5]) { DownloadLink += "&health=alcohol-free"; } if (health[6]) { DownloadLink += "&diet=high-protein"; } if (health[7]) { DownloadLink += "&dietlow-fat"; } if (health[8]) { DownloadLink += "&diet=low-carb"; } } DownloadLink += "&q=" + searchTerm.Replace(" ", " ").Trim().Replace(" ", "+"); var recipeJson = await apiInterface.CallRecipeApi(DownloadLink); RecipeList recipeList = JsonSerializer.Deserialize <RecipeList>(recipeJson, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); return(recipeList); }
//if selectedProduct has a recipe - display it in the recipe listbox private void DisplayRecipeIfExists(ProductModel selectedProduct) { if (selectedProduct.RecipeId != null) { RecipesListBox.SelectedItem = RecipeList.Where(r => r.Id == selectedProduct.RecipeId).First(); } else { RecipesListBox.ClearSelected(); } }
/// <summary> /// Constructor /// </summary> public BeerXmlData() { Equipment = new EquipmentList(); Fermentables = new FermentableList(); Hops = new HopList(); Miscs = new MiscList(); Recipes = new RecipeList(); Styles = new StyleList(); Waters = new WaterList(); Yeasts = new YeastList(); }
private void PopulateList() { RecipeList.Add(new Recipe() { RecipeId = 1, RecipeName = "Sweet Chilli Beef & Vegetable Stir-Fry", RecipeDesc = "with Garlic Rice", Picture = "sweetchilli" }); RecipeList.Add(new Recipe() { RecipeId = 2, RecipeName = "Cheesy Pesto Chicken Calzones", RecipeDesc = "with Tomato Sauce & Marinated Zucchini", Picture = "img1" }); RecipeList.Add(new Recipe() { RecipeId = 3, RecipeName = "Monterey Jack Cheeseburgers", RecipeDesc = "topped with Poblano & Tomato Salsa", Picture = "img2" }); RecipeList.Add(new Recipe() { RecipeId = 4, RecipeName = "Roast Pork & Vegetables", RecipeDesc = "with Basil Pesto & Marinated Tomatoes", Picture = "img3" }); RecipeList.Add(new Recipe() { RecipeId = 5, RecipeName = "Orange-Soy Barramundi & Fried Rice", RecipeDesc = "with Snow Peas & Bok Choy", Picture = "img4" }); RecipeList.Add(new Recipe() { RecipeId = 6, RecipeName = "Sweet Potato & Spicy Cucumber Bao", RecipeDesc = "with Black Garlic Mayo", Picture = "img5" }); RecipeList.Add(new Recipe() { RecipeId = 7, RecipeName = "Tahini Chicken", RecipeDesc = "with Tomato Sauce & Marinated Zucchini", Picture = "img6" }); }
public static bool ToRecipeListDTO(RecipeList input, RecipeListDTO output) { if (input == null) { return(false); } output.ItemVNum = input.ItemVNum; output.MapNpcId = input.MapNpcId; output.RecipeId = input.RecipeId; output.RecipeListId = input.RecipeListId; return(true); }
/// <summary> /// Initialisation du conteneur de commandes /// </summary> void InitCom() { string[] tab = CookingCore_Alexandre_FORESTIER_Charlotte_PELLERIN.Recette.GetAll(); RecipeList recette = new RecipeList(tab, true); Grid.SetRow(recette.scroll, 1); commandes.Children.Add(recette.scroll); quantite = recette.quantite; //RecipeList recetteP = new RecipeList(tab, false); }
public ViewResult AddRecipeForm(Recipe recipe) { if (ModelState.IsValid) { RecipeList.AddRecipe(recipe); return(View("Submitted")); } else { return(View()); } }
public MainWindow() { InitializeComponent(); recipeSource = new FileRecipeSource(); // Inicjalizacja kontrolek. RecipeList recipeList = FindName("RecipeList") as RecipeList; recipeList.Initialize(recipeSource); //TODO: Powiązać eventy/handlery }
private void RecipeListUpdatedEventHandler(object sender, EventArgs e) { RecipeList.Clear(); if (_recipeListModel.Recipes.Count < 1) { _msgBoxService.ShowInfo("Vi er meget kede af det, men der er desværre ingen resultater. Prøv med en anden søgning."); return; } foreach (var recipe in _recipeListModel.Recipes) { RecipeList.Add(recipe); } }
public IActionResult Edit(int id, [Bind("Id,Name,Time,Difficulty,NumberOfLikes,Ingredients,Process,Tips")] Recipe recipe) { if (id != recipe.Id) { return(NotFound()); } if (ModelState.IsValid) { RecipeList.GetRecipeList()[id] = recipe; return(RedirectToAction(nameof(Index))); } return(View(recipe)); }
// GET: Recipe public ActionResult Index() { if (Authenticate.IsAuthenticated()) { recipelist = new RecipeList(); FetchLogin(); recipelist.Load(login.Id); return(View(recipelist)); } else { return(RedirectToAction("Login", "Login", new { returnurl = HttpContext.Request.Url })); } }
public ActionResult Index() { var service = CreateRecipeService(); var model = new RecipeList() { SeasonFilter = new SeasonFilter() { ControllerName = "Recipe" }, Larders = service.GetRecipes(), }; return(View(model)); }
/// <summary> /// Saves a recipe to the database asyncronously /// </summary> /// <param name="recipe">The recipe to store</param> /// <returns>An integer indicating the key of the recipe or the affected rows (if updating)</returns> public async Task <int> SaveRecipeAsync(Recipe recipe) { if (RecipeList != null && RecipeList.Any(r => r.Id == recipe.Id || r.Name == recipe.Name)) { return(await _database.UpdateAsync(recipe)); } else if (recipe.Id != 0) { return(await _database.InsertOrReplaceAsync(recipe)); } else { return(await _database.InsertAsync(recipe)); } }
public ActionResult Index(SeasonFilter SeasonFilter) { var service = CreateLarderService(); var model = new RecipeList() { SeasonFilter = new SeasonFilter() { ControllerName = "Larder" } }; model.Larders = service.GetLardersBySeason(SeasonFilter); model.SeasonFilter = SeasonFilter; return(View("Index", model)); }
public MainWindow() { InitializeComponent(); recipeSource = new FileRecipeSource(); recipeHistory = new FileRecipeHistory(); HelperService.Initialize(recipeSource, recipeHistory); // Inicjalizacja kontrolek. RecipeList recipeList = FindName("RecipeList") as RecipeList; recipeList.Initialize(recipeSource); _SearchBar.QueryChanged += recipeList.Filter; }
public bool CreateRecipeList(RecipeListCreate model) { var entity = new RecipeList() { OwnerId = _userId, Recipeid = model.RecipeID, IngredientId = model.IngredientID, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.RecipeList.Add(entity); return(ctx.SaveChanges() == 1); } }
private void button23_Click(object sender, EventArgs e) { TradeData tradeData = new TradeData(); Tradeinfo tradeinfo = new Tradeinfo(); RecipeList recipeList = new RecipeList(); FeeitemList feeitemList = new FeeitemList(); tradeinfo.tradeType = TradeType.普通门诊; tradeinfo.billtype = "0"; List <Recipe> recipes = new List <Recipe>(); Recipe recipe = new Recipe(); recipes.Add(recipe); recipeList.recipes = recipes; List <Feeitem> feeitems = new List <Feeitem>(); foreach (DataRow dr in ((DataTable)dataGridView2.DataSource).Rows) { Feeitem feeitem = new Feeitem(); feeitem.itemno = dr["PresDetailID"].ToString(); feeitem.recipeno = dr["presNO"].ToString(); feeitem.hiscode = dr["ItemID"].ToString(); feeitem.itemname = dr["ItemName"].ToString(); feeitem.itemtype = dr["ItemType"].ToString(); feeitem.unitprice = dr["RetailPrice"].ToString(); feeitem.count = dr["PresAmount"].ToString(); feeitem.fee = dr["TotalFee"].ToString(); feeitem.babyflag = "0"; feeitems.Add(feeitem); } feeitemList.feeitems = feeitems; tradeData.MIID = 1; tradeData.SerialNo = txtMzCenterCostID.Text.ToString().Trim(); tradeData.tradeinfo = tradeinfo; tradeData.recipeList = recipeList; tradeData.feeitemList = feeitemList; InvokeController("MZ_PreviewChargeDllNew", tradeData); }
public void Update(RecipeListDTO recipe) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { RecipeList result = context.RecipeList.FirstOrDefault(r => r.RecipeListId.Equals(recipe.RecipeListId)); if (result != null) { Mapper.Mapper.Instance.RecipeListMapper.ToRecipeList(recipe, result); context.SaveChanges(); } } } catch (Exception e) { Logger.Error(e); } }
public List <Recipe> readAll() { RecipeList temp = null; var serializer = new XmlSerializer(typeof(RecipeList)); try { using (var fileStream = File.OpenRead(path)) { temp = (RecipeList)serializer.Deserialize(fileStream); } return(temp.Recipes); } catch (Exception e) { string error = @"An exception occured: " + e; //Log theLog = new Log(); //theLog.LogMessage(error); return(new List <Recipe>()); } }
//usuwanie przepisu z listy private void Delete() { if (SharedVM.HomeVM.SelectedRecipe == null) { MessageBox.Show("Nie wybrano żadnego przepisu."); return; } MessageBoxResult dialogResult = MessageBox.Show("Czy na pewno chcesz usunąć przepis?", "Usuwanie przepisu", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { using (var contex = new CookingBookEntities1()) { contex.Recipes.Remove(contex.Recipes.Where(x => x.ID == SelectedRecipe.ID).First()); contex.Ingredients.RemoveRange(contex.Ingredients.Where(x => x.RecipeID == SelectedRecipe.ID)); contex.SaveChanges(); RecipeList.Remove(SelectedRecipe); } } }
public RecipeListDTO Insert(RecipeListDTO recipeList) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { RecipeList entity = new RecipeList(); Mapper.Mapper.Instance.RecipeListMapper.ToRecipeList(recipeList, entity); context.RecipeList.Add(entity); context.SaveChanges(); if (Mapper.Mapper.Instance.RecipeListMapper.ToRecipeListDTO(entity, recipeList)) { return(recipeList); } return(null); } } catch (Exception e) { Logger.Error(e); return(null); } }