Beispiel #1
0
 public void UpdateReportsAffectedBySubstitute(Substitute sub)
 {
     if (sub.LeaderId == sub.PersonId)
     {
         // Substitute is a substitute - Not a Personal Approver.
         // Select reports to be updated based on OrgUnits
         var orgIds = new List <int>();
         orgIds.Add(sub.OrgUnitId);
         orgIds.AddRange(_orgService.GetChildOrgsWithoutLeader(sub.OrgUnitId).Select(x => x.Id));
         var reports = _driveRepo.AsQueryable().Where(rep => orgIds.Contains(rep.Employment.OrgUnitId)).ToList();
         var idsOfLeadersOfImmediateChildOrgs      = _orgService.GetIdsOfLeadersInImmediateChildOrgs(sub.OrgUnitId);
         var reportsForLeadersOfImmediateChildOrgs = _driveRepo.AsQueryable().Where(rep => idsOfLeadersOfImmediateChildOrgs.Contains(rep.PersonId)).ToList();
         reports.AddRange(reportsForLeadersOfImmediateChildOrgs);
         foreach (var report in reports)
         {
             report.ResponsibleLeaderId = _driveService.GetResponsibleLeaderForReport(report).Id;
         }
         _driveRepo.Save();
     }
     else
     {
         // Substitute is a personal approver
         // Select reports to be updated based on PersonId on report
         var reports2 = _driveRepo.AsQueryable().Where(rep => rep.PersonId == sub.PersonId).ToList();
         foreach (var report in reports2)
         {
             report.ResponsibleLeaderId = sub.SubId;
         }
         _driveRepo.Save();
     }
 }
Beispiel #2
0
        public void UpdateReportsAffectedBySubstitute(Substitute sub)
        {
            if (sub.LeaderId == sub.PersonId)
            {
                // Substitute is a substitute - Not a Personal Approver.
                // Select reports to be updated based on OrgUnits
                var orgIds = new List <int>();
                orgIds.Add(sub.OrgUnitId);
                orgIds.AddRange(_orgService.GetChildOrgsWithoutLeader(sub.OrgUnitId).Select(x => x.Id));
                var idsOfLeadersOfImmediateChildOrgs = _orgService.GetIdsOfLeadersInImmediateChildOrgs(sub.OrgUnitId);

                var reports = _reportRepo.AsNoTracking().Where(rep => orgIds.Contains(rep.Employment.OrgUnitId) || idsOfLeadersOfImmediateChildOrgs.Contains(rep.PersonId)).ToList();
                foreach (var report in reports)
                {
                    if (report.ReportType != sub.Type)
                    {
                        continue;
                    }
                    report.ResponsibleLeaderId = _reportService.GetResponsibleLeaderForReport(report).Id;
                    _reportRepo.Patch(report);
                }
                _reportRepo.Save();
            }
            else
            {
                // Substitute is a personal approver
                // Select reports to be updated based on PersonId on report
                var reports2 =
                    _reportRepo.AsNoTracking().Where(rep => rep.PersonId == sub.PersonId).ToList();
                foreach (var report in reports2.AsEnumerable())
                {
                    if (report.ReportType != sub.Type)
                    {
                        continue;
                    }
                    report.ResponsibleLeaderId = _reportService.GetResponsibleLeaderForReport(report).Id;
                    _reportRepo.Patch(report);
                }
                _reportRepo.Save();
            }
        }
Beispiel #3
0
 public void UpdateReportsAffectedBySubstitute(Substitute sub)
 {
     try
     {
         if (sub.LeaderId == sub.PersonId)
         {
             // Substitute is a substitute - Not a Personal Approver.
             // Select reports to be updated based on OrgUnits
             var orgIds = new List <int>();
             orgIds.Add(sub.OrgUnitId);
             orgIds.AddRange(_orgService.GetChildOrgsWithoutLeader(parentId: sub.OrgUnitId).Select(x => x.Id));
             var reports = _driveRepo.AsQueryable().Where(rep => orgIds.Contains(rep.Employment.OrgUnitId)).ToList();
             var idsOfLeadersOfImmediateChildOrgs      = _orgService.GetIdsOfLeadersInImmediateChildOrgs(parentOrgId: sub.OrgUnitId);
             var reportsForLeadersOfImmediateChildOrgs = _driveRepo.AsQueryable().Where(rep => idsOfLeadersOfImmediateChildOrgs.Contains(rep.PersonId)).ToList();
             reports.AddRange(reportsForLeadersOfImmediateChildOrgs);
             foreach (var report in reports)
             {
                 report.UpdateResponsibleLeaders(_driveService.GetResponsibleLeadersForReport(report));
             }
             _driveRepo.Save();
         }
         else
         {
             // Substitute is a personal approver
             // Select reports to be updated based on PersonId on report
             var reports = _driveRepo.AsQueryable().Where(rep => rep.PersonId == sub.PersonId).ToList();
             foreach (var report in reports)
             {
                 report.UpdateResponsibleLeaders(_driveService.GetResponsibleLeadersForReport(report));
             }
             _driveRepo.Save();
         }
     }
     catch (Exception e)
     {
         _logger.LogError($"{this.GetType().Name}, Error updating reports for substitute ", e);
     }
 }