public static void Initialize(ToastCoreContext context) { //context.Database.EnsureDeleted(); //Execute this command when updating the model context.Database.EnsureCreated(); if (!context.Toasters.Any()) { var toaster = new Toaster { Profile = 0, Status = Status.Off, NumToasts = 0, Time = 0, TimeStart = new DateTime().ToString(), TimeEnd = new DateTime().ToString(), ToastsMade = 0 }; context.Toasters.Add(toaster); context.SaveChanges(); } if (!context.Pantries.Any()) { var pantry = new Pantry { NumberOfBreads = 100, Status = PantryStatus.Full }; context.Pantries.Add(pantry); context.SaveChanges(); } }
public IActionResult PutBreads(int nBreads) { _pantry.NumberOfBreads = nBreads; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(StatusCode(500, "Error: " + ex.Message)); } return(StatusCode(200, (int)nBreads)); }
public IActionResult SetTime(int time) { _toaster.Time = time; _toaster.Profile = Profile.NoProfile; _context.Entry(_toaster).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(StatusCode(500, "Error: " + ex.Message)); } return(StatusCode(200, _toaster.Time.ToString())); }