/// <summary> /// Delete Identifier /// </summary> /// <param name="context"></param> /// <param name="personId"></param> public void DeleteIdentifier(TestProjectDbContext context, Guid personId) { Person person = context.Person.AsNoTracking().FirstOrDefault(x => x.Id == personId); if (person == null) { throw new ErrorException("Person Id is invalid"); } var identifiers = context.Identifier.Where(x => x.PersonId == personId); foreach (var identifier in identifiers) { context.Entry(identifier).State = EntityState.Deleted; } context.Identifier.RemoveRange(); context.SaveChanges(); }
/// <summary> /// Create Identifier /// </summary> /// <param name="context"></param> /// <param name="model"></param> public void CreateIdentifier(TestProjectDbContext context, Identifier model) { context.Identifier.Add(model); context.Entry(model).State = EntityState.Added; context.SaveChanges(); }
/// <summary> /// update person /// </summary> /// <param name="context"></param> /// <param name="person"></param> public void UpdatePerson(TestProjectDbContext context, Person person) { context.Entry(person).State = EntityState.Modified; context.SaveChanges(); }
/// <summary> /// Create person /// </summary> /// <param name="context"></param> /// <param name="model"></param> public void CreatePerson(TestProjectDbContext context, Person model) { context.Person.Add(model); context.Entry(model).State = EntityState.Added; context.SaveChanges(); }
/// <summary> /// Delete Person /// </summary> /// <param name="context"></param> /// <param name="person"></param> public void DeletePerson(TestProjectDbContext context, Person person) { person.Deleted = true; context.Entry(person).State = EntityState.Modified; context.SaveChanges(); }