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));
        }
Esempio n. 2
0
        public ActionResult LookupEmployee([FromRoute] int employeeId)
        {
            var response = new GetEmployeeDetailsResponse
            {
                Id             = employeeId,
                Name           = "Joe Smith",
                Department     = "DEV",
                StartingSalary = 50000
            };

            return(Ok(response));
        }
        public ActionResult LookupEmployee([FromRoute] int employeeId)
        {
            // go to the database whatever..
            var response = new GetEmployeeDetailsResponse
            {
                Id             = employeeId,
                Name           = "Joe Schmidt",
                Department     = "DEV",
                StartingSalary = 50000
            };

            return(Ok(response));
        }
Esempio n. 4
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));
        }