예제 #1
0
        public void Insert(PersonDetailModel person)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var entity = _mapper.MapDetailModelToEntity(person);
                entity.Id = Guid.NewGuid();

                directoryDbContext.Persons.Add(entity);
                directoryDbContext.SaveChanges();
            }
        }
예제 #2
0
        public void Insert(AddressDetailModel model)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var person = directoryDbContext.Persons.First(p => p.Id == model.PersonId);
                var entity = _mapper.MapDetailModelToEntity(model, person);
                entity.Id = Guid.NewGuid();

                directoryDbContext.Adresses.Add(entity);
                directoryDbContext.SaveChanges();
            }
        }
예제 #3
0
        public void Update(AddressDetailModel address)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var entity = directoryDbContext.Adresses.First(p => p.Id == address.Id);

                entity.City    = address.City;
                entity.Street  = address.Street;
                entity.ZipCode = address.ZipCode;

                directoryDbContext.SaveChanges();
            }
        }
예제 #4
0
        public void Update(PersonDetailModel person)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var entity = directoryDbContext.Persons.First(p => p.Id == person.Id);

                entity.FirstName = person.FirstName;
                entity.LastName  = person.LastName;
                entity.IN        = person.IN;
                entity.TIN       = person.TIN;

                directoryDbContext.SaveChanges();
            }
        }
예제 #5
0
        public void Remove(Guid addressId, Guid personId)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var person = directoryDbContext.Persons.First(p => p.Id == personId);
                var entity = new Address()
                {
                    Id = addressId, Person = person
                };
                directoryDbContext.Adresses.Attach(entity);

                directoryDbContext.Adresses.Remove(entity);
                directoryDbContext.SaveChanges();
            }
        }
예제 #6
0
        public void Remove(Guid personId)
        {
            using (var directoryDbContext = new DirectoryDbContext())
            {
                var addresses = directoryDbContext.Adresses.Where(a => a.Person.Id == personId).ToList();
                var entity    = new Person()
                {
                    Id = personId, Adresses = addresses
                };
                directoryDbContext.Persons.Attach(entity);

                directoryDbContext.Persons.Remove(entity);
                directoryDbContext.SaveChanges();
            }
        }