Beispiel #1
0
        public async Task <IActionResult> GetGeneralStatistics([FromQuery] SanBongStatisticsParams userParams)
        {
            try
            {
                var result = await _repo.GetGeneralStatistics(userParams);

                return(StatusCode(200, new SuccessResponseDto
                {
                    Message = "Lấy dữ liệu thống kê tổng quan về " + _entityName + " thành công!",
                    Result = new SuccessResponseResultWithSingleDataDto
                    {
                        Data = result
                    }
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Lấy dữ liệu thống kê tổng quan về " + _entityName + " thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }
Beispiel #2
0
        public async Task <Object> GetGeneralStatistics(SanBongStatisticsParams userParams)
        {
            var result       = _context.DanhSachSanBong.AsQueryable();
            var totalPitch   = 0;   // tổng số sân bóng
            var minAreaPitch = 0.0; // diện tích nhỏ nhất
            var maxAreaePich = 0.0; // diện tích lớn nhất

            if (userParams != null && userParams.StartingTime.GetHashCode() != 0 && userParams.EndingTime.GetHashCode() != 0)
            {
                totalPitch   = result.Count();
                minAreaPitch = result.Where(x => x.ThoiGianTao >= userParams.StartingTime && x.ThoiGianTao <= userParams.EndingTime).Min(x => x.DienTich);
                maxAreaePich = result.Where(x => x.ThoiGianTao >= userParams.StartingTime && x.ThoiGianTao <= userParams.EndingTime).Max(x => x.DienTich);
            }
            else
            {
                totalPitch   = result.Count();
                minAreaPitch = result.Min(x => x.DienTich);
                maxAreaePich = result.Max(x => x.DienTich);
            }

            return(new
            {
                Total = totalPitch,
                MinArea = minAreaPitch,
                MaxArea = maxAreaePich
            });
        }