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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }