コード例 #1
0
ファイル: SampleData.cs プロジェクト: johndelfGM/NerdDinner
        private static Dinner[] GetDinners()
        {
            var dinners = new Dinner[]
                {
                new Dinner { Title = "Test Dinner One", Address = "Seattle, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner One", EventDate = DateTime.Now, UserName = "******", Latitude = 47.671798706054688, Longitude = -122.12323760986328 },
                new Dinner { Title = "Test Dinner Two", Address = "Redmond, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Two", EventDate = DateTime.Now.AddDays(1), UserName = "******", Latitude = 47.671798706054688, Longitude = -122.12323760986328 },
                new Dinner { Title = "Test Dinner Three", Address = "New York", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Three", EventDate = DateTime.Now.AddDays(2), UserName = "******", Latitude = 40.712784, Longitude = 74.005941 },
                new Dinner { Title = "Test Dinner Four", Address = "Chicago", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Four", EventDate = DateTime.Now.AddDays(3), UserName = "******", Latitude = 41.878114, Longitude = -87.629798 },
                new Dinner { Title = "Test Dinner Five", Address = "San Francisco", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Five", EventDate = DateTime.Now.AddDays(4), UserName = "******", Latitude = 33.748995, Longitude = -84.387982 },
                new Dinner { Title = "Test Dinner Six", Address = "Atlanta", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Six", EventDate = DateTime.Now.AddDays(5), UserName = "******", Latitude = 39.739236, Longitude = -104.990251 },
                new Dinner { Title = "Test Dinner Seven", Address = "Denver", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Seven", EventDate = DateTime.Now.AddDays(6), UserName = "******", Latitude = 39.952584, Longitude = -75.165222 },
                new Dinner { Title = "Test Dinner Eight", Address = "Pittsburgh", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Eight", EventDate = DateTime.Now.AddDays(7), UserName = "******", Latitude = 37.774929, Longitude = -122.4194160 },
                new Dinner { Title = "Test Dinner Nine", Address = "Kirkland, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Nine", EventDate = DateTime.Now.AddDays(8), UserName = "******", Latitude = 31.968599, Longitude = -99.901813 },
                new Dinner { Title = "Test Dinner Ten", Address = "Bellevue, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Ten", EventDate = DateTime.Now.AddDays(9), UserName = "******", Latitude = 33.748995, Longitude = 74.005941 },
                };

            return dinners;
        }
コード例 #2
0
ファイル: GeoLocation.cs プロジェクト: johndelfGM/NerdDinner
        public static void SearchByPlaceNameOrZip(Dinner dinner)
        {
            string url = "http://ws.geonames.org/postalCodeSearch?{0}={1}&maxRows=1&style=SHORT&username=nerddinner";
            int n;
            bool isNumeric = int.TryParse(dinner.Address, out n);
            url = String.Format(url, isNumeric ? "postalcode" : "placename", dinner.Address);

            var result = XDocument.Load(url);

            if (result.Descendants("code").Any())
            {
                var latLong = (from x in result.Descendants("code")
                               select new LatLong
                               {
                                   Lat = (float)x.Element("lat"),
                                   Long = (float)x.Element("lng")
                               }).First();

                dinner.Latitude = latLong.Lat;
                dinner.Longitude = latLong.Long;
            }
        }
コード例 #3
0
ファイル: SampleData.cs プロジェクト: luckybawa/Nerd_Dinner
        private static Dinner[] GetDinners()
        {
            var dinners = new Dinner[]
            {
                new Dinner {
                    Title = "Test Dinner One", Address = "Seattle, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner One", EventDate = DateTime.Now, UserName = "******", Latitude = 47.671798706054688, Longitude = -122.12323760986328
                },
                new Dinner {
                    Title = "Test Dinner Two", Address = "Redmond, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Two", EventDate = DateTime.Now.AddDays(1), UserName = "******", Latitude = 47.671798706054688, Longitude = -122.12323760986328
                },
                new Dinner {
                    Title = "Test Dinner Three", Address = "New York", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Three", EventDate = DateTime.Now.AddDays(2), UserName = "******", Latitude = 40.712784, Longitude = 74.005941
                },
                new Dinner {
                    Title = "Test Dinner Four", Address = "Chicago", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Four", EventDate = DateTime.Now.AddDays(3), UserName = "******", Latitude = 41.878114, Longitude = -87.629798
                },
                new Dinner {
                    Title = "Test Dinner Five", Address = "San Francisco", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Five", EventDate = DateTime.Now.AddDays(4), UserName = "******", Latitude = 33.748995, Longitude = -84.387982
                },
                new Dinner {
                    Title = "Test Dinner Six", Address = "Atlanta", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Six", EventDate = DateTime.Now.AddDays(5), UserName = "******", Latitude = 39.739236, Longitude = -104.990251
                },
                new Dinner {
                    Title = "Test Dinner Seven", Address = "Denver", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Seven", EventDate = DateTime.Now.AddDays(6), UserName = "******", Latitude = 39.952584, Longitude = -75.165222
                },
                new Dinner {
                    Title = "Test Dinner Eight", Address = "Pittsburgh", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Eight", EventDate = DateTime.Now.AddDays(7), UserName = "******", Latitude = 37.774929, Longitude = -122.4194160
                },
                new Dinner {
                    Title = "Test Dinner Nine", Address = "Kirkland, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Nine", EventDate = DateTime.Now.AddDays(8), UserName = "******", Latitude = 31.968599, Longitude = -99.901813
                },
                new Dinner {
                    Title = "Test Dinner Ten", Address = "Bellevue, WA", ContactPhone = "425-XXX-XXXX", Country = "USA", Description = "Test Dinner Ten", EventDate = DateTime.Now.AddDays(9), UserName = "******", Latitude = 33.748995, Longitude = 74.005941
                },
            };

            return(dinners);
        }
コード例 #4
0
        public virtual async Task<Dinner> CreateDinnerAsync(Dinner dinner)
        {
            var rsvp = new Rsvp
            {
                UserName = dinner.UserName
            };

            dinner.Rsvps = new List<Rsvp> { rsvp };

            _database.Add(dinner);
            _database.Add(rsvp);
            await _database.SaveChangesAsync();

            return dinner;
        }
コード例 #5
0
        public virtual async Task DeleteRsvpAsync(Dinner dinner, string userName)
        {
            var rsvp = dinner?.Rsvps.SingleOrDefault(r => string.Equals(r.UserName, userName, StringComparison.OrdinalIgnoreCase));
            if (rsvp != null)
            {
                _database.Rsvp.Remove(rsvp);
                await _database.SaveChangesAsync();
            };

            // Else no errors - this operation is idempotent
        }
コード例 #6
0
        public virtual async Task<Rsvp> CreateRsvpAsync(Dinner dinner, string userName)
        {
            Rsvp rsvp = null;
            if (dinner != null)
            {
                if (dinner.IsUserRegistered(userName))
                {
                    rsvp = dinner.Rsvps.SingleOrDefault(r => string.Equals(r.UserName, userName, StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    rsvp = new Rsvp
                    {
                        UserName = userName
                    };

                    dinner.Rsvps.Add(rsvp);
                    _database.Add(rsvp);
                    await _database.SaveChangesAsync();
                }
            }

            return rsvp;
        }
コード例 #7
0
 public virtual async Task<Dinner> UpdateDinnerAsync(Dinner dinner)
 {
     _database.Update(dinner);
     await _database.SaveChangesAsync();
     return dinner;
 }