public async Task SalaryAdjustment_Success_HappyPath_2()
        {
            using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
            Guid identityWorkId = Guid.NewGuid();
            Guid instanceID     = Guid.NewGuid();

            try
            {
                var employee = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(
                    identityWorkId, instanceID);

                var middlewareManagerPeriodDetail = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator());
                var periodDetails = await middlewareManagerPeriodDetail.FindByExpressionAsync(p =>
                                                                                              p.InstanceID == instanceID, identityWorkId, new string[] { "Period", "Period.PeriodType" });


                Guid sbcID                = Guid.NewGuid();
                var  creationDate         = DateTime.Now;
                EmployeeSBCAdjustment sbc = BuildEmployeeSBCAdjustment(sbcID, Guid.NewGuid(), identityWorkId, instanceID, creationDate, employee.FirstOrDefault().ID, 123.23M, 123.23M, 123.23M);


                EmployeeSalaryIncrease employeeSalaryIncrease = new EmployeeSalaryIncrease()
                {
                    Active                  = true,
                    company                 = identityWorkId,
                    CreationDate            = creationDate,
                    DailySalary             = 145.65M,
                    DeleteDate              = null,
                    Description             = "",
                    EmployeeID              = employee.FirstOrDefault().ID,
                    ID                      = Guid.NewGuid(),
                    user                    = Guid.NewGuid(),
                    InstanceID              = instanceID,
                    ModificationDate        = periodDetails.OrderBy(p => p.InitialDate).FirstOrDefault().InitialDate.AddMonths(2),
                    Name                    = "",
                    StatusID                = 1,
                    Timestamp               = DateTime.Now,
                    EmployeeSBCAdjustment   = sbc,
                    EmployeeSBCAdjustmentID = sbc.ID
                };


                var middlewareManager = new MiddlewareManager <EmployeeSalaryIncrease>(new BaseRecordManager <EmployeeSalaryIncrease>());


                await middlewareManager.CreateAsync(new List <EmployeeSalaryIncrease>() { employeeSalaryIncrease }, identityWorkId);
            }
            catch (CotorraException ex)
            {
                Assert.True(true, "No debió de pasar");
            }
            catch
            {
                Assert.True(true, "No debió de pasar");
            }
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : BaseEntity
        {
            var AnualIncomeTaxs = new MemoryStorageContext().GetDefaultAnualIncomeTax(identityWorkId, instanceId, Guid.Empty);

            var middlewareManager = new MiddlewareManager <AnualIncomeTax>(new BaseRecordManager <AnualIncomeTax>(),
                                                                           new AnualIncomeTaxValidator());
            await middlewareManager.CreateAsync(AnualIncomeTaxs, identityWorkId);

            return(AnualIncomeTaxs as List <T>);
        }
Exemple #3
0
        public async Task <Employee> UpdateEmployeeDailySalary(Employee employee, decimal amount, Guid identityWorkId)
        {
            employee.DailySalary = amount;
            var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());
            await middlewareManager.UpdateAsync(new List <Employee> {
                employee
            }, identityWorkId);

            return(employee);
        }
Exemple #4
0
        private async Task <List <PayrollCompanyConfiguration> > getPayrollCompanyConfigurationAsync(PreviewTransformParams previewTransformParams)
        {
            var middlewarePayrollCompanyConfigurationManager = new MiddlewareManager <PayrollCompanyConfiguration>(new BaseRecordManager <PayrollCompanyConfiguration>(),
                                                                                                                   new PayrollCompanyConfigurationValidator());
            var payrollCompanyConfiguration = await middlewarePayrollCompanyConfigurationManager.FindByExpressionAsync(p =>
                                                                                                                       p.InstanceID == previewTransformParams.InstanceID && p.Active,
                                                                                                                       previewTransformParams.IdentityWorkID);

            return(payrollCompanyConfiguration);
        }
