Esempio n. 1
0
        public void AceptanceCriteriesForInsert(CustomerDto customer)
        {
            var NitEntity = _kindOfIdRepo.GetOne <KindOfIdentificationEntity>(x => x.IdentificationName == "Nit").Result;

            var ExistingSameKindIdAndIdNumber   = _repoCustomer.SearchMatching <CustomerEntity>(x => x.IdNumber == customer.IdNumber && x.KindOfIdentificationId == customer.KindOfIdentificationId).Result.Any();
            var ExistingSameNameAndKindOfPerson = _repoCustomer.SearchMatching <CustomerEntity>(x => x.KindOfPerson == customer.KindOfPerson && x.FirstName + x.SecondName + x.FirstLastName + x.SecondLastName == customer.FirstName + customer.SecondName + customer.FirstLastName + customer.SecondLastName).Result.Any();

            if (ExistingSameKindIdAndIdNumber)
            {
                throw new PersonWithSameParametersExistingException("Ya existe una persona con el mismo numero y tipo de identificación");
            }
            if (ExistingSameNameAndKindOfPerson)
            {
                throw new PersonWithSameParametersExistingException("Ya existe una persona con el mismo nombre y razon social");
            }
            if (customer.SignUpDate == default)
            {
                throw new SignUpDateMissingException("Por favor ingrese la fecha de creación");
            }
            if (customer.DateOfBirth == default)
            {
                throw new DateOfBirthMissingException("Por favor ingrese la fecha de nacimiento");
            }
            if (customer.KindOfIdentificationId == NitEntity.KindOfIdentificationId)
            {
                throw new EmployeeWithNitException("El tipo de identificacion de una persona no puede ser Nit");
            }
        }
        public async Task <bool> DeleteKindOfIdentification(KindOfIdentificationDto kindOfId)
        {
            if (kindOfId.IdentificationName == null)
            {
                throw new DeniedDeleteNameNullException("Por favor Ingrese el nombre de la identificacion a eliminar");
            }

            if (kindOfId.IdentificationName.ToUpper() == "CEDULA" || kindOfId.IdentificationName.ToUpper() == "PASAPORTE" || kindOfId.IdentificationName.ToUpper() == "NIT")
            {
                throw new DeleteDeniedKindOfIdImportantException("No puede eliminar una de las identificaciones fundamentales");
            }

            var KindOfIdToDelete = await _kindOfIdRepo.GetOne <KindOfIdentificationEntity>(x => x.KindOfIdentificationId == kindOfId.KindOfIdentificationId).ConfigureAwait(false);

            if (KindOfIdToDelete != null)
            {
                await _kindOfIdRepo.Delete <KindOfIdentificationEntity>(KindOfIdToDelete);

                return(true);
            }
            throw new ArgumentNullException("La identificacion que intenta eliminar no existe");
        }
        public void AceptanceCriteriesForInsert(EmployeeDto employee)
        {
            var NitEntity = _KindOfIdRepo.GetOne <KindOfIdentificationEntity>(x => x.IdentificationName == "Nit").Result;

            var ExistingSameNameAndKindOfPerson = _employeeRepo.SearchMatching <EmployeeEntity>(x => x.KindOfPerson == employee.KindOfPerson && x.FirstName + x.SecondName + x.FirstLastName + x.SecondLastName == employee.FirstName + employee.SecondName + employee.FirstLastName + employee.SecondLastName).Result.Any();
            var ExistingSameKindIdAndIdNumber   = _employeeRepo.SearchMatching <EmployeeEntity>(x => x.IdNumber == employee.IdNumber && x.KindOfIdentificationId == employee.KindOfIdentificationId).Result.Any();
            var ExistingEmployeeCode            = _employeeRepo.SearchMatching <EmployeeEntity>(x => x.EmployeeCode == employee.EmployeeCode).Result.Any();

            if (ExistingSameKindIdAndIdNumber)
            {
                throw new PersonWithSameParametersExistingException("Ya existe una persona con el mismo numero y tipo de identificación");
            }
            if (ExistingEmployeeCode)
            {
                throw new AlreadyExistingEmployeeCodeException("Ya existe un empleado con el mismo codigo");
            }
            if (ExistingSameNameAndKindOfPerson)
            {
                throw new PersonWithSameParametersExistingException("Ya existe una persona con el mismo nombre y razon social");
            }
            if (employee.SignUpDate == default)
            {
                throw new SignUpDateMissingException("Por favor ingrese la fecha de creación");
            }
            if (employee.DateOfBirth == default)
            {
                throw new DateOfBirthMissingException("Por favor ingrese la fecha de nacimiento");
            }
            if (employee.KindOfIdentificationId == NitEntity.KindOfIdentificationId)
            {
                throw new EmployeeWithNitException("El tipo de identificacion de una persona no puede ser Nit");
            }
            if (employee.KindOfPerson == "Juridica")
            {
                throw new JuridicEmployeeException("Un empleado no puede ser juridico");
            }
        }