Esempio n. 1
0
        public void ImportDbDataFromJson(string path)
        {
            var ctx = new FluentModel();

            using (ctx)
            {
                var files = Directory.GetFiles(path);

                var teams = ctx.GetAll<WeaponReport>().ToList();

                foreach (var file in files)
                {
                    var fileText = File.ReadAllText(file);
                    var teamReport = JsonConvert.DeserializeObject<WeaponReport>(fileText);

                    var teamReportDb = ctx.WeaponReports.FirstOrDefault(t => t.weaponName == teamReport.weaponName);
                    if (teamReportDb != null)
                    {
                        teamReportDb.weaponId = teamReport.weaponId;
                        teamReportDb.weaponName = teamReport.weaponName;
                        teamReportDb.manufacturer = teamReport.manufacturer;
                    }
                    else
                    {
                        ctx.Add(teamReport);
                        ctx.SaveChanges();
                    }
                }
            }
        }
Esempio n. 2
0
 public void UpdateDatabase()
 {
     using (var context = new FluentModel())
     {
         var schemaHandler = context.GetSchemaHandler();
         this.EnsureDB(schemaHandler);
     }
 }