Exemple #5
0
            public async Task Should_Get_ATSPhases()
            {
                using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
                //Act
                var middlewareManager = new MiddlewareManager <NOMEvaluationPhase>(new BaseRecordManager <NOMEvaluationPhase>(), new NOMEvaluationPhaseValidator());
                var ATS = await middlewareManager.FindByExpressionAsync(x => x.NOMEvaluationSurveyID ==
                                                                        Guid.Parse("6EC14905-F634-418F-B0D2-EF2F315835E8") && x.Active == true, Guid.Empty);

                Assert.True(ATS.Any());
            }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceID)
        {
            var SGDFLimitsLst = new List <SGDFLimits>();

            SGDFLimitsLst.AddRange(new MemoryStorageContext().GetDefaultSGDFLimits(identityWorkId, instanceID, Guid.Empty));

            var middlewareManager = new MiddlewareManager <SGDFLimits>(new BaseRecordManager <SGDFLimits>(), new SGDFLimitsValidator());
            await middlewareManager.CreateAsync(SGDFLimitsLst, identityWorkId);

            return(SGDFLimitsLst as List <T>);
        }
        public async Task <NOMSurveyReply> GetAsync(string token, Guid identityWorkID)
        {
            var  decode = HttpUtility.UrlDecode(token);
            Guid id     = Guid.Parse(StringCipher.Decrypt(decode));

            var middlewareManager = new MiddlewareManager <NOMSurveyReply>(new BaseRecordManager <NOMSurveyReply>(), new NOMSurveyReplyValidator());

            var resultPrevious = await middlewareManager.FindByExpressionAsync(p => p.ID == id, identityWorkID, new string[] { "NOMAnswer" });

            return(resultPrevious.FirstOrDefault());
        }
        public async Task DeleteAsync(List <Guid> id, Guid identityWorkID)
        {
            var nmAnswerMiddlewareManager = new MiddlewareManager <NOMAnswer>(new BaseRecordManager <NOMAnswer>(), new NOMAnswerValidator());

            var answers = await nmAnswerMiddlewareManager.FindByExpressionAsync(p => id.Contains(p.NOMSurveyReplyID), identityWorkID);

            var middlewareManager = new MiddlewareManager <NOMSurveyReply>(new BaseRecordManager <NOMSurveyReply>(), new NOMSurveyReplyValidator());
            await nmAnswerMiddlewareManager.DeleteAsync(answers.Select(p => p.ID).ToList(), identityWorkID);

            await middlewareManager.DeleteAsync(id, identityWorkID);
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceID)
        {
            var IMSSWorkRiskTableLst = new List <IMSSWorkRisk>();

            IMSSWorkRiskTableLst.AddRange(new MemoryStorageContext().GetDefaultIMSSWorkRisk(identityWorkId, instanceID, Guid.Empty));

            var middlewareManager = new MiddlewareManager <IMSSWorkRisk>(new BaseRecordManager <IMSSWorkRisk>(), new IMSSWorkRiskValidator());
            await middlewareManager.CreateAsync(IMSSWorkRiskTableLst, identityWorkId);

            return(IMSSWorkRiskTableLst as List <T>);
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : BaseEntity
        {
            var nOMSurveyReplyResult = (await new NOMSurveyReplyManagerUT().CreateDefaultAsync <NOMSurveyReplyResult>(identityWorkId, instanceId)).FirstOrDefault();

            var NOMAnswers        = BuildAnswers(identityWorkId, instanceId, nOMSurveyReplyResult.NOMSurveyReply.ID);
            var middlewareManager = new MiddlewareManager <NOMAnswer>(new BaseRecordManager <NOMAnswer>(), new NOMAnswerValidator());

            middlewareManager.Create(NOMAnswers, identityWorkId);

            return(NOMAnswers as List <T>);
        }
Exemple #11
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);
            }
        }
