Beispiel #1
0
 public DTO.Area GetArea(Guid id)
 {
     using (var context = new SaguContext())
     {
         return GetAreaObjectMaps().FirstOrDefault(a => a.Id == id).Get(a => a.AsDTO());
     }
 }
Beispiel #2
0
 public IEnumerable<DTO.Area> GetAreas()
 {
     using (var context = new SaguContext())
     {
         return GetAreaObjectMaps().Select(a => a.AsDTO());
     }
 }
 public DTO.ExploredArea GetExploredArea(Guid id)
 {
     using (var context = new SaguContext())
     {
         return context.ExploredAreas.Find(id).Get(a => a.AsDTO());
     }
 }
 public IEnumerable<DTO.ExploredArea> GetExploredAreas(Guid explorerId)
 {
     using (var context = new SaguContext())
     {
         return context.ExploredAreas.Include(a => a.Area).Where(a => a.ExplorerId == explorerId).ToList().Select(a => a.AsDTO());
     }
 }
 public IEnumerable<DTO.Explorer> GetExplorers()
 {
     using (var context = new SaguContext())
     {
         return GetExplorerObjectMaps().Select(e => e.AsDTO());
     }
 }
 public DTO.Explorer GetExplorer(Guid id)
 {
     using (var context = new SaguContext())
     {
         return GetExplorerObjectMaps().FirstOrDefault(e => e.Id == id).Get(e => e.AsDTO());
     }
 }
Beispiel #7
0
 private Model.AreaImage GetImage(Guid id)
 {
     using (var context = new SaguContext())
     {
         return context.AreaImages.Find(id);
     }
 }
Beispiel #8
0
 public IEnumerable<DTO.Animal> GetAnimals()
 {
     using (var context = new SaguContext())
     {
         return context.Animals
                         .Include(a => a.Area).ToList().Select(a => a.AsDTO());
     }
 }
Beispiel #9
0
 public DTO.Animal GetAnimal(Guid id)
 {
     using (var context = new SaguContext())
     {
         return context.Animals
                         .Include(a => a.Area).FirstOrDefault(a => a.Id == id).Get(a => a.AsDTO());
     }
 }
Beispiel #10
0
        public DTO.Animal CreateAnimal(DTO.Animal animal)
        {
            using (var context = new SaguContext())
            {
                context.Animals.Add(animal.AsEntity());
                context.SaveChanges();

                return animal;
            }
        }
        public DTO.ExploredArea CreateExploredArea(DTO.ExploredArea area)
        {
            using (var context = new SaguContext())
            {
                context.ExploredAreas.Add(area.AsEntity());
                context.SaveChanges();

                return area;
            }
        }
Beispiel #12
0
        public DTO.Area CreateArea(DTO.Area area)
        {
            using (var context = new SaguContext())
            {
                var newArea = context.Areas.Add(area.AsEntity());
                context.SaveChanges();

                return newArea.AsDTO();
            }
        }
Beispiel #13
0
 private IEnumerable<Sagu.Model.Area> GetAreaObjectMaps()
 {
     using (var context = new SaguContext())
     {
         return context.Areas
                         .Include(a => a.Image)
                         .Include(a => a.Animals)
                         .Include(a => a.Monsters)
                         .ToList();
     }
 }
Beispiel #14
0
        public DTO.Explorer CreateExplorer(DTO.Explorer explorer)
        {
            explorer.Id = Guid.NewGuid();
            explorer.Level = 1;

            using (var context = new SaguContext())
            {
                var newExplorer = context.Explorers.Add(explorer.AsEntity());
                context.SaveChanges();

                return newExplorer.AsDTO();
            }
        }
Beispiel #15
0
 private IEnumerable<Model.Explorer> GetExplorerObjectMaps()
 {
     using (var context = new SaguContext())
     {
         return context.Explorers
                         .Include(e => e.ExploredAreas)
                         .Include(e => e.ExploredAreas.Select(a => a.Area))
                         .Include(e => e.ExploredAreas.Select(a => a.Area.Image))
                         .Include(e => e.ExploredAreas.Select(a => a.Area.Animals))
                         .Include(e => e.ExploredAreas.Select(a => a.Area.Monsters))
                         .ToList();
     }
 }
Beispiel #16
0
        public void DeleteExplorer(Guid id)
        {
            using (var context = new SaguContext())
            {
                var explorerToRemove = context.Explorers.Find(id);

                if (explorerToRemove == null)
                    throw new KeyNotFoundException();

                context.Explorers.Remove(explorerToRemove);
                context.SaveChanges();
            }
        }
Beispiel #17
0
        public void DeleteAnimal(Guid id)
        {
            using (var context = new SaguContext())
            {
                var animalToRemove = context.Animals.Find(id);

                if (animalToRemove == null)
                    throw new KeyNotFoundException();

                context.Animals.Remove(animalToRemove);
                context.SaveChanges();
            }
        }
        public DTO.ExploredArea UpdateExploredArea(DTO.ExploredArea area)
        {
            using (var context = new SaguContext())
            {
                var areaToUpdate = context.ExploredAreas.Find(area.Id);

                if (areaToUpdate == null)
                    throw new KeyNotFoundException();

                areaToUpdate.AmountExplored = area.AmountExplored;
                context.SaveChanges();

                return area;
            }
        }
Beispiel #19
0
        public DTO.Explorer UpdateExplorer(DTO.Explorer explorer)
        {
            using (var context = new SaguContext())
            {
                var explorerToUpdate = context.Explorers.Find(explorer.Id);

                if (explorerToUpdate == null)
                    throw new KeyNotFoundException();

                context.Entry(explorerToUpdate).CurrentValues.SetValues(explorer);
                context.SaveChanges();

                return explorer;
            }
        }
Beispiel #20
0
        public DTO.Animal UpdateAnimal(DTO.Animal animal)
        {
            using (var context = new SaguContext())
            {
                var animalToUpdate = context.Animals.Find(animal.Id);

                if (animalToUpdate == null)
                    throw new KeyNotFoundException();

                context.Entry(animalToUpdate).CurrentValues.SetValues(animal);
                context.SaveChanges();

                return animal;
            }
        }
Beispiel #21
0
        public DTO.Area UpdateArea(DTO.Area area)
        {
            using (var context = new SaguContext())
            {
                var areaToUpdate = context.Areas.Include(a => a.Image).FirstOrDefault(a => a.Id == area.Id);

                if (areaToUpdate == null)
                    throw new KeyNotFoundException();

                areaToUpdate.Image = area.Image.Get(i => i.AsEntity()) ?? areaToUpdate.Image;
                context.Entry(areaToUpdate).CurrentValues.SetValues(area);

                context.SaveChanges();

                return area;
            }
        }