// Embed relations in request resource: reuse old relation if there is one and it hasn't changed private async Task EmbedRelations(Offerline offerline, Offerline oldOfferline = null) { try { if (offerline.VatRate != null) { if (oldOfferline != null && oldOfferline.VatRate != null && oldOfferline.VatRate.Id == offerline.VatRate.Id) { offerline.VatRate = oldOfferline.VatRate; } else { offerline.VatRate = await _vatRateDataProvider.GetByIdAsync(int.Parse(offerline.VatRate.Id)); } } // Offer cannot be updated. Take Offer of oldOfferline on update. if (oldOfferline != null) { offerline.Offer = oldOfferline.Offer; } else { offerline.Offer = await _offerDataProvider.GetByIdAsync(offerline.Offer.Id); } } catch (EntityNotFoundException) { _logger.LogDebug($"Failed to find a related entity"); throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist."); } }
// Embed relations in request resource: reuse old relation if there is one and it hasn't changed private async Task EmbedRelations(Offer offer, Offer oldOffer = null) { try { if (offer.VatRate != null) { if (oldOffer != null && oldOffer.VatRate != null && oldOffer.VatRate.Id == offer.VatRate.Id) { offer.VatRate = oldOffer.VatRate; } else { offer.VatRate = await _vatRateDataProvider.GetByIdAsync(int.Parse(offer.VatRate.Id)); } } else { // Offer must have a VAT rate. Take VAT rate of oldOffer if none is passed. if (oldOffer != null) { offer.VatRate = oldOffer.VatRate; _logger.LogDebug("Received an update for offer {0} without a VAT rate", offer.Id); } } // Customer cannot be updated. Take customer of oldOffer on update. if (oldOffer != null) { offer.Customer = oldOffer.Customer; } else { offer.Customer = await _customerDataProvider.GetByNumberAsync(offer.Customer.Id); } // Request cannot be updated. Take request of oldOffer on update. if (oldOffer != null) { offer.Request = oldOffer.Request; } else { offer.Request = await _requestDataProvider.GetByIdAsync(offer.Request.Id); } // Order cannot be updated. Take order of oldOffer on update. if (oldOffer != null) { offer.Order = oldOffer.Order; } else { offer.Order = null; } var includeCustomer = new QuerySet(); includeCustomer.Include.Fields = new string[] { "customer" }; // Contact can only be updated through CaseManager. Take contact of oldOffer on update. if (oldOffer != null) { offer.Contact = oldOffer.Contact; } else if (offer.Contact != null) { offer.Contact = await _contactDataProvider.GetByIdAsync(offer.Contact.Id, includeCustomer); } // Building can only be updated through CaseManager. Take building of oldOffer on update. if (oldOffer != null) { offer.Building = oldOffer.Building; } else if (offer.Building != null) { offer.Building = await _buildingDataProvider.GetByIdAsync(offer.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 <VatRate> GetByIdAsync(int id, QuerySet query = null) { return(await _vatRateDataProvider.GetByIdAsync(id, query)); }
// Embed relations in deposit invoice resource: reuse old relation if there is one and it hasn't changed private async Task EmbedRelationsAsync(DepositInvoice depositInvoice, DepositInvoice oldDepositInvoice = null) { try { if (depositInvoice.VatRate != null) { if (oldDepositInvoice != null && oldDepositInvoice.VatRate != null && oldDepositInvoice.VatRate.Id == depositInvoice.VatRate.Id) { depositInvoice.VatRate = oldDepositInvoice.VatRate; } else { depositInvoice.VatRate = await _vatRateDataProvider.GetByIdAsync(int.Parse(depositInvoice.VatRate.Id)); } } // Customer cannot be updated. Take customer of oldDepositInvoice on update. if (oldDepositInvoice != null) { depositInvoice.Customer = oldDepositInvoice.Customer; } else { depositInvoice.Customer = await _customerDataProvider.GetByNumberAsync(depositInvoice.Customer.Id); } // Order cannot be updated. Take order of oldDepositInvoice on update. if (oldDepositInvoice != null) { depositInvoice.Order = oldDepositInvoice.Order; } else if (depositInvoice.Order != null) // isolated invoice doesn't have an order attached { depositInvoice.Order = await _orderDataProvider.GetByIdAsync(depositInvoice.Order.Id); } var includeCustomer = new QuerySet(); includeCustomer.Include.Fields = new string[] { "customer" }; // Contact can only be updated through CaseManager. Take contact of oldDepositInvoice on update. if (oldDepositInvoice != null) { depositInvoice.Contact = oldDepositInvoice.Contact; } else if (depositInvoice.Contact != null) { depositInvoice.Contact = await _contactDataProvider.GetByIdAsync(depositInvoice.Contact.Id, includeCustomer); } // Building can only be updated through CaseManager. Take building of oldDepositInvoice on update. if (oldDepositInvoice != null) { depositInvoice.Building = oldDepositInvoice.Building; } else if (depositInvoice.Building != null) { depositInvoice.Building = await _buildingDataProvider.GetByIdAsync(depositInvoice.Building.Id, includeCustomer); } } catch (EntityNotFoundException) { _logger.LogDebug($"Failed to find a related entity"); throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist."); } }