Exemple #12
0
        public void BeforeDelete(List <Guid> lstObjectsToValidate)
        {
            var middlewareManagerEmployee = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());

            if (middlewareManagerEmployee.FindByExpression(p =>
                                                           p.Active == true &&
                                                           lstObjectsToValidate.Contains(p.EmployerRegistrationID.Value), Guid.Empty).Any())
            {
                throw new CotorraException(4005, "4005",
                                           $"El registro patronal no se puede eliminar por que tiene colaboradores asignados.", null);
            }
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : BaseEntity
        {
            var WorkCenters = new List <WorkCenter>();

            WorkCenters.Add(BuildT <WorkCenter>(identityWorkId, instanceId));

            var middlewareManager = new MiddlewareManager <WorkCenter>(new BaseRecordManager <WorkCenter>(),
                                                                       new WorkCenterValidator());
            await middlewareManager.CreateAsync(WorkCenters, identityWorkId);

            return(WorkCenters as List <T>);
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceID)
        {
            var settlementList = new List <SettlementCatalog>();

            settlementList.AddRange(new MemoryStorageContext().GetDefaultSettlementCatalogTable(identityWorkId, instanceID, Guid.Empty));

            var middlewareManager = new MiddlewareManager <SettlementCatalog>(new BaseRecordManager <SettlementCatalog>(),
                                                                              new SettlementCatalogValidator());
            await middlewareManager.CreateAsync(settlementList, identityWorkId);

            return(settlementList as List <T>);
        }
Exemple #15
0
        public object BeforeDelete(List <Guid> lstObjectsToValidate, Guid identityWorkID)
        {
            //Desaplicar los ajustes de salario del periodo actual (si aplica)
            BeforeDeleteCommon(lstObjectsToValidate);


            var toDelete = MiddlewareManager.FindByExpressionAsync(x => lstObjectsToValidate.Contains(x.ID) && x.Active, Guid.Empty).Result;

            var sbcToDelete = _middlewareManagerSBCAdjustment.FindByExpression(x => toDelete.Select(y => y.EmployeeSBCAdjustmentID).Contains(x.ID), toDelete.FirstOrDefault().company);

            return(sbcToDelete);
        }
        public async Task <HistoricEmployeeSalaryAdjustment> UpdateModificationDateAsync(Guid employeeID, DateTime modifiedDate,
                                                                                         Guid identityWorkID)
        {
            var middlewareHistoricAdjustmentManager = new MiddlewareManager <HistoricEmployeeSalaryAdjustment>
                                                          (new BaseRecordManager <HistoricEmployeeSalaryAdjustment>(), new HistoricEmployeeSalaryAdjustmentValidator());
            var historics = await middlewareHistoricAdjustmentManager.FindByExpressionAsync(p => p.EmployeeID == employeeID, identityWorkID);

            historics.FirstOrDefault().ModificationDate = modifiedDate;
            await middlewareHistoricAdjustmentManager.UpdateAsync(historics, identityWorkID);

            return(historics.FirstOrDefault());
        }
