public void AfterUpdate(List <PeriodType> lstObjectsToValidate) { //all good var periodMiddlewareManager = new MiddlewareManager <Period>(new BaseRecordManager <Period>(), new PeriodValidator()); var company = lstObjectsToValidate.FirstOrDefault().company; var periodTypeIDs = lstObjectsToValidate.Select(p => p.ID); //Obtener los periodos y sus detalles var periods = periodMiddlewareManager.FindByExpression(p => periodTypeIDs.Contains(p.PeriodTypeID), company, new string[] { "PeriodDetails" }); foreach (var period in periods) { var periodTypeModified = lstObjectsToValidate.FirstOrDefault(p => p.ID == period.PeriodTypeID); //Por cada periodo se update los días de pago y sus fortnight period.FortnightPaymentDays = periodTypeModified.FortnightPaymentDays; period.PaymentDays = periodTypeModified.PaymentDays; foreach (var periodDetail in period.PeriodDetails) { if (periodDetail.PeriodStatus != PeriodStatus.Authorized && periodDetail.PeriodStatus != PeriodStatus.Stamped) { //Si es por los días de pago if (periodTypeModified.FortnightPaymentDays == AdjustmentPay_16Days_Febrary.PayPaymentDays) { periodDetail.PaymentDays = periodTypeModified.PaymentDays; } //Si es por los días calendario else { periodDetail.PaymentDays = Convert.ToDecimal((periodDetail.FinalDate - periodDetail.InitialDate).TotalDays + 1); } } } } //al finalizar se actualizan periodMiddlewareManager.Update(periods, company); }