コード例 #1
0
        public async Task <IActionResult> GetBldgTypeOccupancyByService()
        {
            const string VACENT  = "Vacant";
            const string UNKNOWN = "Unknown";
            var          chart   = _dataService.GetChart <ServiceOccupancySeries>();

            chart.Columns = (await _buildingService.GetBuildingTypes()).Select(btype => btype.Type).ToList();
            chart.Series  = new List <ServiceOccupancySeries>();

            var services = await _unitService.GetServices();

            var seriesCats = services.Select(u => u.ServiceName).ToList();

            seriesCats.Add(VACENT);
            seriesCats.Add(UNKNOWN);

            foreach (var series in seriesCats)
            {
                chart.Series.Add(new ServiceOccupancySeries()
                {
                    Name = series,
                    Data = new List <int>()
                });
            }

            foreach (var column in chart.Columns)
            {
                foreach (var series in chart.Series)
                {
                    if (series.Name.Equals(VACENT))
                    {
                        var bldgType = await _buildingService.GetBuildingType(column);

                        if (!bldgType.InSurge)
                        {
                            series.Data.Add((await _buildingService.GetBuildingTypeCapacity(column)) - (await _buildingService.GetBuildingTypeCurrentGuests(column)));
                        }
                        else
                        {
                            series.Data.Add((await _buildingService.GetBuildingTypeSurgeCapacity(column)) - (await _buildingService.GetBuildingTypeCurrentGuests(column)));
                        }
                    }
                    else if (series.Name.Equals(UNKNOWN))
                    {
                        series.Data.Add(
                            (await _guestStayService.GetGuestStays(
                                 null,
                                 s => s.CheckedOut == false &&
                                 s.CheckedIn == true &&
                                 !(DateTime.Compare(s.CheckInDate.Date, DateTime.Today) > 0) &&
                                 s.Building.BuildingCategory.Type.Equals(column) &&
                                 (s.Guest.RankId == null || s.Guest.RankId == 0))
                            ).Count()
                            );
                    }
                    else
                    {
                        series.Data.Add(
                            (await _guestStayService.GetGuestStays(null,
                                                                   s => s.CheckedOut == false &&
                                                                   s.CheckedIn == true &&
                                                                   !(DateTime.Compare(s.CheckInDate.Date, DateTime.Today) > 0) &&
                                                                   s.Guest.Rank.Service.ServiceName.Equals(series.Name) &&
                                                                   s.Building.BuildingCategory.Type.Equals(column))).Count()
                            );
                    }
                }
            }
            return(Ok(chart));
        }