Exemple #17
0
        /// <summary>
        /// Payroll authorization
        /// </summary>
        /// <returns></returns>
        public async Task <List <Overdraft> > AuthorizationAsync(AuthorizationParams authorizationParams)
        {
            List <Overdraft> overdraftToCalculate = null;

            try
            {
                //VerifyPeriod - Si el periodo detalle siguiente no existe (porke fue el último)
                //habilitar el siguiente año
                await VerifyPeriod(authorizationParams);

                using (var connection = new SqlConnection(ConnectionManager.ConfigConnectionString))
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        await connection.OpenAsync();
                    }

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "AuthorizeOverdraft";
                        command.Parameters.AddWithValue("@PeriodDetailId", authorizationParams.PeriodDetailIDToAuthorize);
                        command.Parameters.AddWithValue("@InstanceId", authorizationParams.InstanceID);
                        command.Parameters.AddWithValue("@company", authorizationParams.IdentityWorkID);
                        command.Parameters.AddWithValue("@user", authorizationParams.user);

                        //Execute SP de autorización
                        await command.ExecuteNonQueryAsync();
                    }
                }

                //Encontrar los nuevos sobre recibos para hacerles el cálculo
                var periodDetailManager = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator());
                var periodDetail        = await periodDetailManager.FindByExpressionAsync(p =>
                                                                                          p.PeriodStatus == PeriodStatus.Calculating,
                                                                                          authorizationParams.IdentityWorkID);

                var lstPeriodIds = periodDetail.Select(p => p.PeriodID);

                //11. Calculation overdrafts (Fire and Forget)
                await new OverdraftCalculationManager().CalculationFireAndForgetByPeriodIdsAsync(lstPeriodIds, authorizationParams.IdentityWorkID,
                                                                                                 authorizationParams.InstanceID, authorizationParams.user);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Ocurrió un error al autorizar la nómina: {ex.ToString()}");
                throw new CotorraException(70000, "70000", "Ocurrió un error al autorizar la nómina", ex);
            }


            return(overdraftToCalculate);
        }
        public async Task Authorization_Should_Authorize()
        {
            using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            var identityWorkId = Guid.NewGuid();
            var instanceID     = Guid.NewGuid();

            var employee = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceID);

            var middlewareManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator());
            var overdraftDetails  = await middlewareManager.FindByExpressionAsync(p => p.InstanceID == instanceID && p.ConceptPayment.Name == "Sueldo", identityWorkId,
                                                                                  new string[] { "Overdraft" });

            var randomValue = new Random(15000);

            for (int i = 0; i < overdraftDetails.Count; i++)
            {
                overdraftDetails[i].Amount     = Convert.ToDecimal(randomValue.NextDouble());
                overdraftDetails[i].Taxed      = Convert.ToDecimal(randomValue.NextDouble());
                overdraftDetails[i].Exempt     = Convert.ToDecimal(randomValue.NextDouble());
                overdraftDetails[i].IMSSTaxed  = Convert.ToDecimal(randomValue.NextDouble());
                overdraftDetails[i].IMSSExempt = Convert.ToDecimal(randomValue.NextDouble());
            }

            var middlewareDetailManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator());
            await middlewareDetailManager.UpdateAsync(overdraftDetails, identityWorkId);

            var authManager = new AuthorizationManager();
            var authParams  = new AuthorizationParams()
            {
                IdentityWorkID            = identityWorkId,
                InstanceID                = instanceID,
                PeriodDetailIDToAuthorize = overdraftDetails.FirstOrDefault().Overdraft.PeriodDetailID
            };

            await authManager.AuthorizationAsync(authParams);

            var middlewareHistoricAccumulatedEmployeeManager = new MiddlewareManager <HistoricAccumulatedEmployee>(new BaseRecordManager <HistoricAccumulatedEmployee>(),
                                                                                                                   new HistoricAccumulatedEmployeeValidator());

            //Total de acumulados por empleado
            var resultHistoric = await middlewareHistoricAccumulatedEmployeeManager.GetAllAsync(identityWorkId, instanceID, new string[] { "AccumulatedType" });

            Assert.True(resultHistoric.Count == 33);

            //Overdraft after authorization
            var overdraftDetailsAfter = await middlewareManager.FindByExpressionAsync(p => p.Overdraft.EmployeeID == employee.FirstOrDefault().ID,
                                                                                      identityWorkId, new string[] { "Overdraft" });

            Assert.True(overdraftDetailsAfter.FirstOrDefault().Overdraft.PeriodDetailID != overdraftDetails.FirstOrDefault().Overdraft.PeriodDetailID);
        }
            public async Task ShouldFailWhen2ValuesAreBadSending2Objects()
            {
                using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

                //Arrange
                var Workshifts     = new List <Workshift>();
                var identityWorkId = Guid.NewGuid();

                Workshifts.Add(new Workshift()
                {
                    ID           = Guid.NewGuid(),
                    Active       = true,
                    company      = identityWorkId,
                    Timestamp    = DateTime.UtcNow,
                    InstanceID   = Guid.NewGuid(),
                    Description  = "Turno mixto",
                    CreationDate = DateTime.Now,
                    Name         = "",
                    StatusID     = 1,
                    Hours        = 49
                });

                Workshifts.Add(new Workshift()
                {
                    ID           = Guid.NewGuid(),
                    Active       = true,
                    company      = identityWorkId,
                    Timestamp    = DateTime.UtcNow,
                    InstanceID   = Guid.NewGuid(),
                    Description  = "Turno mixto",
                    CreationDate = DateTime.Now,
                    Name         = "",
                    StatusID     = 1,
                    Hours        = 49
                });

                //Act
                var middlewareManager = new MiddlewareManager <Workshift>(new BaseRecordManager <Workshift>(), new WorkshiftValidator());

                try
                {
                    await middlewareManager.CreateAsync(Workshifts, identityWorkId);
                }
                catch (CotorraException ex)
                {
                    var res = ex.ValidationInfo;
                    Assert.NotEmpty(res);
                    Assert.Equal(8001, ex.ErrorCode);
                }
            }
        public async Task <AreaDTO> Post(Guid instanceID, Guid userID, Guid identityWorkID, AreaValidator validator, IMapper mapper,
                                         AreaDTO AreaDTO)
        {
            Area dep = new Area();

            mapper.Map(AreaDTO, dep);
            dep.InstanceID = instanceID;
            dep.CompanyID  = identityWorkID;

            var mgr = new MiddlewareManager <Area>(new BaseRecordManager <Area>(), validator);
            await mgr.CreateAsync(new List <Area>() { dep }, identityWorkID);

            return(AreaDTO);
        }
