Ejemplo n.º 1
0
            public async Task Should_Create_NOMAnswer_And_Get_ToValidate_Finally_do_DeleteAsync()
            {
                using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

                //Arrange
                var identityWorkId = Guid.NewGuid();
                var instanceId     = Guid.NewGuid();

                var NOMAnswers = await new NOMAnswerManagerUT().CreateDefaultAsync <NOMAnswer>(identityWorkId, instanceId);

                //Act
                var middlewareManager = new MiddlewareManager <NOMAnswer>(new BaseRecordManager <NOMAnswer>(), new NOMAnswerValidator());

                //Asserts
                //Get
                var result = middlewareManager
                             .GetByIds(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result.Count() > 0);

                //Delete
                middlewareManager.Delete(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId);

                //Get it again to verify if the registry it was deleted
                var result2 = middlewareManager
                              .GetByIds(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result2.Count() == 0);
            }
Ejemplo n.º 2
0
        public void BeforeDelete(List <Guid> lstObjectsToValidate)
        {
            var middlewareManagerDetails = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(),
                                                                                   new OverdraftDetailValidator());
            var overdraftDetails = middlewareManagerDetails.FindByExpression(p => lstObjectsToValidate.Contains(p.OverdraftID), Guid.Empty);

            if (overdraftDetails.Any())
            {
                middlewareManagerDetails.Delete(overdraftDetails.Select(p => p.ID).ToList(), Guid.Empty);
            }
        }
