File: Cities.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (304 lines) | stat: -rw-r--r-- 9,708 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;

namespace Microsoft.Web.Http.Data.Test.Models
{
    /// <summary>
    /// Sample data class
    /// </summary>
    /// <remarks>
    /// This class exposes several data types (City, County, State and Zip) and some sample
    /// data for each. 
    /// </remarks>
    public partial class CityData
    {
        private List<State> _states;
        private List<County> _counties;
        private List<City> _cities;
        private List<Zip> _zips;
        private List<ZipWithInfo> _zipsWithInfo;
        private List<CityWithInfo> _citiesWithInfo;

        public CityData()
        {
            _states = new List<State>()
            {
                new State() { Name="WA", FullName="Washington", TimeZone = TimeZone.Pacific },
                new State() { Name="OR", FullName="Oregon", TimeZone = TimeZone.Pacific },
                new State() { Name="CA", FullName="California", TimeZone = TimeZone.Pacific },
                new State() { Name="OH", FullName="Ohio", TimeZone = TimeZone.Eastern, ShippingZone=ShippingZone.Eastern }
            };

            _counties = new List<County>()
             {
                new County() { Name="King",         StateName="WA" },
                new County() { Name="Pierce",       StateName="WA" },
                new County() { Name="Snohomish",    StateName="WA" },

                new County() { Name="Tillamook",    StateName="OR" },
                new County() { Name="Wallowa",      StateName="OR" },
                new County() { Name="Jackson",      StateName="OR" },

                new County() { Name="Orange",       StateName="CA" },
                new County() { Name="Santa Barbara",StateName="CA" },

                new County() { Name="Lucas",        StateName="OH" }
            };
            foreach (State state in _states)
            {
                foreach (County county in _counties.Where(p => p.StateName == state.Name))
                {
                    state.Counties.Add(county);
                    county.State = state;
                }
            }

            _cities = new List<City>()
            {
                new CityWithInfo() {Name="Redmond", CountyName="King", StateName="WA", Info="Has Microsoft campus", LastUpdated=DateTime.Now},
                new CityWithInfo() {Name="Bellevue", CountyName="King", StateName="WA", Info="Means beautiful view", LastUpdated=DateTime.Now},
                new City() {Name="Duvall", CountyName="King", StateName="WA"},
                new City() {Name="Carnation", CountyName="King", StateName="WA"},
                new City() {Name="Everett", CountyName="King", StateName="WA"},
                new City() {Name="Tacoma", CountyName="Pierce", StateName="WA"},

                new City() {Name="Ashland", CountyName="Jackson", StateName="OR"},

                new City() {Name="Santa Barbara", CountyName="Santa Barbara", StateName="CA"},
                new City() {Name="Orange", CountyName="Orange", StateName="CA"},

                new City() {Name="Oregon", CountyName="Lucas", StateName="OH"},
                new City() {Name="Toledo", CountyName="Lucas", StateName="OH"}
            };

            _citiesWithInfo = new List<CityWithInfo>(this._cities.OfType<CityWithInfo>());

            foreach (County county in _counties)
            {
                foreach (City city in _cities.Where(p => p.CountyName == county.Name && p.StateName == county.StateName))
                {
                    county.Cities.Add(city);
                    city.County = county;
                }
            }

            _zips = new List<Zip>()
            {
                new Zip() { Code=98053, FourDigit=8625, CityName="Redmond", CountyName="King", StateName="WA" },
                new ZipWithInfo() { Code=98052, FourDigit=8300, CityName="Redmond", CountyName="King", StateName="WA", Info="Microsoft" },
                new Zip() { Code=98052, FourDigit=6399, CityName="Redmond", CountyName="King", StateName="WA" },
            };

            _zipsWithInfo = new List<ZipWithInfo>(this._zips.OfType<ZipWithInfo>());

            foreach (City city in _cities)
            {
                foreach (Zip zip in _zips.Where(p => p.CityName == city.Name && p.CountyName == city.CountyName && p.StateName == city.StateName))
                {
                    city.ZipCodes.Add(zip);
                    zip.City = city;
                }
            }

            foreach (CityWithInfo city in _citiesWithInfo)
            {
                foreach (ZipWithInfo zip in _zipsWithInfo.Where(p => p.CityName == city.Name && p.CountyName == city.CountyName && p.StateName == city.StateName))
                {
                    city.ZipCodesWithInfo.Add(zip);
                    zip.City = city;
                }
            }
        }

        public List<State> States { get { return this._states; } }
        public List<County> Counties { get { return this._counties; } }
        public List<City> Cities { get { return this._cities; } }
        public List<CityWithInfo> CitiesWithInfo { get { return this._citiesWithInfo; } }
        public List<Zip> Zips { get { return this._zips; } }
        public List<ZipWithInfo> ZipsWithInfo { get { return this._zipsWithInfo; } }
    }

    /// <summary>
    /// These types are simple data types that can be used to build
    /// mocks and simple data stores.
    /// </summary>
    public partial class State
    {
        private readonly List<County> _counties = new List<County>();

        [Key]
        public string Name { get; set; }
        [Key]
        public string FullName { get; set; }
        public TimeZone TimeZone { get; set; }
        public ShippingZone ShippingZone { get; set; }
        public List<County> Counties { get { return this._counties; } }
    }

    [DataContract(Name = "CityName", Namespace = "CityNamespace")]
    public enum ShippingZone
    {
        [EnumMember(Value = "P")]
        Pacific = 0,    // default

        [EnumMember(Value = "C")]
        Central,

        [EnumMember(Value = "E")]
        Eastern
    }

    public enum TimeZone
    {
        Central,
        Mountain,
        Eastern,
        Pacific
    }

    public partial class County
    {
        public County()
        {
            Cities = new List<City>();
        }

        [Key]
        public string Name { get; set; }
        [Key]
        public string StateName { get; set; }

        [IgnoreDataMember]
        public State State { get; set; }

        public List<City> Cities { get; set; }
    }

    [KnownType(typeof(CityWithEditHistory))]
    [KnownType(typeof(CityWithInfo))]
    public partial class City
    {
        public City()
        {
            ZipCodes = new List<Zip>();
        }

        [Key]
        public string Name { get; set; }
        [Key]
        public string CountyName { get; set; }
        [Key]
        public string StateName { get; set; }

        [IgnoreDataMember]
        public County County { get; set; }
        public string ZoneName { get; set; }
        public string CalculatedCounty { get { return this.CountyName; } set { } }
        public int ZoneID { get; set; }

        public List<Zip> ZipCodes { get; set; }

        public override string ToString()
        {
            return this.GetType().Name + " Name=" + this.Name + ", State=" + this.StateName + ", County=" + this.CountyName;
        }

        public int this[int index]
        {
            get
            {
                return index;
            }
            set
            {
            }
        }
    }

    public abstract partial class CityWithEditHistory : City
    {
        private string _editHistory;

        public CityWithEditHistory()
        {
            this.EditHistory = "new";
        }

        // Edit history always appends, never overwrites
        public string EditHistory
        {
            get
            {
                return this._editHistory;
            }
            set
            {
                this._editHistory = this._editHistory == null ? value : (this._editHistory + "," + value);
                this.LastUpdated = DateTime.Now;
            }
        }

        public DateTime LastUpdated
        {
            get;
            set;
        }

        public override string ToString()
        {
            return base.ToString() + ", History=" + this.EditHistory + ", Updated=" + this.LastUpdated;
        }

    }

    public partial class CityWithInfo : CityWithEditHistory
    {
        public CityWithInfo()
        {
            ZipCodesWithInfo = new List<ZipWithInfo>();
        }

        public string Info
        {
            get;
            set;
        }

        public List<ZipWithInfo> ZipCodesWithInfo { get; set; }

        public override string ToString()
        {
            return base.ToString() + ", Info=" + this.Info;
        }

    }

    [KnownType(typeof(ZipWithInfo))]
    public partial class Zip
    {
        [Key]
        public int Code { get; set; }
        [Key]
        public int FourDigit { get; set; }
        public string CityName { get; set; }
        public string CountyName { get; set; }
        public string StateName { get; set; }

        [IgnoreDataMember]
        public City City { get; set; }
    }

    public partial class ZipWithInfo : Zip
    {
        public string Info
        {
            get;
            set;
        }
    }
}