예제 #1
0
        public async Task <IQueryable <OfficeDetailDTO> > GetOfficeDetailsByDate(DateTimeOffset date)
        {
            var offices = DbContext.Offices.Include(x => x.Sections).ToList();

            List <OfficeDetailDTO> dtos = new List <OfficeDetailDTO>();

            foreach (var office in offices)
            {
                var dto        = OfficeDetailDTO.MapToDTOFunc(office);
                var capacities = DbContext.vOfficeDateCapacities.Where(x => x.StartTime == date && x.OfficeId == office.OfficeId);
                dto.OfficeUsedCapacity = capacities.Select(x => x.OfficeUsedCapacity).Sum();
                dto.Sections           = dto.Sections.ToList();
                foreach (var section in dto.Sections)
                {
                    section.SectionUsedCapacity = capacities.Where(x => x.SectionId == section.SectionId).Select(x => x.SectionUsedCapacity).FirstOrDefault();
                }
                dtos.Add(dto);
            }

            return(dtos.AsQueryable());
        }
예제 #2
0
        public async Task <OfficeDetailDTO> GetOfficeDetailById(Guid officeId, DateTimeOffset workDate)
        {
            DateTimeOffset  startTime    = new DateTimeOffset(workDate.Year, workDate.Month, workDate.Day, 0, 0, 0, workDate.Offset);
            DateTimeOffset  endTime      = startTime.AddDays(1);
            var             office       = DbContext.Offices.Include(x => x.Sections).FirstOrDefault(x => x.OfficeId == officeId);
            OfficeDetailDTO officeDetail = OfficeDetailDTO.MapToDTOFunc(office);

            officeDetail.OfficeUsedCapacity = DbContext.WorkRequests.Count(
                x => x.OfficeId == officeId && x.ApprovalStatus.StatusName == "Approved" &&
                ((x.StartTime >= startTime && x.EndTime <= endTime) ||
                 (x.EndTime >= startTime && x.EndTime <= endTime) ||
                 (startTime >= x.StartTime && startTime <= x.EndTime) ||
                 (endTime >= x.StartTime && endTime <= x.EndTime)));

            officeDetail.Sections = await GetSectionDetailsByOfficeId(officeId, workDate);

            officeDetail.SnapshotDate = workDate;


            return(officeDetail);
        }