public List <VenueWebModel> FindVenues2( Location location, double radiusInMeters, Country country, string nameQuery, bool snookerVenues) { try { var query = (from i in db.Venues.Include("Metro") where i.IsSnooker == snookerVenues select i); if (string.IsNullOrEmpty(nameQuery) == false) { query = (from i in db.Venues.Include("Metro") where i.IsSnooker == snookerVenues where i.Name.Contains(nameQuery) select i); } if (country != null) { query = (from i in query where i.Metro.Country == country.ThreeLetterCode select i); } if (location != null) { Location location2 = location.OffsetRoughly(radiusInMeters * 1.5, radiusInMeters * 1.5); double latRange = System.Math.Abs(location2.Latitude - location.Latitude); double lonRange = System.Math.Abs(location2.Longitude - location.Longitude); query = (from i in query where i.Latitude != null && i.Longitude != null where i.Latitude > location.Latitude - latRange && i.Latitude <location.Latitude + latRange where i.Longitude> location.Longitude - lonRange && i.Longitude < location.Longitude + lonRange orderby System.Math.Abs(i.Latitude.Value - location.Latitude) + System.Math.Abs(i.Longitude.Value - location.Longitude) select i); } var items = (from i in query let lastEdit = i.VenueEdits.OrderByDescending(e => e.Time).FirstOrDefault() let lastContributor = lastEdit != null ? lastEdit.Athlete : null let lastContributorDate = lastEdit != null ? (DateTime?)lastEdit.Time : null //let lastContributor = i.VenueEdits.OrderByDescending(e => e.Time).Select(e => e.Athlete).FirstOrDefault() select new { Venue = i, LastContributor = lastContributor, LastContributorDate = lastContributorDate }).Take(1000).ToList(); var venues = (from i in items select VenueWebModel.FromVenue(i.Venue, location, i.LastContributor, i.LastContributorDate)).ToList(); venues = (from i in venues orderby i.DistanceInMeters select i).ToList(); return(venues); } catch (Exception) { return(null); } }
async void createVenue(POIWebModel poi) { this.panelInfo.IsVisible = true; this.panelList.IsVisible = false; this.labelInfo.Text = "Please wait. Registering the venue."; VenueWebModel venue = new VenueWebModel(); venue.Address = poi.Address; venue.Country = ""; venue.IsSnooker = true; venue.Latitude = poi.Location.Latitude; venue.Longitude = poi.Location.Longitude; venue.Name = poi.Name; venue.PhoneNumber = poi.Phone; venue.Website = poi.Website; venue.ID = await App.WebService.CreateNewVenue(venue); if (venue.ID == 0) { this.labelInfo.Text = "Couldn't register the venue. Internet issues? Venue already exists?"; return; } if (this.VenueCreated != null) { this.VenueCreated(this, venue); } }
public VenueWebModel Get(int id) { var venue = db.Venues.Include("Metro").Where(i => i.VenueID == id).Single(); var model = VenueWebModel.FromVenue(venue, null, null); this.loadLastContributorToModel(model); return(model); }
public async Task <FullSnookerVenueData> Load(int venueID) { FullSnookerVenueData data = new FullSnookerVenueData(); data.VenueID = venueID; VenueWebModel venue = await App.WebService.GetVenue(venueID); if (venue == null) { return(null); } data.Venue = venue; App.Cache.Venues.Put(venue); var webResults = await App.WebService.GetResultsAtVenue(venueID); if (webResults != null) { var results = (from r in webResults select r.ToResult()).ToList(); data.Breaks = (from i in results select SnookerBreak.FromResult(i)).ToList(); } var scores = await App.WebService.GetScoresAtVenue(venueID); if (scores != null) { data.Matches = (from i in scores select SnookerMatchScore.FromScore(0, i)).ToList(); } var gameHosts = await App.WebService.GetGameHostsAtVenue(venueID, true); if (gameHosts != null) { data.GameHosts = (from i in gameHosts orderby i.When descending select i).ToList(); data.GameHostsInThePast = (from i in gameHosts where i.When < DateTime.UtcNow orderby i.When descending select i).ToList(); data.GameHostsInTheFuture = (from i in gameHosts where i.When >= DateTime.UtcNow orderby i.When ascending select i).ToList(); } await loadPeople(data); this.putPlaceholdersIfInternetIssues(data); return(data); }
async Task createVenue() { string name = this.entryName.Text; if (name == null) { name = ""; } name = name.Trim(); string address = ""; if (addressLocation != null && this.entryAddress.Text != null) { address = this.entryAddress.Text.Trim(); } Location location = prevLocation; if (name.Length < 3) { await App.Navigator.NavPage.DisplayAlert("Byb", "Please enter a proper name for the venue.", "OK"); return; } ; VenueWebModel venue = new VenueWebModel(); venue.Address = address; venue.Country = ""; venue.IsSnooker = true; venue.Latitude = location.Latitude; venue.Longitude = location.Longitude; venue.Name = name; venue.PhoneNumber = ""; venue.Website = ""; venue.ID = await App.WebService.CreateNewVenue(venue); if (venue.ID == 0) { await App.Navigator.NavPage.DisplayAlert("Byb", "Couldn't register the venue. Internet issues?", "OK"); return; } await App.Navigator.NavPage.Navigation.PopModalAsync(); if (this.VenueCreated != null) { this.VenueCreated(this, venue); } }
public void Put(VenueWebModel venue) { var item = items.Where(i => i.Venue.ID == venue.ID).FirstOrDefault(); if (item != null) { items.Remove(item); } items.Add(new CacheItem() { Venue = venue, TimeLoaded = DateTimeHelper.GetUtcNow() }); }
public List <VenueWebModel> GetAllVenuesInCountry(string country) { var query = (from i in db.Venues where i.Country == country select i); var items = (from i in query let lastEdit = i.VenueEdits.OrderByDescending(e => e.Time).FirstOrDefault() let lastContributor = lastEdit != null ? lastEdit.Athlete : null let lastContributorDate = lastEdit != null ? (DateTime?)lastEdit.Time : null //let lastContributor = i.VenueEdits.OrderByDescending(e => e.Time).Select(e => e.Athlete).FirstOrDefault() select new { Venue = i, LastContributor = lastContributor, LastContributorDate = lastContributorDate }).Take(100).ToList(); var venues = (from i in items orderby i.Venue.Name select VenueWebModel.FromVenue(i.Venue, null, i.LastContributor, i.LastContributorDate)).ToList(); return(venues); }
private void loadLastContributorToModel(VenueWebModel model) { model.LastContributorID = 0; model.LastContributorName = ""; model.LastContributorDate = null; var lastEdit = (from i in db.VenueEdits.Include("Athlete") where i.VenueID == model.ID orderby i.Time descending select i).FirstOrDefault(); if (lastEdit != null) { model.LastContributorID = lastEdit.Athlete.AthleteID; model.LastContributorName = lastEdit.Athlete.NameOrUnknown; model.LastContributorDate = lastEdit.Time; } }
public async Task <VenueWebModel> GetVenue(int venueID) { string url = WebApiUrl + "Venues/" + venueID; try { string json = await this.sendGetRequestAndReceiveResponse(url, true); VenueWebModel venue = JsonConvert.DeserializeObject <VenueWebModel>(json); return(venue); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(null); } }
public async Task <int> CreateNewVenue(VenueWebModel venue) { string url = WebApiUrl + "Venues"; try { string json = await this.sendPostRequestAndReceiveResponse(url, venue, true); int venueID = int.Parse(json); return(venueID); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(0); } }
public VenueWebModel GetClosest(Location location, Distance minDistance) { Distance closestDistance = null; VenueWebModel closestVenue = null; foreach (var item in items) { Distance distance = Distance.Calculate(item.Venue.Location, location); if (closestDistance == null || distance.Meters < closestDistance.Meters) { closestDistance = distance; closestVenue = item.Venue; } } if (closestDistance != null && minDistance != null && closestDistance.Meters > minDistance.Meters) { return(null); } return(closestVenue); }
public int Post([FromBody] VenueWebModel venue) { var athlete = new UserProfileLogic(db).GetAthleteForUserName(User.Identity.Name); var metros = new MetrosLogic(db).GetMetrosAround(venue.Location); if (metros.Count == 0) { throw new Exception("No metros around this location: " + venue.Location.ToString()); } var metro = metros[0]; venue.MetroID = metro.ID; venue.Country = metro.Country; Venue venueToCreate = venue.ToVenue(); Venue createdVenue = new VenuesLogic(db).RegisterVenue(venueToCreate, athlete.AthleteID); return(createdVenue.VenueID); }
async void onLocationReceived(EventHandler done) { // new location? var newLocation = locationSvc.Location; if (newLocation == null || locationSvc.LocationServicesStatus != LocationServicesStatusEnum.Ok) { Location = null; ClosestVenue = null; done(this, EventArgs.Empty); return; } if (Location != null && Distance.Calculate(newLocation, Location).Meters < 500) { done(this, EventArgs.Empty); return; // same location as before } Location = newLocation; // find closest venue in cache VenueWebModel newClosestVenue = App.Cache.Venues.GetClosest(Location, Distance.FromMeters(500)); if (newClosestVenue == null) { // find closest venue online var venues = await webService.FindSnookerVenues(newLocation, "", false, false); if (venues != null && venues.Count > 0) { if (venues[0].DistanceInMeters < 500) { newClosestVenue = venues[0]; } } } ClosestVenue = newClosestVenue; done(this, EventArgs.Empty); }
public List <VenueWebModel> FindVenues( Location location, bool searchLargerRadiusIfNeeded, string nameQuery, bool snookerVenues, bool requireSnookerTables, bool require12ftSnookerTables) { try { List <int> kmAway = new List <int> { 100, 1000, 10000 }; if (string.IsNullOrEmpty(nameQuery) == false && nameQuery.Length > 1) { kmAway.Add(1000000); } //List<VenueWebModel> venuesToReturn = new List<VenueWebModel>(); foreach (int km in kmAway) { var query = (from i in db.Venues.Include("Metro") where i.IsSnooker == snookerVenues select i); if (string.IsNullOrEmpty(nameQuery) == false) { query = (from i in db.Venues.Include("Metro") where i.IsSnooker == snookerVenues where i.Name.Contains(nameQuery) select i); //var list = query.ToList(); //int df1345 = 1; } if (require12ftSnookerTables == true) { query = (from i in query where i.NumberOf12fSnookerTables > 0 select i); } else if (requireSnookerTables == true) { query = (from i in query where i.NumberOf10fSnookerTables > 0 || i.NumberOf12fSnookerTables > 0 select i); } if (location != null) { Location location2 = location.OffsetRoughly(km * 1000, km * 1000); double latRange = System.Math.Abs(location2.Latitude - location.Latitude); double lonRange = System.Math.Abs(location2.Longitude - location.Longitude); query = (from i in query where i.Latitude != null && i.Longitude != null where i.Latitude > location.Latitude - latRange && i.Latitude <location.Latitude + latRange where i.Longitude> location.Longitude - lonRange && i.Longitude < location.Longitude + lonRange orderby System.Math.Abs(i.Latitude.Value - location.Latitude) + System.Math.Abs(i.Longitude.Value - location.Longitude) select i); } var items = (from i in query let lastEdit = i.VenueEdits.OrderByDescending(e => e.Time).FirstOrDefault() let lastContributor = lastEdit != null ? lastEdit.Athlete : null let lastContributorDate = lastEdit != null ? (DateTime?)lastEdit.Time : null //let lastContributor = i.VenueEdits.OrderByDescending(e => e.Time).Select(e => e.Athlete).FirstOrDefault() select new { Venue = i, LastContributor = lastContributor, LastContributorDate = lastContributorDate }).Take(100).ToList(); var venues = (from i in items select VenueWebModel.FromVenue(i.Venue, location, i.LastContributor, i.LastContributorDate)).ToList(); if (location == null || searchLargerRadiusIfNeeded == false) { return(venues); } if (venues.Count > 1) { return(venues); } if (venues.Count == 1 && km == kmAway.Last()) { return(venues); } } } catch (Exception) { return(null); } return(new List <VenueWebModel>()); }
public EditVenuePage(VenueWebModel venue) { this.Venue = venue; this.Title = "Edit / Verify Venue"; this.BackgroundColor = Color.White; double pickerHeight = Config.IsIOS ? 20 : 35; //Config.DefaultFontSize * 1.6; double buttonHeight = Config.IsIOS ? 20 : 35; double buttonWidth = (Config.IsAndroid ? 90 : 70) + (Config.IsTablet ? 30 : 0); switchValidVenue = new Switch() { }; switchValidVenue.IsToggled = !venue.IsInvalid; switchValidVenue.Toggled += (s1, e1) => { this.updateReadonly(); }; entryPhone = new BybStandardEntry() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, TextColor = Config.ColorBlackTextOnWhite, Placeholder = "phone #" }; if (venue.HasPhoneNumber) { entryPhone.Text = venue.PhoneNumber; } entryPhone.Keyboard = Keyboard.Telephone; this.buttonPhone = new BybButton() { Text = "call", HeightRequest = buttonHeight, WidthRequest = buttonWidth, VerticalOptions = LayoutOptions.Center, Style = (Style)App.Current.Resources["SimpleButtonStyle"] }; buttonPhone.Clicked += (s1, e1) => { if (this.entryPhone.Text.Trim() != "") { App.Navigator.OpenPhoneCallApp(this.entryPhone.Text); } }; entryWebsite = new BybStandardEntry() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Placeholder = "website, optional" }; if (venue.HasWebsite) { entryWebsite.Text = venue.Website; } this.buttonWebsite = new BybButton() { Text = "browse", HeightRequest = buttonHeight, WidthRequest = buttonWidth, VerticalOptions = LayoutOptions.Center, Style = (Style)App.Current.Resources["SimpleButtonStyle"], HorizontalOptions = LayoutOptions.End }; buttonWebsite.Clicked += (s1, e1) => { if (this.entryWebsite.Text.Trim() != "") { App.Navigator.OpenBrowserApp(this.entryWebsite.Text); } }; entryAddress = new BybStandardEntry() { HorizontalOptions = LayoutOptions.Fill, Placeholder = "address, optional" }; if (venue.HasAddress) { entryAddress.Text = venue.Address; } double height_MapAndTables = Config.IsTablet ? 180 : 130; this.map = new Xamarin.Forms.Maps.Map() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, IsShowingUser = true, }; picker10fTables = new BybWithBorderPicker() { Title = "Set number of 10' tables", HeightRequest = pickerHeight }; picker12fTables = new BybWithBorderPicker() { Title = "Set number of 12' tables", HeightRequest = pickerHeight }; for (int i = 0; i < 40; ++i) { picker10fTables.Items.Add(i.ToString()); picker12fTables.Items.Add(i.ToString()); } if (venue.NumberOf10fSnookerTables != null) { picker10fTables.SelectedIndex = venue.NumberOf10fSnookerTables.Value; } if (venue.NumberOf12fSnookerTables != null) { picker12fTables.SelectedIndex = venue.NumberOf12fSnookerTables.Value; } this.buttonPOIs = new BybButton() { Text = "query the Internet", HorizontalOptions = LayoutOptions.Start, HeightRequest = buttonHeight, Style = (Style)App.Current.Resources["SimpleButtonStyle"] }; this.buttonPOIs.Clicked += buttonPOIs_Clicked; this.labelPOIsWaiting = new BybLabel() { Text = "loading...", HorizontalOptions = LayoutOptions.Start, HeightRequest = buttonHeight, IsVisible = false, TextColor = Config.ColorBlackTextOnWhite }; this.buttonOk = new BybButton { Text = "Yep, I Confirm", Style = (Style)App.Current.Resources["LargeButtonStyle"] }; var buttonCancel = new BybButton { Style = (Style)App.Current.Resources["BlackButtonStyle"], Text = "Cancel" }; buttonOk.Clicked += buttonOk_Clicked; buttonCancel.Clicked += buttonCancel_Clicked; // this.buttonConfirm = new BybButton() { Text = "Yes, this information is correct", Style = (Style)App.Current.Resources["SimpleButtonStyle"], TextColor = Config.ColorTextOnBackground, HeightRequest = buttonHeight }; // this.buttonConfirm.Clicked += (s, e) => // { // this.buttonConfirm.Text = "Fellow snooker players say 'thank you'"; // this.buttonConfirm.TextColor = Config.ColorTextOnBackgroundGrayed; // this.updateOkButton(true); // }; var aboutGrid = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(10, 0, 0, 0), ColumnSpacing = 0, RowSpacing = 3, RowDefinitions = { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(buttonWidth, GridUnitType.Absolute) }, } }; aboutGrid.Children.Add(entryPhone, 0, 0); aboutGrid.Children.Add(buttonPhone, 1, 0); aboutGrid.Children.Add(entryWebsite, 0, 1); aboutGrid.Children.Add(buttonWebsite, 1, 1); aboutGrid.Children.Add(entryAddress, 0, 2, 2, 3); aboutGrid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new BybLabel { Text = "Valid snooker venue", VerticalTextAlignment = TextAlignment.Center, TextColor = Config.ColorBlackTextOnWhite }, switchValidVenue, } }, 0, 3); var theStackLayout = new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 10, Children = { new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 3, Padding = new Thickness(10, 10, 10, 0), Children = { new BybLabel { Text = venue.Name, FontAttributes = FontAttributes.Bold, TextColor = Config.ColorBlackTextOnWhite }, new BybLabel { Text = venue.MetroName ?? "", TextColor = Config.ColorBlackTextOnWhite }, } }, new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(0), HeightRequest = height_MapAndTables, Children = { map, new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 3, Padding = new Thickness(10, 0, 10, 0), WidthRequest = 60, VerticalOptions = LayoutOptions.CenterAndExpand, Children = { new BybLabel { Text = "10' tables",VerticalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center, TextColor = Config.ColorBlackTextOnWhite }, picker10fTables, new BybLabel { Text = "12' tables",VerticalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Center, TextColor = Config.ColorBlackTextOnWhite }, picker12fTables, } }, } }, new StackLayout { Orientation = StackOrientation.Vertical, Spacing = 3, Padding = new Thickness(10, 10, 10, 0), Children = { new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { new BybLabel { Text = "About the venue:", HorizontalTextAlignment = TextAlignment.Start, HorizontalOptions = LayoutOptions.FillAndExpand, TextColor = Config.ColorBlackTextOnWhite }, buttonPOIs, labelPOIsWaiting } }, } }, aboutGrid } }; Content = new StackLayout() { Orientation = StackOrientation.Vertical, Children = { new ScrollView() { Padding = new Thickness(0), VerticalOptions = LayoutOptions.FillAndExpand, Content = theStackLayout }, new BoxView() { Style = (Style)App.Current.Resources["BoxViewPadding1Style"], VerticalOptions = LayoutOptions.FillAndExpand, HeightRequest = 2 }, new StackLayout() { Orientation = StackOrientation.Vertical, BackgroundColor = Config.ColorBlackBackground, HorizontalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(0, 0, 0, 0), Children = { // new StackLayout // { // Orientation = StackOrientation.Horizontal, // HorizontalOptions = LayoutOptions.Center, // VerticalOptions = LayoutOptions.Center, // Padding = new Thickness(0,15,0,5), // Children = // { // buttonConfirm // } // }, new StackLayout { Spacing = Config.SpaceBetweenButtons, Padding = new Thickness(10, 10, 10, 10), Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = Config.OkCancelButtonsHeight, //Padding = new Thickness(Config.OkCancelButtonsPadding), Children = { buttonCancel, buttonOk, } } } } } }; // update the map var position = new Xamarin.Forms.Maps.Position(venue.Latitude ?? 0, venue.Longitude ?? 0); double latlongdegrees = 0.005; map.MoveToRegion(new Xamarin.Forms.Maps.MapSpan(position, latlongdegrees, latlongdegrees)); map.Pins.Clear(); if (venue.Location != null) { var pin = new Pin { Type = PinType.Generic, Position = position, Label = this.Venue.Name, }; pin.Clicked += (s1, e1) => { App.Navigator.OpenMapsApp(Venue.Location, Venue.Name, Venue.Address); }; map.Pins.Add(pin); } //updateOkButton(false); updateReadonly(); }