Exemple #1
0
        public ActionResult GetAnEmplyee(int employeeId)
        {
            //goto the database and get employee data
            var employeeResponse = new EmployeeResponse
            {
                Id             = employeeId,
                Name           = "Bob Smith",
                Department     = "DEV",
                HireDate       = DateTime.Now.AddDays(-399),
                StartingSalary = 250000
            };

            return(Ok(employeeResponse));
        }
Exemple #2
0
        public ActionResult Hire([FromBody] EmployeeCreateRequest employeeToHire)
        {
            //1. Validate it..if not valid...send 400 back to caller.
            //2. Add to database.
            var employeeResponse = new EmployeeResponse
            {
                Id             = new Random().Next(10, 10000),
                Name           = employeeToHire.Name,
                Department     = employeeToHire.Department,
                HireDate       = DateTime.Now,
                StartingSalary = employeeToHire.StartingSalary
            };

            //3. Return a 201 Created status code.
            //4. Include in the response a link to the new resource.
            //5. Usually, send them a copy of what they get with a GET request on the above resource.

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