示例#1
0
        public async Task <IActionResult> PostFriendLocationBox([FromBody] FriendLocationBoxRequest box)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var applicationUser = _context.ApplicationUser
                                  .SingleOrDefault(a => a.Id == box.UserId.ToString());

            if (applicationUser == null)
            {
                return(NotFound(box.UserId));
            }
            var applicationOptions = await _context.ApplicationOptions
                                     .OrderByDescending(a => a.OptionsDate)
                                     .FirstOrDefaultAsync();

            if (applicationOptions == null)
            {
                return(NotFound("ApplicationOptions"));
            }
            var locationBox = new FriendLocationBox
            {
                BoundingBox = box.BoundingBox,
                Friends     = new List <FriendLocationResult>()
            };
            double latMin = CoordinateFilters.GetLatitudeFloorFromBox(locationBox.BoundingBox),
                   latMax = CoordinateFilters.GetLatitudeCeilingFromBox(locationBox.BoundingBox),
                   lonMin = CoordinateFilters.GetLongitudeFloorFromBox(locationBox.BoundingBox),
                   lonMax = CoordinateFilters.GetLongitudeCeilingFromBox(locationBox.BoundingBox);
            var friends   = await _context.FriendRequests
                            .Where(f => f.TargetId.ToString().Equals(applicationUser.Id))
                            .ToListAsync();

            var currentFriends = from a in _context.ApplicationUser
                                 from f in _context.FriendRequests
                                 where a.Id.Equals(f.InitiatorId.ToString())
                                 where a.CurrentLatitude != null
                                 where a.CurrentLatitude >= latMin
                                 where a.CurrentLatitude < latMax
                                 where a.CurrentLongitude != null
                                 where a.CurrentLongitude >= lonMin
                                 where a.CurrentLongitude <lonMax
                                                           where a.CurrentTimeStamp != null
                                                           where a.CurrentTimeStamp> DateTime.Now.Subtract(applicationOptions.DataTimeWindow)
                                 select new FriendLocationResult
            {
                PhoneNumber = a.PhoneNumber,
                UserId      = Guid.Parse(a.Id),
                Timestamp   = a.CurrentTimeStamp.Value,
                UserName    = a.UserName
            };

            locationBox.Friends = await currentFriends.ToListAsync();

            return(Ok(locationBox));
        }
示例#2
0
        public async Task ButtonLocationBox_OnClicked(object sender, EventArgs e)
        {
            string box = EntryLocationBox.Text;
            FriendLocationBoxRequest req = new FriendLocationBoxRequest();

            req.BoundingBox = box;
            req.UserId      = App.AppUser.id;
            var friends = await App.approxiMATEService.PostFriendLocationBoxAsync(req);

            ListViewBoxes.ItemsSource = friends.Friends;
        }
        public async Task <FriendLocationBox> PostFriendLocationBoxAsync(FriendLocationBoxRequest data)
        {
            var box = new FriendLocationBox();

            if (App.AppUser != null && data.UserId != App.AppUser.id)
            {
                return(box);
            }
            AddJwtHeader();
            var json     = JsonConvert.SerializeObject(data);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PostAsync(Constants.ApproxiMATEwebApiBase + "api/FriendLocationBox", content);

            if (response.IsSuccessStatusCode)
            {
                var jsonresult = response.Content.ReadAsStringAsync().Result;
                box = JsonConvert.DeserializeObject <FriendLocationBox>(jsonresult);
            }
            return(box);
        }