Пример #1
0
        public void ImportSuburbs(MyHobbyContext context)
        {
            List <Suburb> suburbs = new List <Suburb>();

            StreamReader sr = null;

            try
            {
                City hk = context.Cities.SingleOrDefault(c => c.EnglishName == "Hong Kong");
                if (hk != null)
                {
                    return;
                }

                hk = new City()
                {
                    Name = "香港", EnglishName = "Hong Kong"
                };
                context.Cities.Add(hk);

                Assembly resourceAssembly = Assembly.GetAssembly(typeof(MyHobby.Resources.LocateThisAssembly));
                Stream   stream           = resourceAssembly.GetManifestResourceStream("MyHobby.Resources.Suburbs_HK.txt");

                sr = new StreamReader(stream);
                if (sr != null)
                {
                    string      line  = sr.ReadLine();
                    SuburbGroup group = null;

                    while (!string.IsNullOrEmpty(line))
                    {
                        string[] fields = SplitCSV(line); //line.Split(',');

                        if (fields.Length == 3)
                        {
                            group = new SuburbGroup()
                            {
                                Name        = fields[1],
                                EnglishName = fields[2],
                                City        = hk
                            };

                            context.SuburbGroups.Add(group);
                        }
                        else
                        {
                            Suburb suburb = new Suburb()
                            {
                                Name        = fields[0],
                                EnglishName = fields[1],
                                SuburbGroup = group
                            };

                            context.Suburbs.Add(suburb);
                        }

                        line = sr.ReadLine();
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }
Пример #2
0
 public BusinessRepository(MyHobbyContext ctx)
 {
     _ctx = ctx;
 }
Пример #3
0
 public UserRepository(MyHobbyContext ctx)
 {
     _ctx = ctx;
 }
Пример #4
0
 public SuburbRepository(MyHobbyContext ctx)
 {
     _ctx = ctx;
 }
Пример #5
0
 public void CallSeed(MyHobbyContext context)
 {
     Seed(context);
 }
Пример #6
0
 public AdminController(MyHobbyContext context)
 {
     _context = context;
 }
Пример #7
0
 public LessonRepository(MyHobbyContext ctx)
 {
     _ctx = ctx;
 }
Пример #8
0
 public SessionRepository(MyHobbyContext ctx)
 {
     _ctx = ctx;
 }