Ejemplo n.º 1
0
        public DTO.Animal CreateAnimal(DTO.Animal animal)
        {
            using (var context = new SaguContext())
            {
                context.Animals.Add(animal.AsEntity());
                context.SaveChanges();

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

                return area;
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
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;
            }
        }