public IActionResult CreateNewEmployee([FromBody] EditEmployeeVm editEmployeeVm) { FullEmployeeVm newEmployee = new FullEmployeeVm(); newEmployee.Id = _employees.Count == 0 ? 1 : _employees.Max(e => e.Id) + 1; newEmployee.Update(editEmployeeVm); _employees.Add(newEmployee); return(Json(newEmployee.Id)); }
public IActionResult GetById(int id) { FullEmployeeVm employee = _employees.SingleOrDefault(e => e.Id == id); if (employee != null) { return(Json(employee)); } // The employee could not be found return(this.HttpNotFound()); }
public IActionResult UpdateEmployee(int id, [FromBody] EditEmployeeVm editEmployeeVm) { FullEmployeeVm employee = _employees.SingleOrDefault(e => e.Id == id); if (employee == null) { return(HttpNotFound()); } employee.Update(editEmployeeVm); return(Json(employee.Id)); }
public IActionResult Edit(int id) { // Find the employee to the specified id FullEmployeeVm employeeVm = _employees.SingleOrDefault(e => e.Id == id); if (employeeVm == null) { // The employee could not be found return(HttpNotFound()); } // Create the metadata info for the type SchemaFormInfo schemaFormInfo = _schemaFormBuilder.CreateSchemaForm(typeof(FullEmployeeVm)); // Create a response which contains the metadata and the resource return(Json(new { schemaFormInfo.Form, schemaFormInfo.Schema, Data = employeeVm.ToEditEmployeeVm() })); }