public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Price,Size")] Muffin muffin) { if (id != muffin.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(muffin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MuffinExists(muffin.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(muffin)); }
public static void DeleteMuffin(int id) { using (var context = new MuffinContext()) { Muffin deleteMuffin = context.Muffin.Find(id); context.Muffin.Remove(deleteMuffin); context.SaveChanges(); } }
public static void ModifyMuffin(int muffin_id, string muffin_name, decimal muffin_price) { using (var context = new MuffinContext()) { Muffin modifyMuffin = context.Muffin.Find(muffin_id); modifyMuffin.muffin_name = muffin_name; modifyMuffin.muffin_price = muffin_price; context.Entry(modifyMuffin).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public static void AddMuffin(string muffin_name, decimal muffin_price) { using (var context = new MuffinContext()) { Muffin newMuffin = new Muffin(); newMuffin.muffin_name = muffin_name; newMuffin.muffin_price = muffin_price; context.Muffin.Add(newMuffin); context.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,Size")] Muffin muffin) { if (ModelState.IsValid) { _context.Add(muffin); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(muffin)); }
public void Main() { var bread = new Bread(); bread.Make(); var cake = new Cake(); cake.Make(); var muffin = new Muffin(); muffin.Make(); }
public bool Put(Guid id, [FromBody] Muffin value) { value.Id = id; var muffin = this.muffinRepository.GetById(id); if (muffin == null) { return(this.muffinRepository.Add(value)); } else { return(this.muffinRepository.Update(value)); } }
private static string GetExercise3Text(Donut donut, Muffin muffin, Cake cake) { var text = new StringBuilder(); text.AppendLine($"Donut:"); donut.ToString().Split(',').ToList().ForEach(prop => text.AppendLine($" > {prop.TrimStart()}")); text.AppendLine(""); text.AppendLine($"Magdalenas:"); muffin.ToString().Split(',').ToList().ForEach(prop => text.AppendLine($" > {prop.TrimStart()}")); text.AppendLine(""); text.AppendLine($"Pastel:"); cake.ToString().Split(',').ToList().ForEach(prop => text.AppendLine($" > {prop.TrimStart()}")); return(text.ToString()); }
public bool Post([FromBody] Muffin value) { return(this.muffinRepository.Update(value)); }
public static void Main() { Hexagon hex = new Hexagon("James"); Circle c = new Circle("Lisa"); IPointy itfPt = null; try { // dynamic test if interface is supported. itfPt = (IPointy) c; Console.WriteLine(itfPt.Points); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } // or use "as" keyword to see interfaces supported. Hexagon hex2 = new Hexagon("Peter"); IPointy itfPt2 = hex2 as IPointy; if (itfPt2 != null) Console.WriteLine("YES! Points: {0}", itfPt2.Points); else Console.WriteLine("OOPS! Not pointy..."); // or check for implemented interface using "is" keyword Shape[] shapes = { new Hexagon(), new Circle(), new Triangle("Joe"), new Triangle("JoJo")}; for (int i = 0; i < shapes.Length; i++) { shapes[i].Draw(); // who's pointy if (shapes[i] is IPointy) { Console.WriteLine("-> Points: {0}", ((IPointy) shapes[i]).Points); } else { Console.WriteLine("-> {0} is not pointy!", shapes[i].PetName); } } IPointy[] pointies = { new Hexagon(), new Knife(), new Triangle(), new Fork(), new PitchFork()}; foreach (IPointy i in pointies) { Console.WriteLine("Object has {0} points.", i.Points); } // resolving name clashes Octagon oct = new Octagon(); IDrawToForm ifrm = (IDrawToForm) oct; ifrm.Draw(); IDrawToMemory imem = (IDrawToMemory) oct; imem.Draw(); IDrawToPrinter iprt = (IDrawToPrinter) oct; iprt.Draw(); // must use casting to access the interface method ((IDrawToPrinter)oct).Draw(); if (oct is IDrawToMemory) { ((IDrawToMemory)oct).Draw(); } // using BitmapImage invoke each method at object level // as well as extract reference to supported interface BitmapImage bm = new BitmapImage(); bm.Draw(); bm.DrawInBoundingBox(10, 10, 100, 150); bm.DrawUpsideDown(); // get IAdvancedDraw explicitly IAdvancedDraw iad = bm as IAdvancedDraw; if (iad != null) { iad.DrawUpsideDown(); } // multiple inheritance Snickerdoodle sn = new Snickerdoodle(); sn.Draw(); sn.Print(); Muffin mf = new Muffin(); ((IDrawable)mf).Draw(); ((IPrintable)mf).Draw(); mf.Print(); mf.GetNumberOfSides(); }
public void CreateMuffin(Muffin muffin) { //do some work business stuff _context.Muffins.Add(muffin); _context.SaveChanges(); }