public GTPController(GTPContext context)
        {
            _context = context;

            if (_context.GTPs.Count() == 0)
            {
                _context.GTPs.Add(new MyGTP {
                    Name = "a09"
                });
                _context.GTPs.Add(new MyGTP {
                    Name = "a10"
                });
                _context.SaveChanges();
            }
        }
示例#2
0
        public GTPController(GTPContext context)
        {
            _context = context;
            if (_context.GTPs.Count() == 0)
            {
                using (StreamReader qr = new StreamReader(outjson))
                {
                    string       jsona   = qr.ReadToEnd();
                    List <MyGTP> gtplout = JsonConvert.DeserializeObject <List <MyGTP> >(jsona);//
                    if (gtplout.Count == 0)
                    {
                        using (StreamReader r = new StreamReader(injson))
                        {
                            string json = r.ReadToEnd();
                            JsonSerializerSettings sts = new JsonSerializerSettings();
                            sts.Formatting        = Formatting.Indented;
                            sts.NullValueHandling = NullValueHandling.Include;
                            sts.TraceWriter       = new Newtonsoft.Json.Serialization.DiagnosticsTraceWriter();
                            List <MyGTP> gtpl = JsonConvert.DeserializeObject <List <MyGTP> >(json, sts);//

                            foreach (MyGTP gtp in gtpl)
                            {
                                gtp.SetLength();
                                _context.GTPs.Add(gtp);
                            }
                            _context.SaveChanges();
                        }
                    }
                    else
                    {
                        foreach (MyGTP gtp in gtplout)
                        {
                            gtp.SetLength();
                            _context.GTPs.Add(gtp);
                        }
                        _context.SaveChanges();
                    }
                }
            }
        }