Ejemplo n.º 3
0
        public void BeforeDelete(List <Guid> lstObjectsToValidate)
        {
            if (lstObjectsToValidate.Any())
            {
                var middlewareManager      = new MiddlewareManager <Vacation>(new BaseRecordManager <Vacation>(), this);
                var vacationDaysOffManager = new MiddlewareManager <VacationDaysOff>(new BaseRecordManager <VacationDaysOff>(), new VacationDaysOffValidator());
                var entities = middlewareManager.FindByExpression(p => lstObjectsToValidate.Contains(p.ID), Guid.Empty, new string[] { "VacationDaysOff" });

                var daysOff = entities.SelectMany(p => p.VacationDaysOff).Select(p => p.ID);

                if (daysOff.Any())
                {
                    vacationDaysOffManager.Delete(daysOff.ToList(), Guid.Empty);
                }
            }
        }
        public void BeforeDelete(List <Guid> lstObjectsToValidate)
        {
            //all good
            //validar si ya tiene pagos aplicados
            var middlewareManager = new MiddlewareManager <EmployeeConceptsRelationDetail>(new BaseRecordManager <EmployeeConceptsRelationDetail>(),
                                                                                           new EmployeeConceptsRelationDetailValidator());
            var details = middlewareManager.FindByExpression(p => lstObjectsToValidate.Contains(p.EmployeeConceptsRelationID), Guid.Empty);

            if (details.Any(p => p.ConceptsRelationPaymentStatus == ConceptsRelationPaymentStatus.Applied))
            {
                throw new Exception("No se puede eliminar el crédito, debido a que ya tiene pagos aplicados al mismo. Si lo deseas puedes cambiar el estado del crédito a Inactivo, para que no se aplique.");
            }

            if (details.Any())
            {
                middlewareManager.Delete(details.Select(p => p.ID).ToList(), Guid.Empty);
            }
        }
        /// <summary>
        /// Borra los conceptos de infonavit que no deberían de estar ya, por actualización
        /// </summary>
        /// <param name="lstObjectsToValidate"></param>
        private void DeleteOverdraftConcepts(List <InfonavitMovement> lstObjectsToValidate)
        {
            var middlewareManagerOverdraft = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(),
                                                                               new OverdraftValidator());
            var middlewareManagerOverdraftDetails = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(),
                                                                                            new OverdraftDetailValidator());

            var employeeIds     = lstObjectsToValidate.Select(p => p.EmployeeID);
            var companyID       = lstObjectsToValidate.FirstOrDefault().company;
            var overdraftActive = middlewareManagerOverdraft.FindByExpression(p =>
                                                                              p.PeriodDetail.PeriodStatus == PeriodStatus.Calculating &&
                                                                              employeeIds.Contains(p.EmployeeID), companyID
                                                                              , new string[] { "OverdraftDetails", "OverdraftDetails.ConceptPayment" });

            if (overdraftActive.Any())
            {
                var overdraft = overdraftActive.FirstOrDefault();
                lstObjectsToValidate.ForEach(infonavitMovement =>
                {
                    if (infonavitMovement.InfonavitCreditType == InfonavitCreditType.DiscountFactor_D15)
                    {
                        var detailsIds = overdraft.OverdraftDetails
                                         .Where(p =>
                                                (p.ConceptPayment.Code == 59 || p.ConceptPayment.Code == 16) &&
                                                p.ConceptPayment.ConceptType == ConceptType.DeductionPayment)
                                         .Select(p => p.ID)
                                         .ToList();

                        if (detailsIds.Any())
                        {
                            middlewareManagerOverdraftDetails.Delete(detailsIds, companyID);
                        }
                    }
                    else if (infonavitMovement.InfonavitCreditType == InfonavitCreditType.FixQuota_D16)
                    {
                        var detailsIds = overdraft.OverdraftDetails
                                         .Where(p =>
                                                (p.ConceptPayment.Code == 59 || p.ConceptPayment.Code == 15) &&
                                                p.ConceptPayment.ConceptType == ConceptType.DeductionPayment)
                                         .Select(p => p.ID)
                                         .ToList();

                        if (detailsIds.Any())
                        {
                            middlewareManagerOverdraftDetails.Delete(detailsIds, companyID);
                        }
                    }
                    else if (infonavitMovement.InfonavitCreditType == InfonavitCreditType.Percentage_D59)
                    {
                        var detailsIds = overdraft.OverdraftDetails
                                         .Where(p =>
                                                (p.ConceptPayment.Code == 16 || p.ConceptPayment.Code == 15) &&
                                                p.ConceptPayment.ConceptType == ConceptType.DeductionPayment)
                                         .Select(p => p.ID)
                                         .ToList();

                        if (detailsIds.Any())
                        {
                            middlewareManagerOverdraftDetails.Delete(detailsIds, companyID);
                        }
                    }

                    //Seguro de vivienda infonavit
                    if (!infonavitMovement.IncludeInsurancePayment_D14)
                    {
                        var detailsIds = overdraft.OverdraftDetails
                                         .Where(p =>
                                                (p.ConceptPayment.Code == 14) &&
                                                p.ConceptPayment.ConceptType == ConceptType.DeductionPayment)
                                         .Select(p => p.ID)
                                         .ToList();

                        var conceptIds = overdraft.OverdraftDetails
                                         .Where(p =>
                                                (p.ConceptPayment.Code == 14) &&
                                                p.ConceptPayment.ConceptType == ConceptType.DeductionPayment)
                                         .Select(p => p.ConceptPaymentID)
                                         .ToList();

                        if (detailsIds.Any())
                        {
                            middlewareManagerOverdraftDetails.Delete(detailsIds, companyID);
                        }

                        //Delete employeeConceptRelated
                        var employeeConceptRelatedMiddleware = new MiddlewareManager <EmployeeConceptsRelation>(
                            new BaseRecordManager <EmployeeConceptsRelation>(), new EmployeeConceptsRelationValidator());
                        var employessRelatedToDelete = employeeConceptRelatedMiddleware.FindByExpression(p =>
                                                                                                         p.EmployeeID == overdraft.EmployeeID &&
                                                                                                         conceptIds.Contains(p.ConceptPaymentID), companyID);
                        var employessRelatedToDeleteIds = employessRelatedToDelete.Select(p => p.ID).ToList();
                        employeeConceptRelatedMiddleware.Delete(employessRelatedToDeleteIds, companyID);
                    }
                });
            }
        }