public bool UpdateEmployed(EmployedDto request) { if (request.EmployedId == default) { throw new IdCannotNullOrEmptyException(); } var employedIdExist = _repoEmployed .SearchMatching <EmployedEntity>(e => e.EmployedId == request.EmployedId); if (!employedIdExist.Any()) { throw new DontExistIdException(); } var entityUpdate = employedIdExist.FirstOrDefault(); entityUpdate.EmployedCode = request.EmployedCode; entityUpdate.PersonType = request.PersonType; entityUpdate.EmployedPosition = request.EmployedPosition; entityUpdate.AreaId = request.AreaId; entityUpdate.DocumentTypeId = request.DocumentTypeId; entityUpdate.IdentificationNumber = request.IdentificationNumber; entityUpdate.PersonName = request.PersonName; entityUpdate.PersonLastName = request.PersonLastName; entityUpdate.PersonDateOfBirth = request.PersonDateOfBirth; entityUpdate.CreationDate = request.CreationDate; entityUpdate.PersonPhoneNumber = request.PersonPhoneNumber; entityUpdate.PersonEmail = request.PersonEmail; return(_repoEmployed.Update(entityUpdate)); }
public async Task <Guid?> AddArea(AreaRequestDto request) { ValidateRequireFields(request); if (string.IsNullOrEmpty(request.LiableEmployerId.ToString())) { var responseArea = await _repoArea.Insert(_mapper.Map <AreaEntity>(request)).ConfigureAwait(false); return(responseArea.AreaId); } var employedIdExist = _repoEmployed .SearchMatching <EmployedEntity>(employed => employed.EmployedId == request.LiableEmployerId).Any(); if (!employedIdExist) { throw new AreaEmployeIdDontExistException($"El empleado con el id: {request.LiableEmployerId} no existe"); } var employedLiableExist = _repoArea .SearchMatching <AreaEntity>(area => area.LiableEmployerId == request.LiableEmployerId) .Any(); if (employedLiableExist) { throw new AreaLiableAlreadyExistException($"El empleado con el id: {request.LiableEmployerId} ya esta asignado a una area"); } var response = await _repoArea.Insert(_mapper.Map <AreaEntity>(request)).ConfigureAwait(false); return(response.AreaId); }