public async Task <IActionResult> Edit(int id, [Bind("Id,Name,YearofCreation,CountryofCreationId,CreationHistory,StrengthId,TechniqueId,GlassId,Recipe")] Coctails coctails) { if (id != coctails.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(coctails); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoctailsExists(coctails.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CountryofCreationId"] = new SelectList(_context.Country, "Id", "Name", coctails.CountryofCreationId); ViewData["GlassId"] = new SelectList(_context.Glass, "Id", "Name", coctails.GlassId); ViewData["StrengthId"] = new SelectList(_context.Strengths, "Id", "Name", coctails.StrengthId); ViewData["TechniqueId"] = new SelectList(_context.Techniques, "Id", "Name", coctails.TechniqueId); return(View(coctails)); }
private void btnMinus_Click(object sender, EventArgs e) { foreach (var t in lbOut.SelectedItems.Cast <object>().ToList()) { Data = (Coctails)t; OptimizedData.MultiplyItems.Remove(Data); } Refresh(); }
private void btnEditCoctail_Click(object sender, EventArgs e) { _coctail = (Coctails)lbCoctails.SelectedItem; _coctailsRepository.Update(new Coctails { Name = tbNameCoc.Text, Quantity = Convert.ToInt32(tbQuantCoc.Text), Cost = Convert.ToInt32(tbCostCoc.Text), Ingredient = _coctail.Ingredient, Type = cbType.SelectedIndex + 1 }); Refresher(); }
public async Task <IActionResult> Create([Bind("Id,Name,YearofCreation,CountryofCreationId,CreationHistory,StrengthId,TechniqueId,GlassId,Recipe")] Coctails coctails) { if (ModelState.IsValid) { _context.Add(coctails); await _context.SaveChangesAsync(); return(RedirectToAction("Create", "Compounds")); } ViewData["CountryofCreationId"] = new SelectList(_context.Country, "Id", "Name", coctails.CountryofCreationId); ViewData["GlassId"] = new SelectList(_context.Glass, "Id", "Name", coctails.GlassId); ViewData["StrengthId"] = new SelectList(_context.Strengths, "Id", "Name", coctails.StrengthId); ViewData["TechniqueId"] = new SelectList(_context.Techniques, "Id", "Name", coctails.TechniqueId); return(View(coctails)); }
private void btnDelCoctail_Click(object sender, EventArgs e) { _coctail = (Coctails)lbCoctails.SelectedItem; _coctailsRepository.Delete(_coctail.Name); Refresher(); }
public async Task <IActionResult> Import(IFormFile fileExcel) { if (ModelState.IsValid) { if (fileExcel != null) { using (var stream = new FileStream(fileExcel.FileName, FileMode.Create)) { await fileExcel.CopyToAsync(stream); using (XLWorkbook workCoctail = new XLWorkbook(stream, XLEventTracking.Disabled)) { foreach (IXLWorksheet worksheet in workCoctail.Worksheets) { Techniques newtech; var t = (from tech in _context.Techniques where tech.Name.Contains(worksheet.Name) select tech).ToList(); if (t.Count > 0) { newtech = t[0]; } else { newtech = new Techniques(); newtech.Name = worksheet.Name; newtech.Description = "from EXCEL"; _context.Techniques.Add(newtech); } // foreach (IXLRow row in worksheet.RowsUsed().Skip(1)) { try { Coctails coctail = new Coctails(); var coc = (from coct in _context.Coctails where coct.Name.Contains(row.Cell(1).Value.ToString()) select coct).ToList(); if (coc.Count == 0) { coctail.Name = row.Cell(1).Value.ToString(); coctail.YearofCreation = row.Cell(2).Value.ToString(); coctail.CreationHistory = row.Cell(4).Value.ToString(); coctail.Recipe = row.Cell(7).Value.ToString(); coctail.Technique = newtech; if (row.Cell(3).Value.ToString().Length > 0) { var k1 = row.Cell(3).Value.ToString(); Country country; var c = (from ct in _context.Country where ct.Name.Contains(row.Cell(3).Value.ToString()) select ct).ToList(); if (c.Count > 0) { country = c[0]; } else { country = new Country(); country.Name = row.Cell(3).Value.ToString(); _context.Add(country); await _context.SaveChangesAsync();// } coctail.CountryofCreation = country; } if (row.Cell(5).Value.ToString().Length > 0) { Strengths strengths; var k2 = row.Cell(5).Value.ToString(); var s = (from str in _context.Strengths where str.Name.Contains(row.Cell(5).Value.ToString()) select str).ToList(); if (s.Count > 0) { strengths = s[0]; } else { strengths = new Strengths(); strengths.Name = row.Cell(5).Value.ToString(); _context.Add(strengths); await _context.SaveChangesAsync();// } coctail.Strength = strengths; } if (row.Cell(6).Value.ToString().Length > 0) { Glass glass; var k3 = row.Cell(6).Value.ToString(); var g = (from gl in _context.Glass where gl.Name.Contains(row.Cell(6).Value.ToString()) select gl).ToList(); if (g.Count > 0) { glass = g[0]; } else { glass = new Glass(); glass.Name = row.Cell(6).Value.ToString(); _context.Add(glass); await _context.SaveChangesAsync();// } coctail.Glass = glass; } _context.Coctails.Add(coctail); } } catch (Exception e) { } } } } } } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }