public async Task <List <Overdraft> > UpdateByEmployeesAsync(List <Employee> employees) { //all good var identityWorkId = employees.FirstOrDefault().company; //Get the overdrafts to delete var employeesID = employees.Select(p => p.ID).ToList(); var middlewareManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); var middlewareOverdraftDetailManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator()); var overdraftsToDelete = await middlewareManager.FindByExpressionAsync(p => employeesID.Contains(p.EmployeeID), identityWorkId); if (overdraftsToDelete.Any()) { //delete previous overdraft (no timbrados ni autorizados ni cancelados) var overdraftIds = overdraftsToDelete.Where(p => p.OverdraftStatus == OverdraftStatus.None).Select(p => p.ID).ToList(); if (overdraftIds.Any()) { await middlewareOverdraftDetailManager.DeleteByExpresssionAsync(p => overdraftIds.Contains(p.OverdraftID), identityWorkId); await middlewareManager.DeleteAsync(overdraftIds, identityWorkId); } } return(await CreateByEmployeesAsync(employees)); }
public async Task DeleteByExpresssionAsync(Expression <Func <T, bool> > predicate, Guid identityWorkId) { var middlewareManager = new MiddlewareManager <T>(new BaseRecordManager <T>(), Validator); await middlewareManager.DeleteByExpresssionAsync(predicate, identityWorkId, null); }