Exemple #1
0
        internal Project EditProject(Project project)
        {
            var old = GetAllProjects().FirstOrDefault(p => p.Id.Equals(project.Id));

            if (old == null)
            {
                return(CreateProject(project));
            }

            var jDb = JsonDatabaseConnection.GetProjectDb(old.Name);

            if (!old.Name.Equals(project.Name))
            {
                jDb.Rename(project.Name);
            }
            _db.Update(project);
            jDb.Update(project);
            foreach (var monsters in GetAllMonsters().Where(m => project.MonsterIds.Contains(m.Id)))
            {
                jDb.Update(monsters);
            }
            foreach (var spell in GetAllSpells().Where(m => project.SpellIds.Contains(m.Id)))
            {
                jDb.Update(spell);
            }
            return(project);
        }
Exemple #2
0
        internal void DeleteProject(Project project)
        {
            var old = GetAllProjects().FirstOrDefault(p => p.Id.Equals(project.Id));

            if (old == null)
            {
                return;
            }
            JsonDatabaseConnection.GetProjectDb(old.Name).Delete();
            _db.Remove(project);
        }
Exemple #3
0
        private void LoadAllProjects(IDatabaseConnection db)
        {
            var allProjects = GetAllProjects();
            var allMonsters = GetAllMonsters();
            var allSpells   = GetAllSpells();
            var jDb         = new JsonDatabaseConnection();

            foreach (var project in jDb.GetAllProjectNames())
            {
                var pDb = JsonDatabaseConnection.GetProjectDb(project);
                foreach (var p in pDb.GetQueryable <Project>().Where(p => !allProjects.Any(mp => p.Id == mp.Id)).ToList())
                {
                    db.Add(p);
                }
                foreach (var m in pDb.GetQueryable <Monster>().Where(m => !allMonsters.Any(mm => m.Id == mm.Id)).ToList())
                {
                    db.Add(m);
                }
                foreach (var s in pDb.GetQueryable <Spell>().Where(s => !allSpells.Any(ms => s.Id == ms.Id)).ToList())
                {
                    db.Add(s);
                }
            }
        }
Exemple #4
0
 internal Project CreateProject(Project project)
 {
     _db.Add(project);
     JsonDatabaseConnection.GetProjectDb(project.Name).Add(project);
     return(project);
 }