Пример #1
0
        public bool IsValidGroupZone(List <int> listZoneId, int brandId, int type)
        {
            bool result     = false;
            var  groupZones = _unitOfWork.Repository <GroupZone>().GetAll().Where(x => x.BrandId == brandId).Select(x => x.Geom).ToList();

            List <Geometry> geoms;

            if (type == (int)GroupZoneType.Ward)
            {
                geoms = _unitOfWork.Repository <Ward>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList();
            }
            else if (type == (int)GroupZoneType.District)
            {
                geoms = _unitOfWork.Repository <District>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList();
            }
            else
            {
                geoms = _unitOfWork.Repository <SystemZone>().GetAll().Where(x => listZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToList();
            }
            Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null;

            if (IsDuplicateWardInGroupZone(groupZones, geoms) && IsIntersectWard(geoms))
            {
                result = true;
            }

            return(result);
        }
Пример #2
0
        public async Task <Geometry> CheckSystemZoneClose(int wardId)
        {
            var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.WardId == wardId).Select(x => x.Geom).ToListAsync();

            var reuslt = GeoJsonHelper.CombineGeoCollection(systemzones);

            return(reuslt);
        }
Пример #3
0
        public async Task <bool> CheckSystemzoneFillWard(int wardId)
        {
            var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.WardId == wardId).Select(x => x.Geom).ToListAsync();

            var wardGeom = await _unitOfWork.Repository <Ward>().GetAll().Where(x => x.Id == wardId).Select(x => x.Geom).SingleOrDefaultAsync();

            var    systemzonesGeom = GeoJsonHelper.CombineGeoCollection(systemzones);
            double percent         = systemzonesGeom.Area / wardGeom.Area;

            if (percent > 0.98 && percent < 1.02)
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
        public async Task <GroupZoneResponse> PostGroupZone(GroupZoneRequest model, int brandId)
        {
            try
            {
                List <Geometry> geoms;
                if (model.Type == (int)GroupZoneType.Ward)
                {
                    geoms = await _unitOfWork.Repository <Ward>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                else if (model.Type == (int)GroupZoneType.District)
                {
                    geoms = await _unitOfWork.Repository <District>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                else
                {
                    geoms = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => model.ListZoneId.Any(c => c == x.Id)).Select(x => x.Geom).ToListAsync();
                }
                Geometry groupZoneGeom = (geoms.Any()) ? GeoJsonHelper.CombineGeoCollection(geoms) : null;
                var      insertItem    = new GroupZone()
                {
                    BrandId = brandId,
                    Geom    = groupZoneGeom,
                    Name    = model.Name,
                };
                await _unitOfWork.Repository <GroupZone>().InsertAsync(insertItem);

                await _unitOfWork.CommitAsync();

                return(new GroupZoneResponse()
                {
                    Id = insertItem.Id, Geom = insertItem.Geom, BrandId = insertItem.BrandId, Name = insertItem.Name
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Insert Groupzone Error!!!", e.InnerException?.Message);
            }
        }