public ActionResult Hire([FromBody] PostEmployeeCreate employeeToHire)
        {
            // Your template for doing a post to a collection.
            // Validate the data. If it is bad, send a 400 with or without details.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // POST is not idempotent and it is not safe.
            // - You post to make things happen.
            //  - do your programmery stuff. Whatever that.
            // Reponse
            // 201 Created Status code.
            // Add a Location to the response with the URI of the brand new resource.
            // To send them a copy of that resource - exactly as they'd get from following the location header.
            var response = new GetEmployeeDetailsResponse
            {
                Id             = new Random().Next(50, 10000),
                Name           = employeeToHire.Name,
                Department     = employeeToHire.Department,
                StartingSalary = employeeToHire.StartingSalary
            };

            return(CreatedAtRoute("employees#get", new { employeeId = response.Id }, response));
        }
Ejemplo n.º 2
0
        public ActionResult Hire([FromBody] PostEmployeeCreate employeeToHire)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = new GetEmployeeDetailsResponse
            {
                Id             = new Random().Next(50, 10000),
                Name           = employeeToHire.Name,
                Department     = employeeToHire.Department,
                StartingSalary = employeeToHire.StartingSalary
            };

            return(CreatedAtRoute("employees#get", new { employeeId = response.Id }, response));
        }