Esempio n. 1
0
        public async Task <IActionResult> buildingDashboardData()
        {
            var buildingListResult = await _buildingService.GetBuildings();

            var buildingTypeListResult = await _buildingService.GetBuildingTypes();

            var buildingsDataDto = new BuildingsDataDto()
            {
                BuildingList     = _mapper.Map <IEnumerable <BuildingDataDto> >(buildingListResult),
                BuildingTypeList = _mapper.Map <List <BuildingTypeDataDto> >(buildingTypeListResult.ToList())
            };

            foreach (BuildingDataDto b in buildingsDataDto.BuildingList)
            {
                b.CurrentGuests = await _buildingService.GetBuildingCurrentGuests(b.Id);

                b.Capacity = await _buildingService.GetBuildingCapacity(b.Id);

                b.SurgeCapacity = await _buildingService.GetBuildingSurgeCapacity(b.Id);

                var bcat = buildingsDataDto.BuildingTypeList.Find(t => t.Id == b.BuildingCategoryId);
                if (bcat != null)
                {
                    bcat.SurgeCapacity += b.SurgeCapacity;
                    bcat.Capacity      += b.Capacity;
                    bcat.CurrentGuests += b.CurrentGuests;
                }
            }
            return(Ok(buildingsDataDto));
        }