Esempio n. 1
0
        public async Task <StatisticsInfoDto> GetFloorStatisticsAsync(int floorId)
        {
            Floor floor = await _floorRepository.GetByIdAsync(floorId);

            if (floor == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            else
            {
                StatisticsInfoDto statisticsInfoDto = new StatisticsInfoDto();
                foreach (var r in floor.Rooms)
                {
                    if (r.Status != null)
                    {
                        if (r.Status.Clients != null && r.Status.Clients.Count != 0)
                        {
                            statisticsInfoDto.PopulatedRoomCount++;
                        }
                        else
                        {
                            statisticsInfoDto.ReservedRoomCount++;
                        }
                    }
                    else
                    {
                        statisticsInfoDto.FreeRoomCount++;
                    }
                }
                return(statisticsInfoDto);
            }
        }
Esempio n. 2
0
        public async Task <StatisticsInfoDto> GetRoomTypeStatisticsAsync(int floorId, RoomType roomType)
        {
            Floor floor = await _floorRepository.GetByIdAsync(floorId);

            if (floor == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            else
            {
                var rooms = floor.Rooms.Where(x => x.Type == roomType).AsEnumerable();
                if (rooms.Count() == 0)
                {
                    throw new Exception();
                }
                else
                {
                    StatisticsInfoDto statisticsInfoDto = new StatisticsInfoDto();
                    foreach (var r in rooms)
                    {
                        if (r.Status != null)
                        {
                            if (r.Status.Clients != null && r.Status.Clients.Count != 0)
                            {
                                statisticsInfoDto.PopulatedRoomCount++;
                            }
                            else
                            {
                                statisticsInfoDto.ReservedRoomCount++;
                            }
                        }
                        else
                        {
                            statisticsInfoDto.FreeRoomCount++;
                        }
                    }
                    return(statisticsInfoDto);
                }
            }
        }
Esempio n. 3
0
 public async Task <StatisticsInfoDto> GetCorpsStatisticsAsync(int corpsId)
 {
     if (await _corpsRepository.GetByIdAsync(corpsId) == null)
     {
         throw new ArgumentOutOfRangeException();
     }
     else
     {
         StatisticsInfoDto statisticsInfoDto = new StatisticsInfoDto();
         // получаем все этажи
         var floors = (await _floorRepository.GetAllAsync()).Where(x => x.CorpsId == corpsId);
         // идем по этажам
         foreach (var f in floors)
         {
             // получаем комнаты этажа
             var rooms = (await _roomRepository.GetAllAsync()).Where(x => x.FloorId == f.Id);
             foreach (var r in rooms)
             {
                 if (r.Status != null)
                 {
                     if (r.Status.Clients != null && r.Status.Clients.Count != 0)
                     {
                         statisticsInfoDto.PopulatedRoomCount++;
                     }
                     else
                     {
                         statisticsInfoDto.ReservedRoomCount++;
                     }
                 }
                 else
                 {
                     statisticsInfoDto.FreeRoomCount++;
                 }
             }
         }
         return(statisticsInfoDto);
     }
 }
        /// <summary>
        /// Конвертер статистики в данные для графика
        /// </summary>
        /// <param name="statisticsInfoDto">Статистика</param>
        private SeriesCollection StatisticsInfoToSeriesCollection(StatisticsInfoDto statisticsInfoDto)
        {
            if (statisticsInfoDto == null)
            {
                return(null);
            }
            // надписи
            string freeRoomTitle      = "Свободно";
            string reservedRoomTitle  = "Зарезервировано";
            string populatedRoomTitle = "Занято";
            // кисти
            SolidColorBrush freeRoomBrush      = (SolidColorBrush)Application.Current.Resources["FreeRoomBrush"];
            SolidColorBrush reservedRoomBrush  = (SolidColorBrush)Application.Current.Resources["ReservedRoomBrush"];
            SolidColorBrush populatedRoomBrush = (SolidColorBrush)Application.Current.Resources["PopulatedRoomBrush"];

            SeriesCollection seriesViews = new SeriesCollection();

            switch (_selectedPlotType)
            {
            case PlotType.Column:
            {
                seriesViews.Add(new ColumnSeries()
                    {
                        Title  = freeRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.FreeRoomCount
                        },
                        Fill       = freeRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new ColumnSeries()
                    {
                        Title  = reservedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.ReservedRoomCount
                        },
                        Fill       = reservedRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new ColumnSeries()
                    {
                        Title  = populatedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.PopulatedRoomCount
                        },
                        Fill       = populatedRoomBrush,
                        DataLabels = true
                    });
                return(seriesViews);
            }

            case PlotType.Row:
            {
                seriesViews.Add(new RowSeries()
                    {
                        Title  = freeRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.FreeRoomCount
                        },
                        Fill       = freeRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new RowSeries()
                    {
                        Title  = reservedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.ReservedRoomCount
                        },
                        Fill       = reservedRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new RowSeries()
                    {
                        Title  = populatedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.PopulatedRoomCount
                        },
                        Fill       = populatedRoomBrush,
                        DataLabels = true
                    });
                return(seriesViews);
            }

            case PlotType.Pie:
            {
                seriesViews.Add(new PieSeries()
                    {
                        Title  = freeRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.FreeRoomCount
                        },
                        Fill       = freeRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new PieSeries()
                    {
                        Title  = reservedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.ReservedRoomCount
                        },
                        Fill       = reservedRoomBrush,
                        DataLabels = true
                    });
                seriesViews.Add(new PieSeries()
                    {
                        Title  = populatedRoomTitle,
                        Values = new ChartValues <int> {
                            statisticsInfoDto.PopulatedRoomCount
                        },
                        Fill       = populatedRoomBrush,
                        DataLabels = true
                    });
                return(seriesViews);
            }

            default:
                // ничего не возвращаем
                return(null);
            }
        }