public async Task <Employee> CreateEmployee(Employee employee) { _context.Add(employee); await _context.SaveChangesAsync(); return(employee); }
public async Task <IActionResult> Create([Bind("Name,Address")][FromBody] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); // We'll return the details of the newly created customer. // The frontend won't know the id we've given the new customer so we want to send this back so it. return(Json(new { success = true, data = customer })); } return(Json(new { success = false, message = "Invalid customer given" })); }
public static void Initialize(DemoBackendContext context) { context.Database.EnsureCreated(); //if DB doesn't exist, it will auto create the DB. if (context.Employees.Any()) { return; } var employee = new Employee { FirstName = "Joshua", LastName = "Colanggo", DateCreated = DateTime.UtcNow }; context.Add(employee); context.SaveChanges(); }