Example #1
0
        public IActionResult AddEmployee(EmployeeCreateResult employeeCreate, IEmployeeService service)
        {
            if (employeeCreate == null)
            {
                return(BadRequest());
            }

            var employeeEntity = employeeCreate.Adapt <Employee>();

            if (!service.Add(employeeEntity))
            {
                throw new Exception($"Creation of employee failed .. !!!!");
            }

            var employeeToReturn = employeeEntity.Adapt <EmployeeResult>();

            return(CreatedAtRoute(nameof(GetEmployeeDetails), new { id = employeeToReturn.Id }, employeeToReturn));
        }
Example #2
0
        public async Task <IHttpActionResult> Post([FromBody] Employee employee)
        {
            if (ModelState.IsValid)
            {
                EmployeeCreateResult result = await _empService.CreateEmployee(employee);

                if (result.Succeeded)
                {
                    return(Created <EmployeeCreateResult>(Url.Link("GetEmployee", new { id = result.Employee.EmployeeId }), result));
                }
                else
                {
                    if (result.UserAlreadyExists)
                    {
                        return(Conflict()); //409
                    }

                    return(InternalServerError());
                }
            }

            return(BadRequest(ModelState));
        }