public static void Initialize(LauContext context) { context.Database.EnsureCreated(); if (context.LauItems.Any()) { return; } var lauItems = new LauItem[] { new LauItem { Category = "Kaos", Color = "Hijau", Brand = "Cole", Price = 69000, Description = "", Status = true, DateBought = DateTime.Now, DateCreated = DateTime.Now, DateModified = DateTime.Now } }; foreach (LauItem l in lauItems) { context.LauItems.Add(l); } context.SaveChanges(); var lauLogs = new LauLog[] { new LauLog { DateIn = DateTime.Now, DateOut = DateTime.Now, Price = 15000, Status = true } }; foreach (LauLog l in lauLogs) { context.LauLogs.Add(l); } context.SaveChanges(); var lauUnits = new LauUnit[] { new LauUnit { LauItemId = 1, LauLogId = 1, Quantity = 1, Status = true, Notes = "" } }; foreach (LauUnit l in lauUnits) { context.LauUnits.Add(l); } context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("DateIn,DateOut,Price,Status")] LauLog lauLog) { try { if (ModelState.IsValid) { _context.Add(lauLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException e) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(lauLog)); }