Exemple #21
0
        public async Task <DepartmentDTO> Post(Guid instanceID, Guid userID, Guid identityWorkID, DepartmentValidator validator, IMapper mapper,
                                               DepartmentDTO departmentDTO)
        {
            Department dep = new Department();

            mapper.Map(departmentDTO, dep);
            dep.InstanceID = instanceID;
            dep.CompanyID  = identityWorkID;

            var mgr = new MiddlewareManager <Department>(new BaseRecordManager <Department>(), validator);
            await mgr.CreateAsync(new List <Department>() { dep }, identityWorkID);

            return(departmentDTO);
        }
Exemple #22
0
        public void AfterCreateUpdate(List <EmployeeSalaryIncrease> lstObjectsToValidate)
        {
            var instanceID   = lstObjectsToValidate.FirstOrDefault().InstanceID;
            var companyID    = lstObjectsToValidate.FirstOrDefault().company;
            var user         = lstObjectsToValidate.FirstOrDefault().user;
            var employeesIds = lstObjectsToValidate.Select(p => p.EmployeeID);

            //Get Employees
            var middlewareManagerEmployee = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());
            var employees = middlewareManagerEmployee.FindByExpression(p =>
                                                                       p.InstanceID == instanceID &&
                                                                       employeesIds.Contains(p.ID), companyID);

            //PeriodTypes of Employees
            var periodTypeIds = employees.Select(p => p.PeriodTypeID);

            //Get Period Details
            var middlewareManagerPD = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator());
            var periodDetails       = middlewareManagerPD.FindByExpression(p =>
                                                                           p.InstanceID == instanceID &&
                                                                           p.PeriodStatus == PeriodStatus.Calculating &&
                                                                           periodTypeIds.Contains(p.Period.PeriodTypeID),
                                                                           companyID);

            //Modify directly to calcuting period
            foreach (var periodDetail in periodDetails)
            {
                using (var connection = new SqlConnection(
                           ConnectionManager.ConfigConnectionString))
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "ApplySalaryAdjustments";
                        command.Parameters.AddWithValue("@PeriodDetailId", periodDetail.ID);
                        command.Parameters.AddWithValue("@InstanceId", instanceID);
                        command.Parameters.AddWithValue("@company", companyID);
                        command.Parameters.AddWithValue("@user", user);

                        //Execute SP de autorización
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
Exemple #23
0
        public void BeforeDelete(List <Guid> lstObjectsToValidate)
        {
            var employeeSalaryIncreaseMiddlewareManager = new MiddlewareManager <EmployeeSalaryIncrease>(new BaseRecordManager <EmployeeSalaryIncrease>(), new EmployeeSalaryIncreaseValidator());

            if (employeeSalaryIncreaseMiddlewareManager.FindByExpression(p => lstObjectsToValidate.Contains(p.EmployeeSBCAdjustmentID),
                                                                         Guid.Empty).Any())
            {
                throw new CotorraException(6901, "6901", "No se puede eliminar la modificación de SBC porque fue creado desde un incremento de salario," +
                                           " elimina el aumento de salario relacionado.", null);
            }

            //Desaplicar los ajustes de salario del periodo actual (si aplica)
            BeforeDeleteCommon(lstObjectsToValidate);
        }
Exemple #24
0
        private void ValidateInDate(List <Incident> lstObjectsToValidate)
        {
            VacationInhabilityIncidentHelperValidator helperValidator = new VacationInhabilityIncidentHelperValidator();
            var employeesIDs = lstObjectsToValidate.Select(x => x.EmployeeID);

            var inhabilityManager = new MiddlewareManager <Inhability>(new BaseRecordManager <Inhability>(), new InhabilityValidator());
            var vacationManager   = new MiddlewareManager <Vacation>(new BaseRecordManager <Vacation>(), new VacationValidator());

            var orderListInitialDate = lstObjectsToValidate.Select(x => x.Date).OrderBy(p => p).FirstOrDefault();
            var inhabilities         = inhabilityManager.FindByExpression(x => (x.InitialDate >= orderListInitialDate || x.InitialDate.AddDays(x.AuthorizedDays - 1) >= orderListInitialDate) && employeesIDs.Contains(x.EmployeeID), Guid.Empty, new string[] { });
            var vacations            = vacationManager.FindByExpression(x => x.InitialDate >= orderListInitialDate && employeesIDs.Contains(x.EmployeeID), Guid.Empty, new string[] { });

            helperValidator.ValidateInDate(vacations, inhabilities, lstObjectsToValidate);
        }
Exemple #25
0
        public async Task ATS_Result_should_be_one_when_answer_phase_1_is_1_and_answer_1_phase_2_is_1()
        {
            using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            //Arrange
            var identityWorkId     = Guid.NewGuid();
            var instanceId         = Guid.NewGuid();
            var employeeId         = Guid.NewGuid();
            var periodId           = Guid.NewGuid();
            var evaluationSurveyId = Guid.Parse("6EC14905-F634-418F-B0D2-EF2F315835E8");//ATS
            var middlewareManager  = new NOMSurveyManager();

            var nomSurveyReply = BuildNomSurveyReply(identityWorkId, instanceId, employeeId, periodId,
                                                     evaluationSurveyId);
            var answerPhase1 = new NOMAnswerManagerUT().BuildAnswer(identityWorkId, instanceId, nomSurveyReply.ID);
            var answerPhase2 = new NOMAnswerManagerUT().BuildAnswer(identityWorkId, instanceId, nomSurveyReply.ID);
            var nomEvaluationPhaseManager = new MiddlewareManager <NOMEvaluationPhase>(new BaseRecordManager <NOMEvaluationPhase>(), new NOMEvaluationPhaseValidator());

            var aTSPhases = await nomEvaluationPhaseManager.FindByExpressionAsync(x => x.NOMEvaluationSurveyID ==
                                                                                  evaluationSurveyId && x.Active == true, Guid.Empty);

            var listATSPhasesIDs   = aTSPhases.Select(x => x.ID);
            var PhaseI             = aTSPhases.FirstOrDefault(x => x.Number == 1);
            var PhaseII            = aTSPhases.FirstOrDefault(x => x.Number == 2);
            var questionMiddleWare = new MiddlewareManager <NOMEvaluationQuestion>(new BaseRecordManager <NOMEvaluationQuestion>(), new NOMEvaluationQuestionValidator());
            var aTSQuestions       = questionMiddleWare.FindByExpression(e => listATSPhasesIDs.Contains(e.NOMEvaluationPhaseID),
                                                                         Guid.Empty);
            var phaseIATSQuestions  = questionMiddleWare.FindByExpression(e => e.Active && e.NOMEvaluationPhaseID == PhaseI.ID, Guid.Empty);
            var phaseIIATSQuestions = questionMiddleWare.FindByExpression(e => e.Active && e.NOMEvaluationPhaseID == PhaseII.ID, Guid.Empty);


            answerPhase1.NOMEvaluationQuestionID = phaseIATSQuestions.FirstOrDefault().ID;
            answerPhase1.Value = 1;

            answerPhase2.NOMEvaluationQuestionID = phaseIIATSQuestions.FirstOrDefault().ID;
            answerPhase2.Value = 1;

            //Act
            var processed = middlewareManager.ProcessFinalizationATS(nomSurveyReply, new List <NOMAnswer>()
            {
                answerPhase1, answerPhase2
            }, aTSQuestions, aTSPhases);


            //Arrange
            Assert.NotNull(processed);
            Assert.Equal(1, processed.Result);
            Assert.Equal(EvaluationStateType.Answered, processed.EvaluationState);
        }
            public async Task Should_Create_Overdraft_And_Get_ToValidate_Finally_do_Delete()
            {
                var txOptions = new System.Transactions.TransactionOptions();

                txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;

                using var scope = new TransactionScope(TransactionScopeOption.Required, txOptions, TransactionScopeAsyncFlowOption.Enabled);

                //Act
                Guid identityWorkId = Guid.NewGuid();
                Guid instanceId     = Guid.NewGuid();

                var middlewareManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(),
                                                                          new OverdraftValidator());
                var overdr = await middlewareManager.FindByExpressionAsync(p =>
                                                                           p.ID == Guid.Parse("24062420-7C73-4453-B837-A9B25AC26595"), identityWorkId,
                                                                           new string[] { "OverdraftDetails" });

                var detail = overdr.FirstOrDefault().OverdraftDetails
                             .Where(p => p.ID == Guid.Parse("c1314de9-13cf-4531-8641-23b04a4ce187"));

                var middlewareManagerDetail = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(),
                                                                                      new OverdraftDetailValidator());
                var detail2 = await middlewareManagerDetail.FindByExpressionAsync(p => p.ID == Guid.Parse("c1314de9-13cf-4531-8641-23b04a4ce187"), identityWorkId);

                var overdrafts = await new OverdraftManagerUT().CreateDefaultOverdraftAsync(identityWorkId, instanceId);

                //Asserts
                //Get
                var result = await middlewareManager
                             .GetByIdsAsync(overdrafts.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result.Any());

                //Delete
                var middlewareOverdraftDetailManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator());

                await middlewareOverdraftDetailManager.DeleteAsync(overdrafts.SelectMany(p => p.OverdraftDetails).Select(p => p.ID).ToList(), identityWorkId);

                await middlewareManager.DeleteAsync(overdrafts.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result.FirstOrDefault().ID == overdrafts.FirstOrDefault().ID);

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

                Assert.False(result2.Any());
            }
