public async Task <ListStreetSegmentResponse> GetStreetSegmentInRadiusPoint(string coor) { Geometry geom = null; var radius = _unitOfWork.Repository <Config>().GetAll().Where(x => x.Active && x.Name.Equals("StoreRadius")).Select(x => x.Value).FirstOrDefault();;// unit: meter try { geom = GeoJsonHelper.ParseStringToPoint(coor); // s = c0/360; c0 = 40075.017 var rs = await _unitOfWork.Repository <StreetSegment>().GetAll().Where(x => (x.Geom.Distance(geom) * 40075.017 * 1000 / 360) <= radius).Select(x => new StreetSegmentResponse { Name = x.Name, Geom = x.Geom, CreateDate = x.CreateDate, ModifyDate = x.ModifyDate, WardId = x.WardId, Id = x.Id }).ToListAsync(); return(new ListStreetSegmentResponse { ListStreetSegment = rs }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Street Segment by Store Location Error!!!", e.InnerException?.Message); } }
public async Task <bool> CheckStoreInSystemzoneAsync(Guid accountId, string coordinateString) { var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.AccountId == accountId).ToListAsync(); Geometry geom = GeoJsonHelper.ParseStringToPoint(coordinateString); var intersects = systemzones.Any(x => x.Geom.Intersects(geom)); return(intersects); }
public async Task <StoreResponse> GetStoreOrder(int brandId, string coordinateString, DateTime timeOrder, int dateOrder) { var timeInMinute = (timeOrder.Hour * 60) + timeOrder.Minute; var timeSlot = (int)timeInMinute / (60 * 6); // 6 is 1 timeslot var tradezoneVer = await _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => x.IsActive == true && x.BrandId == brandId).FirstOrDefaultAsync(); if (!tradezoneVer.TimeSlot.ElementAt(timeSlot).Equals('1')) { return(null); } var dateInVersion = Convert.ToString(tradezoneVer.DateFilter, 2).PadLeft(7, '0'); if (!dateInVersion.ElementAt(dateOrder).Equals('1')) { return(null); } if (!(tradezoneVer is null)) { var location = GeoJsonHelper.ParseStringToPoint(coordinateString); var tradezone = tradezoneVer.TradeZones; var result = tradezone.Where(x => x.Geom.Intersects(location)).FirstOrDefault(); if (result != null) { return(new StoreResponse { Name = result.StoreTradeZones.ElementAt(0).Store.Name, Address = result.StoreTradeZones.ElementAt(0).Store.Address, BrandName = result.StoreTradeZones.ElementAt(0).Store.Brand?.Name, CreateDate = result.StoreTradeZones.ElementAt(0).Store.CreateDate, Geom = result.StoreTradeZones.ElementAt(0).Store.Geom, Id = result.StoreTradeZones.ElementAt(0).Store.Id, BrandId = result.StoreTradeZones.ElementAt(0).Store.BrandId, ImageUrl = result.StoreTradeZones.ElementAt(0).Store.ImageUrl, Type = result.StoreTradeZones.ElementAt(0).Store.Brand?.Segment?.Name, Status = result.StoreTradeZones.ElementAt(0).Store.Status, AbilityToServe = result.StoreTradeZones.ElementAt(0).Store.AbilityToServe, TimeSlot = result.StoreTradeZones.ElementAt(0).Store.TimeSlot }); } else { return(null); } }
public void CheckViolation() { var redis = _redisClientsManager.GetClient(); var assets = redis.GetAllKeys(); foreach (var item in assets) { bool isEnd = false; bool isStart = false; var currentAsset = redis.Get <AssetRedis>(item); ViolationLog log = new ViolationLog() { AssetId = currentAsset.Id, Description = "Test", Severity = 1, TypeViolation = 1 }; Geometry locationGeometry = null; if (currentAsset.Location.Contains(",")) { locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location); } else { locationGeometry = GeoJsonHelper.ParseStringToLineString(currentAsset.Location); } var tradeZones = _unitOfWork.Repository <TradeZoneVersion>().GetAll().Where(x => x.BrandId == currentAsset.BrandId && x.IsActive == true).Select(x => x.TradeZones).SingleOrDefault(); var tradezone = tradeZones.Where(x => x.StoreTradeZones.Any(x => x.StoreId == currentAsset.StoreId)).FirstOrDefault(); if (!(tradezone is null)) { log.Geom = locationGeometry.Difference(tradezone.Geom); string[] points = currentAsset.Location.Split(", "); for (int i = 0; i < points.Length; i++) { var point = GeoJsonHelper.ParseStringToPoint(points.ElementAt(i)); if (!tradezone.Geom.Intersects(point)) { if (!isStart) { log.StartTime = currentAsset.StartTime.AddSeconds(3 * i); isStart = true; } else { isEnd = true; log.EndTime = currentAsset.StartTime.AddSeconds(3 * i); } } } if (isStart) { if (!isEnd) { log.EndTime = log.StartTime; } _unitOfWork.Repository <ViolationLog>().Insert(log); _unitOfWork.Commit(); } } } }
public async Task <StoreResponse> PostStore(Guid accountId, PostStoresRequest model) { var myGeom = GeoJsonHelper.ParseStringToPoint(model.CoordinateString); Store insert = new Store { Name = model.Name, TimeSlot = model.TimeSlot, CreateDate = DateTime.UtcNow.AddHours(7), BrandId = model.BrandId, Geom = myGeom, Address = model.Address, Status = (int?)Status.NeedApproval, AbilityToServe = model.AbilityToServe, ImageUrl = model.ImageUrl }; if (model.FloorAreaId > 0) { insert.FloorAreaId = model.FloorAreaId; } try { await _unitOfWork.Repository <Store>().InsertAsync(insert); await _unitOfWork.CommitAsync(); List <StoreStreetSegmentResponse> storeStreetSegmentResponses = new List <StoreStreetSegmentResponse>(); if (model.StreetSegmentIds != null) { foreach (var item in model.StreetSegmentIds) { StoreStreetSegment storeStreetSegment = new StoreStreetSegment { StoreId = insert.Id, StreetSegmentId = item }; await _unitOfWork.Repository <StoreStreetSegment>().InsertAsync(storeStreetSegment); await _unitOfWork.CommitAsync(); storeStreetSegmentResponses.Add(new StoreStreetSegmentResponse { StoreId = storeStreetSegment.StoreId, StreetSegmentId = storeStreetSegment.StreetSegmentId }); } } await _unitOfWork.Repository <History>().InsertAsync(new History { AccountId = accountId, Action = (int)ActionEnum.ActionSurvey.InsertStore, CreateDate = DateTime.UtcNow.AddHours(7), StoreId = insert.Id, }); await _unitOfWork.CommitAsync(); return(new StoreResponse { Name = insert.Name, Address = insert.Address, FloorAreaName = insert.FloorArea?.Name, BrandName = insert.Brand?.Name, CreateDate = insert.CreateDate, Geom = insert.Geom, Id = insert.Id, FloorAreaId = insert.FloorAreaId, StoreStreetSegments = storeStreetSegmentResponses, BrandId = insert.BrandId, ImageUrl = insert.ImageUrl, Status = insert.Status, TimeSlot = insert.TimeSlot, }); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Insert Store Error!!!", e.InnerException?.Message); } }
public async Task <List <BuildingDetailResponse> > GetBuildingByStoreLocation(string coor, float radius) { Geometry geom = null; // unit: meter try { geom = GeoJsonHelper.ParseStringToPoint(coor); // s = c0/360; c0 = 40075.017 return(await _unitOfWork.Repository <Building>().GetAll().Where(x => (x.Geom.Distance(geom) * 40075.017 * 1000 / 360) <= radius && x.Status == (int)Status.Surveyed).Select(x => new BuildingDetailResponse { Id = x.Id, Name = x.Name, Geom = x.Geom, NumberOfFloor = x.NumberOfFloor, Active = x.Active, CampusId = x.CampusId, CreateDate = x.CreateDate, ImageUrl = x.ImageUrl, Type = x.Type.Name, Address = x.Address, Status = x.Status, ReferenceId = x.ReferenceId, BuildingStreetSegments = new List <BuidingStreetSegmentResponse>(x.BuildingStreetSegments.Select(b => new BuidingStreetSegmentResponse { BuildingId = b.BuidingId, StreetSegmentId = b.StreetSegmentId })), ReferencrName = x.ReferenceId != null ? x.Reference.Name : null, Floors = new List <FloorResopnse>(x.Floors.Select(f => new FloorResopnse { Id = f.Id, BuildingId = f.BuildingId, FloorNumber = f.FloorNumber, Name = f.Name, FloorAreas = new List <FloorAreaResopnse>(f.FloorAreas.Select(a => new FloorAreaResopnse { Id = a.Id, FloorId = a.FloorId, Name = a.Name, Stores = new List <StoreResponse>(a.Stores.Select(s => new StoreResponse { Name = s.Name, Address = s.Address, FloorAreaName = s.FloorArea != null ? s.FloorArea.Name : null, BrandName = s.Brand != null ? s.Brand.Name : null, CreateDate = s.CreateDate, Geom = s.Geom, Id = s.Id, FloorAreaId = s.FloorAreaId, BrandId = s.BrandId, ImageUrl = s.ImageUrl, Type = s.Brand.Segment.Name, Status = s.Status, ReferenceId = s.ReferenceId, AbilityToServe = s.AbilityToServe, TimeSlot = s.TimeSlot })) })) })) }).ToListAsync()); } catch (Exception e) { throw new CrudException(HttpStatusCode.BadRequest, "Get Building by Store Location Error!!!", e.InnerException?.Message); } }