コード例 #1
0
        public IHttpActionResult OverviewStatistics(bool showSelf = false, bool includeChildren = true)
        {
            var currentUser = _workContext.CurrentAccountUser;

            IList <int> governmentIds = new List <int>();

            if (showSelf)
            {
                governmentIds = _governmentService.GetGovernmentIdsByParentId(currentUser.Government.Id);
                if (!governmentIds.Contains(currentUser.Government.Id))
                {
                    governmentIds.Add(currentUser.Government.Id);
                }
            }
            else
            {
                governmentIds = _governmentService.GetGovernmentIdsByCurrentUser();
            }

            var properties              = _propertyService.GetAllProperties(governmentIds, false);
            var constructProperties     = properties.Where(p => p.PropertyType == PropertyType.House);
            var constructLandProperties = properties.Where(p => p.PropertyType == PropertyType.LandUnderHouse);
            var landProperties          = properties.Where(p => p.PropertyType == PropertyType.Land);

            var response = new OverviewStatistics();

            response.TotalCount     = properties.Count();
            response.LandCount      = landProperties.Count();
            response.ConstructCount = response.TotalCount - response.LandCount;

            response.TotalPrice     = properties.Select(p => p.Price).Sum();
            response.LandPrice      = response.LandCount > 0 ? landProperties.Select(p => p.Price).Sum() : 0;
            response.ConstructPrice = response.TotalPrice - response.LandPrice;

            response.ConstructArea = constructProperties.Count() > 0 ? constructProperties.Select(p => p.ConstructArea).Sum() : 0;

            response.ConstrcutLandArea  = constructProperties.Count() > 0 ? constructProperties.Select(p => p.LandArea).Sum() : 0;
            response.ConstrcutLandArea += constructLandProperties.Count() > 0 ? constructLandProperties.Select(p => p.LandArea).Sum() : 0;

            response.LandArea = response.LandCount > 0 ? landProperties.Select(p => p.LandArea).Sum() : 0;
            return(Ok(response));
        }