Exemple #27
0
            public async Task Should_Change_Status_To_UnregisteredUsingClient()
            {
                var txOptions = new System.Transactions.TransactionOptions();

                txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;

                using var scope = new TransactionScope(TransactionScopeOption.Required, txOptions, TransactionScopeAsyncFlowOption.Enabled);

                //Act
                Guid identityWorkId    = Guid.NewGuid(); //Guid.Parse("7535C4E6-4712-4DD6-955D-FCA86E054D49");
                Guid instanceId        = Guid.NewGuid(); //Guid.Parse("33D7CA50-39E9-4B14-B482-5FCBEC07E8DB");
                var  employees         = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, randomValues: true);
                var  middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());

                //Asserts

                //Get
                var result = await middlewareManager
                             .GetByIdsAsync(employees.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result.Any());
                var employeeFromDB = result.FirstOrDefault();

                Assert.Equal(CotorriaStatus.Active, employeeFromDB.LocalStatus);
                Assert.Equal(DateTime.Now.Date, employeeFromDB.LastStatusChange.Date);


                //Set inactive
                DateTime?unregisteredDate = DateTime.Now.AddDays(1);
                var      employeeId       = employeeFromDB.ID;

                var statusClient = new StatusClient <Employee>("", ClientConfiguration.ClientAdapter.Local);
                await statusClient.SetUnregistered(new List <Guid>() { employeeId }, identityWorkId, unregisteredDate);

                //Asserts

                //GetAggain
                result = await middlewareManager
                         .GetByIdsAsync(employees.Select(p => p.ID).ToList(), identityWorkId);

                Assert.True(result.Any());
                employeeFromDB = result.FirstOrDefault();

                //Asserts

                Assert.Equal(CotorriaStatus.Unregistered, employeeFromDB.LocalStatus);
                Assert.Equal(DateTime.Now.Date, employeeFromDB.LastStatusChange.Date);
                Assert.Equal(unregisteredDate.GetValueOrDefault().Date, employeeFromDB.UnregisteredDate.GetValueOrDefault().Date);
            }
