示例#1
0
        // POST api/EmployeeInfoAPI
        public HttpResponseMessage PostEmployeeInfo(EmployeeInfo employeeinfo)
        {
            // INTERVIEW_TODO: 4. Validate the employee, and return a meaningful error if it is not valid
            // Details:
            // We need to modify the application to ensure that all employees have salary > 0, and a unique EmpNo
            // The user should be notified with a meaningful error message if the request is not valid.
            // The check should be done in the presentation as well as the business layer.
            // Please modify the Create.cshtml file (it contains all the javascript code) to handle the validation logic.
            // Question 1: There are several approaches to solve this, what is the best one for a production application? - Validate at both client and server side.
            // Question 2: How would you change the application UI design to improve the user interaction? -  Changed the input type pf employee number and salary.

            var errorResponse = ValidateEmployeeInfo(employeeinfo);

            if (ModelState.IsValid && string.IsNullOrWhiteSpace(errorResponse))
            {
                _service.InsertEmployee(employeeinfo);
                var response = Request.CreateResponse(HttpStatusCode.Created, employeeinfo);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = employeeinfo.EmpNo }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, errorResponse));
            }
        }