public async Task Save(Vehicle vehicle, long claimDbId) { var claimInsured = ClaimInsuredVehicleDB.NewInstance(); claimInsured.Vehicle = vehicle.Adapt <VehicleDB>(); claimInsured.ClaimId = claimDbId; claimInsured.Claim = null; applicationDbContext.ClaimInsuredVehicles.Add(claimInsured); applicationDbContext.SaveChanges(); }
private async Task DeleteClaimVehicle(ClaimInsuredVehicleDB claimInsuredVehicle) { var vehicle = claimInsuredVehicle.Vehicle; claimInsuredVehicle.Claim = null; claimInsuredVehicle.Vehicle = null; applicationDbContext.ClaimInsuredVehicles.Remove(claimInsuredVehicle); applicationDbContext.Vehicles.Remove(vehicle); applicationDbContext.SaveChanges(); }
public ClaimDB Map(Claim claim) { var claimDb = claim.Adapt <ClaimDB>(); if (claimDb == null) { return(claimDb); } if (claim.Adress != null) { claimDb.Adress = new AdressDB(); claimDb.Adress = claim.Adress.Adapt <AdressDB>(); } if (claim.State != null) { claimDb.State = null; claimDb.StateId = claim.StateId; } if (claim.ClaimInsuredPersons != null && claim.ClaimInsuredPersons.Any()) { claimDb.ClaimInsuredPersons = new List <ClaimInsuredPersonDB>(); claim.ClaimInsuredPersons.ForEach(person => { ClaimInsuredPersonDB claimInsured = ClaimInsuredPersonDB.NewInstance(); claimInsured.Person = person.Adapt <PersonDB>(); if (person.Id > 0) { claimInsured.PersonId = person.Id; } if (claimDb.Id > 0) { claimInsured.ClaimId = claimDb.Id; } claimDb.ClaimInsuredPersons.Add(claimInsured); }); } if (claim.ClaimThirdInsuredPersons != null && claim.ClaimThirdInsuredPersons.Any()) { claimDb.ClaimThirdInsuredPersons = new List <ClaimThirdInsuredPersonDB>(); claim.ClaimThirdInsuredPersons.ForEach(person => { ClaimThirdInsuredPersonDB claimThirdInsured = ClaimThirdInsuredPersonDB.NewInstance(); claimThirdInsured.Person = person.Adapt <PersonDB>(); if (person.Id > 0) { claimThirdInsured.PersonId = person.Id; } if (claimDb.Id > 0) { claimThirdInsured.ClaimId = claimDb.Id; } claimDb.ClaimThirdInsuredPersons.Add(claimThirdInsured); }); } if (claim.ClaimInsuredVehicles != null && claim.ClaimInsuredVehicles.Any()) { claimDb.ClaimInsuredVehicles = new List <ClaimInsuredVehicleDB>(); claim.ClaimInsuredVehicles.ForEach(vehicle => { ClaimInsuredVehicleDB claimVehicle = ClaimInsuredVehicleDB.NewInstance(); claimVehicle.Vehicle = vehicle.Adapt <VehicleDB>(); if (vehicle.Id > 0) { claimVehicle.VehicleId = vehicle.Id; } if (claimDb.Id > 0) { claimVehicle.ClaimId = claimDb.Id; } claimDb.ClaimInsuredVehicles.Add(claimVehicle); }); } if (claim.ClaimThirdInsuredVehicles != null && claim.ClaimThirdInsuredVehicles.Any()) { claimDb.ClaimThirdInsuredVehicles = new List <ClaimThirdInsuredVehicleDB>(); claim.ClaimThirdInsuredVehicles.ForEach(vehicle => { ClaimThirdInsuredVehicleDB claimThirdVehicle = ClaimThirdInsuredVehicleDB.NewInstance(); claimThirdVehicle.Vehicle = vehicle.Adapt <VehicleDB>(); if (vehicle.Id > 0) { claimThirdVehicle.VehicleId = vehicle.Id; } if (claimDb.Id > 0) { claimThirdVehicle.ClaimId = claimDb.Id; } claimDb.ClaimThirdInsuredVehicles.Add(claimThirdVehicle); }); } if (claim.ClaimMessages != null && claim.ClaimMessages.Any()) { claimDb.ClaimMessages = new List <ClaimMessageDB>(); claim.ClaimThirdInsuredVehicles.ForEach(claimMessage => { claimDb.ClaimMessages.Add(claimMessage.Adapt <ClaimMessageDB>()); }); } return(claimDb); }