Exemple #28
0
        public async Task DispatchAsync(Guid actionID, Guid idRegister)
        {
            var middlewareManager = new MiddlewareManager <Action>(new BaseRecordGeneralManager <Action>(), new ActionValidator());


            var action = (await middlewareManager
                          .FindByExpressionAsync(p => p.ID == actionID && p.Active == true, Guid.Empty, new string[]
                                                 { "ActionSubscriptions" })).FirstOrDefault();

            IDataResolver dataResolver = DataResolverFactory.GetResolver(action);

            var data = await dataResolver.ResolveDataAsync(action, idRegister);

            DisperseAsync(action.ActionSubscriptions, data);
        }
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceID) where T : BaseEntity
        {
            var permanentMovements = new List <PermanentMovement>();
            List <ConceptPayment> conceptPayments = null;

            var employees = await(new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId: identityWorkId, instanceID: instanceID, randomValues: true));

            var middlewareConceptPaymentManager = new MiddlewareManager <ConceptPayment>(new BaseRecordManager <ConceptPayment>(), new ConceptPaymentValidator());

            conceptPayments = await middlewareConceptPaymentManager.FindByExpressionAsync(p => p.InstanceID == instanceID, identityWorkId);

            if (!conceptPayments.Any())
            {
                conceptPayments = await(new ConceptManagerUT().CreateDefaultSalaryPaymentConceptsAsync(identityWorkId, instanceID));
            }

            permanentMovements.Add(new PermanentMovement()
            {
                AccumulatedAmount = 0,
                Active            = true,
                Amount            = 500,
                company           = identityWorkId,
                ConceptPaymentID  = conceptPayments.FirstOrDefault(p => p.ConceptType == ConceptType.SalaryPayment && p.Name == "Sueldo").ID,
                EmployeeID        = employees.FirstOrDefault().ID,
                ControlNumber     = 0,
                CreationDate      = DateTime.UtcNow,
                DeleteDate        = null,
                Description       = "",
                ID = Guid.NewGuid(),
                InitialApplicationDate = DateTime.UtcNow,
                LimitAmount            = 0,
                Name = "Movimiento permamente sueldito",
                PermanentMovementStatus = PermanentMovementStatus.Active,
                PermanentMovementType   = PermanentMovementType.Amount,
                RegistryDate            = DateTime.UtcNow,
                StatusID     = 1,
                TimesApplied = 0,
                TimesToApply = 5,
                user         = Guid.NewGuid(),
                InstanceID   = instanceID,
                Timestamp    = DateTime.UtcNow
            });

            var middlewareManager = new MiddlewareManager <PermanentMovement>(new BaseRecordManager <PermanentMovement>(), new PermanentMovementValidator());
            await middlewareManager.CreateAsync(permanentMovements, identityWorkId);

            return(permanentMovements as List <T>);
        }
