public async Task <Employee> CreateEmployee(Employee employee)
        {
            _context.Add(employee);

            await _context.SaveChangesAsync();

            return(employee);
        }
Beispiel #2
0
        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" }));
        }
Beispiel #3
0
        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();
        }