コード例 #1
0
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceID) where T : BaseEntity
        {
            var employerRegistrations = new List <EmployerRegistration>();
            var addressID             = Guid.NewGuid();

            employerRegistrations.Add(new EmployerRegistration()
            {
                ID           = Guid.NewGuid(),
                Active       = true,
                company      = identityWorkId,
                Timestamp    = DateTime.UtcNow,
                InstanceID   = instanceID,
                Description  = "OSCAR KALA HAAK",
                CreationDate = DateTime.Now,
                user         = Guid.NewGuid(),
                Name         = "EmplorerTest",
                StatusID     = 1,

                Code              = "R1723289120",
                RiskClass         = "Risk",
                RiskClassFraction = 0.20m,
                AddressID         = addressID,

                Address = new Schema.Address()
                {
                    ID             = addressID,
                    Active         = true,
                    company        = identityWorkId,
                    Timestamp      = DateTime.UtcNow,
                    InstanceID     = instanceID,
                    Description    = "Direccion Registro Patronal",
                    CreationDate   = DateTime.Now,
                    user           = Guid.NewGuid(),
                    Name           = "Direccion Registro Patronal",
                    StatusID       = 1,
                    ExteriorNumber = "123",
                    FederalEntity  = "Jalisco",
                    InteriorNumber = "145",
                    Municipality   = "Guadalajara",
                    Reference      = "Reference",
                    Street         = "Albert",
                    Suburb         = "Colomos",
                    ZipCode        = "44660",
                }
            });


            var middlewareManager = new MiddlewareManager <EmployerRegistration>(new BaseRecordManager <EmployerRegistration>(), new EmployerRegistrationValidator());
            await middlewareManager.CreateAsync(employerRegistrations, identityWorkId);

            var addressID1 = Guid.NewGuid();
            var payrollCompanyConfiguration = new List <PayrollCompanyConfiguration>();

            payrollCompanyConfiguration.Add(new PayrollCompanyConfiguration()
            {
                ID                  = Guid.NewGuid(),
                Active              = true,
                company             = identityWorkId,
                Timestamp           = DateTime.UtcNow,
                InstanceID          = instanceID,
                user                = Guid.NewGuid(),
                Name                = "Company Config",
                Description         = "Configuration",
                StatusID            = 1,
                AdjustmentPay       = AdjustmentPay_16Days_Febrary.PayCalendarDays,
                CreationDate        = DateTime.UtcNow,
                CurrentExerciseYear = DateTime.UtcNow.Year,
                CurrencyID          = Guid.Parse("57B07610-ED2A-40F5-8093-FA3EAA38B41D"), //pesos
                DeleteDate          = null,
                PaymentDays         = 16m,
                PaymentPeriodicity  = PaymentPeriodicity.Biweekly,
                PeriodInitialDate   = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1),
                StartDate           = new DateTime(DateTime.UtcNow.Year, 1, 1),
                RFC                 = "KAHO641101B39",
                SocialReason        = "OSCAR KALA HAAK",
                CURP                = "KAHO641101HDFLKS06",
                FiscalRegime        = FiscalRegime.FiscalIncorporationPerson,
                SalaryZone          = SalaryZone.ZoneA,
                NonDeducibleFactor  = 0.25M,
                CurrentPeriod       = 1,
                AddressID           = addressID1,
                Address             = new Schema.Address()
                {
                    ID             = addressID1,
                    Active         = true,
                    company        = identityWorkId,
                    Timestamp      = DateTime.UtcNow,
                    InstanceID     = instanceID,
                    Description    = "Direccion Registro Patronal",
                    CreationDate   = DateTime.Now,
                    user           = Guid.NewGuid(),
                    Name           = "Direccion Registro Patronal",
                    StatusID       = 1,
                    ExteriorNumber = "123",
                    FederalEntity  = "Jalisco",
                    InteriorNumber = "145",
                    Municipality   = "Guadalajara",
                    Reference      = "Reference",
                    Street         = "Albert",
                    Suburb         = "Colomos",
                    ZipCode        = "44660",
                }
            });

            var middlewarePayrollCompanyConfigurationManager = new MiddlewareManager <PayrollCompanyConfiguration>(new BaseRecordManager <PayrollCompanyConfiguration>(),
                                                                                                                   new PayrollCompanyConfigurationValidator());
            await middlewarePayrollCompanyConfigurationManager.CreateAsync(payrollCompanyConfiguration, identityWorkId);


            var fileCER = File.ReadAllBytes(Path.Combine(AssemblyDirectory, "fiscal\\cfdi33nom12\\KAHO641101B39.cer"));
            var fileKEY = File.ReadAllBytes(Path.Combine(AssemblyDirectory, "fiscal\\cfdi33nom12\\KAHO641101B39.key"));

            var digitalSign = new DigitalSign.DigitalSign();
            var employerFiscalInformations = new List <EmployerFiscalInformation>();

            var clsCryptoToCreate = new ClsCrypto(
                identityWorkId.ToString().ToLower().Replace("-", ""),
                instanceID.ToString().ToLower().Replace("-", ""),
                instanceID.ToString().ToLower().Replace("-", "").Substring(0, 19));

            var fileCerEncrypted = clsCryptoToCreate.Encrypt(Convert.ToBase64String(fileCER));
            var fileKeyEncrypted = clsCryptoToCreate.Encrypt(Convert.ToBase64String(fileKEY));
            var passEncrypted    = StringCipher.Encrypt("12345678a");

            employerFiscalInformations.Add(new EmployerFiscalInformation()
            {
                ID                = Guid.NewGuid(),
                Active            = true,
                company           = identityWorkId,
                Timestamp         = DateTime.UtcNow,
                InstanceID        = instanceID,
                Description       = "Emplorer FiscalInfoTest",
                CreationDate      = DateTime.Now,
                user              = Guid.NewGuid(),
                Name              = "EmplorerFiscalInfoTest",
                RFC               = payrollCompanyConfiguration.FirstOrDefault().RFC,
                StatusID          = 1,
                CertificateCER    = fileCerEncrypted,
                CertificateKEY    = fileKeyEncrypted,
                CertificatePwd    = passEncrypted,
                CertificateNumber = digitalSign.GetCertificateNumber(fileCER),
                StartDate         = digitalSign.GetExpirationDate(fileCER).Item1,
                EndDate           = digitalSign.GetExpirationDate(fileCER).Item2
            });

            var middlewareManagerFiscalInfo = new MiddlewareManager <EmployerFiscalInformation>(new BaseRecordManager <EmployerFiscalInformation>(),
                                                                                                new EmployerFiscalInformationValidator());
            await middlewareManagerFiscalInfo.CreateAsync(employerFiscalInformations, identityWorkId);


            return(employerRegistrations as List <T>);
        }
