public async Task <RegixPersonModel> AddRegixPersonAsync(RegixPersonModel model) { if (model == null) { throw new NullReferenceException("RegixPersonModel is null"); } RegixPersonModel existing = await _context.RegixPerson .Where(x => x.Identifier == model.Identifier && String.Equals(x.FirstName, model.FirstName) && String.Equals(x.MiddleName, model.MiddleName) && String.Equals(x.LastName, model.LastName) && x.DateOfBirth == model.DateOfBirth && x.DateOfDeath == model.DateOfDeath) .Select(x => x.ToModel()) .FirstOrDefaultAsync(); if (existing != null) { return(existing); } var person = model.ToEntity(); await _context.RegixPerson.AddAsync(person); await _context.SaveChangesAsync(); model.Id = person.Id; return(model); }
public async Task <RegixPersonModel> GetPersonFromRegixAsync(string identifier) { PersonSearchResultModel result = await _integrationService.GetPersonFromRegiXAsync(identifier); RegixPersonModel person = GetPersonViewModelFromResponse(result, identifier); return(person); }
public static RegixPersonModel ToViewModel(this RegiX.Client.ResponseModels.ValidPersonResponse model) { if (model == null) { return(null); } RegixPersonModel viewModel = new RegixPersonModel { Id = -1, FirstName = model.FirstName, MiddleName = model.SurName, LastName = model.FamilyName, DateOfBirth = model.BirthDateSpecified ? DateTime.SpecifyKind(model.BirthDate, DateTimeKind.Utc) : default(DateTime?), DateOfDeath = model.DeathDateSpecified ? DateTime.SpecifyKind(model.DeathDate, DateTimeKind.Utc) : default(DateTime?), }; return(viewModel); }
public static RegixPerson ToEntity(this RegixPersonModel model) { if (model == null) { return(null); } RegixPerson entity = new RegixPerson { Identifier = model.Identifier, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, DateOfBirth = model.DateOfBirth.HasValue == true?DateTime.SpecifyKind(model.DateOfBirth.Value, DateTimeKind.Utc) : default(DateTime?), DateOfDeath = model.DateOfDeath.HasValue == true?DateTime.SpecifyKind(model.DateOfDeath.Value, DateTimeKind.Utc) : default(DateTime?), RequestId = model.RequestId, UpdatedAt = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), }; return(entity); }
private RegixPersonModel GetPersonViewModelFromResponse(PersonSearchResultModel result, string searchIdentifier) { if (result == null || result.ResponseObject == null) { return(null); } ValidPersonResponse personResponse = result.ResponseObject as ValidPersonResponse; if (personResponse == null) { throw new Exception("Could not convert response to ValidPersonResponse"); } RegixPersonModel model = personResponse.ToViewModel(); model.RequestId = result.RequestId; model.Identifier = searchIdentifier; return(model); }
public static RegixPersonModel ToModel(this RegixPerson entity) { if (entity == null) { return(null); } RegixPersonModel model = new RegixPersonModel { Id = entity.Id, Identifier = entity.Identifier, FirstName = entity.FirstName, MiddleName = entity.MiddleName, LastName = entity.LastName, DateOfBirth = entity.DateOfBirth.HasValue == true?DateTime.SpecifyKind(entity.DateOfBirth.Value, DateTimeKind.Utc) : default(DateTime?), DateOfDeath = entity.DateOfDeath.HasValue == true?DateTime.SpecifyKind(entity.DateOfDeath.Value, DateTimeKind.Utc) : default(DateTime?), RequestId = entity.RequestId, UpdatedAt = entity.UpdatedAt.HasValue == true?DateTime.SpecifyKind(entity.UpdatedAt.Value, DateTimeKind.Utc) : default(DateTime?), }; return(model); }
public async Task <DistraintCreateModel> AddAsync(DistraintCreateModel model) { if (model == null) { throw new NullReferenceException("DistraintCreateModel is null"); } using (var tran = _context.Database.BeginTransaction()) { try { var distraint = model.ToEntity(); if (model.IsNewProperty) { OtherPropertyModel newProperty = await _propertyService.AddOtherPropertyAsync(model.NewOtherProperty); distraint.PropertyIdOtherProperty = newProperty?.Id; } else if (model.PropertyIdVehicle == -1 && !String.IsNullOrEmpty(model.VehicleProperty.RegistrationNumber)) { Vehicle vehicle = await _propertyService.AddOrUpdateVehicleAsync(model.VehicleProperty); distraint.PropertyIdVehicle = vehicle.Id; } else if (model.PropertyIdAircraft == -1 && !String.IsNullOrEmpty(model.AircraftProperty.MsnserialNumber)) { Aircraft aircraft = await _propertyService.AddOrUpdateAircraftAsync(model.AircraftProperty); distraint.PropertyIdAircraft = aircraft.Id; } else if (model.PropertyIdVessel == -1 && !String.IsNullOrEmpty(model.VesselProperty.RegistrationData?.RegistrationNumber)) { Vessel vessel = await _propertyService.AddOrUpdateVesselAsync(model.VesselProperty); distraint.PropertyIdVessel = vessel.Id; } if (distraint.IsInFavourOfPerson) { if (model.InFavourOfPerson != null && !String.IsNullOrWhiteSpace(model.InFavourOfPerson.Identifier)) { RegixPersonModel person = await _personService.AddRegixPersonAsync(model.InFavourOfPerson); distraint.InFavourOfPersonId = person.Id; distraint.InFavourOfCompany = null; distraint.InFavourOfCompanyId = null; } else { throw new Exception("In favour of person missing data!"); } } else { if (model.InFavourOfCompany != null && !String.IsNullOrWhiteSpace(model.InFavourOfCompany.Uic)) { RegixCompanyModel company = await _companyService.AddRegixCompanyAsync(model.InFavourOfCompany); distraint.InFavourOfCompanyId = company.Id; distraint.InFavourOfPerson = null; distraint.InFavourOfPersonId = null; } else { throw new Exception("In favour of company missing data!"); } } if (distraint.IsDebtorPerson) { if (model.DebtorPerson != null && !String.IsNullOrWhiteSpace(model.DebtorPerson.Identifier)) { RegixPersonModel person = await _personService.AddRegixPersonAsync(model.DebtorPerson); distraint.DebtorPersonId = person.Id; distraint.DebtorCompany = null; distraint.DebtorCompanyId = null; } else { throw new Exception("Debtor person missing data!"); } } else { if (model.DebtorCompany != null && !String.IsNullOrWhiteSpace(model.DebtorCompany.Uic)) { RegixCompanyModel company = await _companyService.AddRegixCompanyAsync(model.DebtorCompany); distraint.DebtorCompanyId = company.Id; distraint.DebtorPerson = null; distraint.DebtorPersonId = null; } else { throw new Exception("Debtor company missing data!"); } } await _context.Distraint.AddAsync(distraint); await _context.SaveChangesAsync(); tran.Commit(); model.Id = distraint.Id; return(model); } catch (Exception e) { tran.Rollback(); throw e; } } }