Ejemplo n.º 1
0
        public IActionResult PartiallyUpdateEmployeeForCompany(Guid companyId, Guid id,
                                                               [FromBody] JsonPatchDocument <EmployeeForUpdateDto> patchDoc)
        {
            if (patchDoc == null)
            {
                logger.LogError("patchDoc object sent from client is null.");
                return(BadRequest("patchDoc object is null"));
            }
            if (repository.Company.GetCompany(companyId, false) == null)
            {
                return(NotFound());
            }
            var employee = repository.Employee.GetCompanyEmployee(companyId, id, true);

            if (employee == null)
            {
                return(NotFound());
            }
            var employeeForUpdateDto = mapper.Map <EmployeeForUpdateDto>(employee);

            //patchDoc.ApplyTo(employeeForUpdateDto,ModelState);
            //if (!TryValidateModel(employeeForUpdateDto))
            //{
            //    return ValidationProblem(ModelState);
            //}


            var thisActionResultWontBeNullOnValidationProblem = patchDoc.ApplyToAndCheckModel(employeeForUpdateDto, this);

            if (thisActionResultWontBeNullOnValidationProblem != null)
            {
                return(thisActionResultWontBeNullOnValidationProblem);
            }

            mapper.Map(employeeForUpdateDto, employee);
            repository.Save();
            return(Ok());
        }