示例#1
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;
            }
        }
示例#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();
            }
        }
示例#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();
            }
        }
示例#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();
            }
        }
示例#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();
            }
        }
        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;
            }
        }
示例#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;
            }
        }
示例#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;
            }
        }
示例#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;
            }
        }