Ejemplo n.º 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();
     }
 }
Ejemplo n.º 2
0
        public IHttpActionResult LeadersPeople(int type = 1)
        {
            var subsituteType    = (ReportType)type;
            var currentTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            var substitutes       = _substituteRepo.AsQueryable().Where(x => x.PersonId == x.LeaderId && x.SubId == CurrentUser.Id && x.EndDateTimestamp >= currentTimestamp && x.Type == subsituteType).Distinct().ToList();
            var personalApproving = _substituteRepo.AsQueryable().Where(x => x.PersonId != x.LeaderId && x.SubId == CurrentUser.Id && x.EndDateTimestamp >= currentTimestamp && x.Type == subsituteType).Select(x => x.Person).ToList();
            var orgs = _orgService.GetWhereUserIsResponsible(CurrentUser.Id).Where(x => subsituteType == ReportType.Vacation && x.HasAccessToVacation).ToList();

            foreach (var sub in substitutes)
            {
                orgs.AddRange(_orgService.GetWhereUserIsResponsible(sub.PersonId));
            }

            var people = _reportRepo.AsNoTracking().Where(x => x.ResponsibleLeaderId == CurrentUser.Id && x.Status == ReportStatus.Pending).Select(x => x.Person).Distinct().ToList();

            foreach (var org in orgs)
            {
                foreach (var person in org.Employments.Where(x => (x.EndDateTimestamp == 0 || x.EndDateTimestamp >= currentTimestamp) && people.All(y => y.Id != x.PersonId) && x.PersonId != CurrentUser.Id).Select(x => x.Person))
                {
                    people.Add(person);
                }

                var leadersIds = _orgService.GetIdsOfLeadersInImmediateChildOrgs(org.Id);

                foreach (var leaderId in leadersIds)
                {
                    var leader = Repo.AsQueryable().FirstOrDefault(x => x.Id == leaderId);
                    if (leader != null && !people.Contains(leader))
                    {
                        people.Add(leader);
                    }
                }
            }

            foreach (var subbing in personalApproving)
            {
                if (!people.Contains(subbing))
                {
                    people.Add(subbing);
                }
            }

            people.RemoveAll(x => x.Employments.All(y => y.EndDateTimestamp <= currentTimestamp && y.EndDateTimestamp != 0));

            return(Ok(people.GroupBy(p => p.Id).Select(g => g.First()).AsQueryable()));
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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);
     }
 }