示例#1
0
        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));
        }
示例#2
0
        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());
        }
示例#3
0
        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));
        }
示例#4
0
        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() }));
        }