Exemple #30
0
        public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : class
        {
            //EvaluationPeriod
            var nomEvaluationPeriod = new NOMEvaluationPeriod()
            {
                ID           = Guid.NewGuid(),
                Active       = true,
                Timestamp    = DateTime.UtcNow,
                Description  = "Soy una surveyreply",
                CreationDate = DateTime.Now,
                company      = identityWorkId,
                user         = Guid.NewGuid(),
                InstanceID   = instanceId,
                Name         = "g1",
                StatusID     = 1,
                InitialDate  = DateTime.Now,
                FinalDate    = DateTime.Now.AddDays(1),
                Period       = "2019",
                State        = true,
            };
            var lstNomEvaluationPeriods = new List <NOMEvaluationPeriod>();

            lstNomEvaluationPeriods.Add(nomEvaluationPeriod);

            var middlewareManagerEvaluationPeriod = new MiddlewareManager <NOMEvaluationPeriod>(new BaseRecordManager <NOMEvaluationPeriod>(), new NOMEvaluationPeriodValidator());

            middlewareManagerEvaluationPeriod.Create(lstNomEvaluationPeriods, identityWorkId);

            //Employee
            var lstEmployees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, randomValues: true);

            var nomSurveyReply = new NOMSurveyReplyParams()
            {
                EmployeeId            = lstEmployees.FirstOrDefault().ID,
                NOMEvaluationPeriodId = nomEvaluationPeriod.ID,
                NOMEvaluationSurveyId = Guid.Parse("612A7938-1D11-4400-8BB7-AD29191AC33C"),
                IdentityWorkId        = identityWorkId,
                InstanceId            = instanceId
            };

            var manager = new NOMSurveyManager();
            var res     = await manager.CreateAsync(nomSurveyReply);

            return(new List <T>()
            {
                res as T
            });
        }