コード例 #2
0
        private async Task <EmployerFiscalInformationData> SaveFiscalInformationAsync(EmployerFiscalInformationData data)
        {
            //Decrypt cer and key files
            try
            {
                var employerFiscalInformations = new List <EmployerFiscalInformation>();

                var digitalSign  = new DigitalSign.DigitalSign();
                var requiredData = getRequireData();
                var clsCrypto    = new ClsCrypto(requiredData.Ps, requiredData.IV, requiredData.Salt);

                data.cfb = clsCrypto.Decrypt(data.cfb).Replace("data:application/x-x509-ca-cert;base64,", String.Empty).Replace("data:application/octet-stream;base64,", String.Empty);
                data.kfb = clsCrypto.Decrypt(data.kfb).Replace("data:application/x-x509-ca-cert;base64,", String.Empty).Replace("data:application/octet-stream;base64,", String.Empty);

                if (!String.IsNullOrEmpty(data.cfb) && !String.IsNullOrEmpty(data.kfb))
                {
                    var fileCER = Convert.FromBase64String(data.cfb);
                    var fileKEY = Convert.FromBase64String(data.kfb);

                    //validate Cer and Key
                    digitalSign.validateCerKEYContent(fileCER, fileKEY, data.pfb, data.RFC);

                    var clsCryptoToCreate = new ClsCrypto(
                        SessionModel.CompanyID.ToString().ToLower().Replace("-", ""),
                        SessionModel.InstanceID.ToString().ToLower().Replace("-", ""),
                        SessionModel.InstanceID.ToString().ToLower().Replace("-", "").Substring(0, 19));

                    var certificateCER = clsCryptoToCreate.Encrypt(data.cfb);
                    var certificateKEY = clsCryptoToCreate.Encrypt(data.kfb);
                    var certificatePwd = StringCipher.Encrypt(data.pfb);

                    //Certificate number
                    data.CertificateNumber = digitalSign.GetCertificateNumber(fileCER);

                    //expiration date
                    var resultExpirationDate = digitalSign.GetExpirationDate(fileCER);
                    data.StartDate      = resultExpirationDate.Item1.ToShortDateString();
                    data.ExpirationDate = resultExpirationDate.Item2.ToShortDateString();

                    employerFiscalInformations.Add(new EmployerFiscalInformation()
                    {
                        ID                = data.ID == null ? Guid.NewGuid() : (Guid)data.ID,
                        Active            = true,
                        company           = SessionModel.CompanyID,
                        Timestamp         = DateTime.UtcNow,
                        InstanceID        = SessionModel.InstanceID,
                        Description       = $"InfoFiscal de {data.RFC}",
                        CreationDate      = DateTime.UtcNow,
                        user              = SessionModel.IdentityID,
                        Name              = "InfoFiscal",
                        StatusID          = 1,
                        RFC               = data.RFC,
                        CertificateCER    = certificateCER,
                        CertificateKEY    = certificateKEY,
                        CertificatePwd    = certificatePwd,
                        CertificateNumber = data.CertificateNumber,
                        StartDate         = resultExpirationDate.Item1,
                        EndDate           = resultExpirationDate.Item2
                    });

                    if (data.ID != null)
                    {
                        await clientFiscal.UpdateAsync(employerFiscalInformations, SessionModel.CompanyID);
                    }
                    else
                    {
                        await clientFiscal.CreateAsync(employerFiscalInformations, SessionModel.CompanyID);
                    }

                    data.ID = employerFiscalInformations.FirstOrDefault().ID;
                }
                else
                {
                    throw new CotorraException(3012, "3012", "Es necesario especificar el certificado y el key.", null);
                }
            }
            catch (Exception ex)
            {
                throw new CotorraException(3011, "3011", $"Ocurrió un error al cargar el certificado: {ex.Message}", ex);
            }

            return(data);
        }