// Embed relations in request resource: reuse old relation if there is one and it hasn't changed private async Task EmbedRelations(Request request, Request oldRequest = null) { try { if (request.WayOfEntry != null) { if (oldRequest != null && oldRequest.WayOfEntry != null && oldRequest.WayOfEntry.Id == request.WayOfEntry.Id) { request.WayOfEntry = oldRequest.WayOfEntry; } else { request.WayOfEntry = await _wayOfEntryDataProvider.GetByIdAsync(int.Parse(request.WayOfEntry.Id)); } } // Origin cannot be updated. Take origin of oldRequest on update. if (oldRequest != null) { request.Origin = oldRequest.Origin; } else if (request.Origin != null) { request.Origin = await _interventionDataProvider.GetByIdAsync(request.Origin.Id); } // Offer cannot be updated. Take offer of oldRequest on update. if (oldRequest != null) { request.Offer = oldRequest.Offer; } else { request.Offer = null; } if (request.Offer != null && request.Customer == null) { request.Customer = oldRequest.Customer; // Request already has an offer, so it must have a customer } else { if (request.Customer != null) { if (oldRequest != null && oldRequest.Customer != null && oldRequest.Customer.Id == request.Customer.Id) { request.Customer = oldRequest.Customer; } else { request.Customer = await _customerDataProvider.GetByNumberAsync(request.Customer.Id); } } } var includeCustomer = new QuerySet(); includeCustomer.Include.Fields = new string[] { "customer" }; // Contact can only be updated through CaseManager. Take contact of oldRequest on update. if (oldRequest != null) { request.Contact = oldRequest.Contact; } else if (request.Contact != null) { request.Contact = await _contactDataProvider.GetByIdAsync(request.Contact.Id, includeCustomer); } // Building can only be updated through CaseManager. Take building of oldRequest on update. if (oldRequest != null) { request.Building = oldRequest.Building; } else if (request.Building != null) { request.Building = await _buildingDataProvider.GetByIdAsync(request.Building.Id, includeCustomer); } } catch (EntityNotFoundException) { _logger.LogDebug($"Failed to find a related entity"); throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist."); } }
public async Task <Intervention> GetByIdAsync(int id, QuerySet query) { return(await _interventionDataProvider.GetByIdAsync(id, query)); }