Esempio n. 1
0
        public IHttpActionResult PostEmployee([FromBody] EmployeeModel model)
        {
            var employee = Mapper.Map <BusinessObjects.Employee>(model);

            bool updated = HumanResourcesService.UpdateEmployee(employee);

            if (!updated)
            {
                return(NotFound());
            }

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateEmployee(int id, [FromBody] EmployeeResource empResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var isEmailUsed = await _service.FindEmployeeByEmail(empResource.Email);

            if (isEmailUsed.Success)
            {
                if (isEmailUsed.Employee.Id != id)
                {
                    return(Conflict("Esse email já foi utilizado."));
                }
            }
            var employee = _converter.ConvertToModel(empResource);
            var result   = await _service.UpdateEmployee(id, employee);

            if (!result.Success)
            {
                return(NotFound(result.Message));
            }
            return(Ok(result.Employee));
        }