Ejemplo n.º 1
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.º 2
0
 public IHttpActionResult GetWhereUserIsResponsible(int personId)
 {
     return(Ok(_orgService.GetWhereUserIsResponsible(personId)));
 }