Ejemplo n.º 1
0
        public void ValidateIfExistTheSameIdentification(EmployedDto request, IEnumerable <EmployedEntity> people)
        {
            var validateByIdentificactionNumber = people.Where(x =>
                                                               x.IdentificationNumber == request.IdentificationNumber && x.DocumentTypeId == request.DocumentTypeId);

            if (validateByIdentificactionNumber.Any())
            {
                throw new AlreadyExistException($"ya existe alguien el mismo numero de indentificación y tipo de documento: {request.IdentificationNumber}");
            }
        }
Ejemplo n.º 2
0
        public void ValidateDontHaveDocumentTypeNit(EmployedDto request, IEnumerable <EmployedEntity> people)
        {
            var documentIdExist = _repoDocumentType
                                  .SearchMatching <DocumentTypeEntity>(dt => dt.DocumentTypeId == request.DocumentTypeId);

            if (!documentIdExist.Any())
            {
                throw new NoExistDocumentTypeException();
            }
            var documentIsNit = documentIdExist.Where(x => x.DocumentType.ToLower() == "nit");

            if (documentIsNit.Any())
            {
                throw new CannotBeCorporatePersonException("Una persona no puede tener un tipo de documento Nit");
            }
        }
Ejemplo n.º 3
0
        public async Task <Guid> AddEmployed(EmployedDto request)
        {
            ValidateRequireFields(request);
            var employees = _repoEmployed.GetAll <EmployedEntity>();

            ValidateIfExistTheSameIdentification(request, employees);
            ValidateIfExistSameName(request, employees);
            ValidateDontHaveDocumentTypeNit(request, employees);
            ValidateCannotBeCorporatePerson(request, employees);
            ValidateHaveUniqueCode(request, employees);
            ValidateAsginatedArea(request, employees);

            var areaExist = _repoArea.SearchMatching <AreaEntity>(a => a.AreaId == request.AreaId).Any();

            if (!areaExist)
            {
                throw new NotExistAreaException($"No existe el area del siguiente Id: { request.AreaId}");
            }
            var response = await _repoEmployed.Insert(_mapper.Map <EmployedEntity>(request)).ConfigureAwait(false);

            return(response.EmployedId);
        }
Ejemplo n.º 4
0
        public void Throw_DontExistIdException_when_id_it_isnt()
        {
            var employedRepoMock = new Mock <IEmployedRepository>();

            employedRepoMock
            .Setup(x => x.SearchMatching(It.IsAny <Expression <Func <EmployedEntity, bool> > >()))
            .Returns(new List <EmployedEntity>());
            var service = new ServiceCollection();

            service.AddTransient(_ => employedRepoMock.Object);
            service.ConfigurePeopleManagementService(new DbSettings());
            var provider    = service.BuildServiceProvider();
            var employedSvc = provider.GetRequiredService <IEmployedService>();

            var newEmployed = new EmployedDto
            {
                EmployedId   = Guid.NewGuid(),
                EmployedCode = Guid.NewGuid()
            };

            Assert.Throws <DontExistIdException>(() => employedSvc.UpdateEmployed(newEmployed));
        }
Ejemplo n.º 5
0
 private static void ValidateRequireFields(EmployedDto request)
 {
     if (request.EmployedCode == default)
     {
         throw new EmployedCodeNotDefinedException();
     }
     if (request.AreaId == Guid.Empty)
     {
         throw new AreaIdNotDefinedException();
     }
     if (request.DocumentTypeId == Guid.Empty)
     {
         throw new DocumentTypeIdNotDefinedException();
     }
     if (request.PersonDateOfBirth == default)
     {
         throw new DateOfBirthNotDefinedException();
     }
     if (request.CreationDate == default)
     {
         throw new CreationDateNotDefinedException();
     }
 }
Ejemplo n.º 6
0
 public EmployedResponseDto UpdateEmployed(EmployedDto request) =>
 _employedFacade.UpdateEmployed(request);
Ejemplo n.º 7
0
 public async Task <EmployedResponseDto> CreateEmployed(EmployedDto request) =>
 await _employedFacade.CreateEmployed(request).ConfigureAwait(false);