Skip to content

Commit

Permalink
Remove List <RelatedEntity>Id from <EntityUpdateDto> (#1114)
Browse files Browse the repository at this point in the history
* NOX-237 Remove <RelatedEntityId> list from <EntityUpdateDto>

* NOX-237 fix test
  • Loading branch information
anna-naumova25 authored Nov 14, 2023
1 parent abca728 commit ff5ff0b
Show file tree
Hide file tree
Showing 62 changed files with 25 additions and 780 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ public UpdateCommissionCommandHandlerBase(
entity.DeleteAllRefToCountry();
}

await DbContext.Entry(entity).Collection(x => x.Bookings).LoadAsync();
var bookingsEntities = new List<Cryptocash.Domain.Booking>();
foreach(var relatedEntityId in request.EntityDto.BookingsId)
{
var relatedKey = Cryptocash.Domain.BookingMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Bookings.FindAsync(relatedKey);

if(relatedEntity is not null)
bookingsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Bookings", relatedEntityId.ToString());
}
entity.UpdateRefToBookings(bookingsEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,6 @@ public UpdateCountryCommandHandlerBase(
else
throw new RelatedEntityNotFoundException("Currency", request.EntityDto.CurrencyId.ToString());

await DbContext.Entry(entity).Collection(x => x.Commissions).LoadAsync();
var commissionsEntities = new List<Cryptocash.Domain.Commission>();
foreach(var relatedEntityId in request.EntityDto.CommissionsId)
{
var relatedKey = Cryptocash.Domain.CommissionMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Commissions.FindAsync(relatedKey);

if(relatedEntity is not null)
commissionsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Commissions", relatedEntityId.ToString());
}
entity.UpdateRefToCommissions(commissionsEntities);

await DbContext.Entry(entity).Collection(x => x.VendingMachines).LoadAsync();
var vendingMachinesEntities = new List<Cryptocash.Domain.VendingMachine>();
foreach(var relatedEntityId in request.EntityDto.VendingMachinesId)
{
var relatedKey = Cryptocash.Domain.VendingMachineMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.VendingMachines.FindAsync(relatedKey);

if(relatedEntity is not null)
vendingMachinesEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("VendingMachines", relatedEntityId.ToString());
}
entity.UpdateRefToVendingMachines(vendingMachinesEntities);

await DbContext.Entry(entity).Collection(x => x.Customers).LoadAsync();
var customersEntities = new List<Cryptocash.Domain.Customer>();
foreach(var relatedEntityId in request.EntityDto.CustomersId)
{
var relatedKey = Cryptocash.Domain.CustomerMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Customers.FindAsync(relatedKey);

if(relatedEntity is not null)
customersEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Customers", relatedEntityId.ToString());
}
entity.UpdateRefToCustomers(customersEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ public UpdateCurrencyCommandHandlerBase(
return null;
}

await DbContext.Entry(entity).Collection(x => x.Countries).LoadAsync();
var countriesEntities = new List<Cryptocash.Domain.Country>();
foreach(var relatedEntityId in request.EntityDto.CountriesId)
{
var relatedKey = Cryptocash.Domain.CountryMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Countries.FindAsync(relatedKey);

if(relatedEntity is not null)
countriesEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Countries", relatedEntityId.ToString());
}
entity.UpdateRefToCountries(countriesEntities);

await DbContext.Entry(entity).Collection(x => x.MinimumCashStocks).LoadAsync();
var minimumCashStocksEntities = new List<Cryptocash.Domain.MinimumCashStock>();
foreach(var relatedEntityId in request.EntityDto.MinimumCashStocksId)
{
var relatedKey = Cryptocash.Domain.MinimumCashStockMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.MinimumCashStocks.FindAsync(relatedKey);

if(relatedEntity is not null)
minimumCashStocksEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("MinimumCashStocks", relatedEntityId.ToString());
}
entity.UpdateRefToMinimumCashStocks(minimumCashStocksEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,6 @@ public UpdateCustomerCommandHandlerBase(
return null;
}

await DbContext.Entry(entity).Collection(x => x.PaymentDetails).LoadAsync();
var paymentDetailsEntities = new List<Cryptocash.Domain.PaymentDetail>();
foreach(var relatedEntityId in request.EntityDto.PaymentDetailsId)
{
var relatedKey = Cryptocash.Domain.PaymentDetailMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.PaymentDetails.FindAsync(relatedKey);

if(relatedEntity is not null)
paymentDetailsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("PaymentDetails", relatedEntityId.ToString());
}
entity.UpdateRefToPaymentDetails(paymentDetailsEntities);

await DbContext.Entry(entity).Collection(x => x.Bookings).LoadAsync();
var bookingsEntities = new List<Cryptocash.Domain.Booking>();
foreach(var relatedEntityId in request.EntityDto.BookingsId)
{
var relatedKey = Cryptocash.Domain.BookingMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Bookings.FindAsync(relatedKey);

if(relatedEntity is not null)
bookingsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Bookings", relatedEntityId.ToString());
}
entity.UpdateRefToBookings(bookingsEntities);

await DbContext.Entry(entity).Collection(x => x.Transactions).LoadAsync();
var transactionsEntities = new List<Cryptocash.Domain.Transaction>();
foreach(var relatedEntityId in request.EntityDto.TransactionsId)
{
var relatedKey = Cryptocash.Domain.TransactionMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Transactions.FindAsync(relatedKey);

if(relatedEntity is not null)
transactionsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Transactions", relatedEntityId.ToString());
}
entity.UpdateRefToTransactions(transactionsEntities);

var countryKey = Cryptocash.Domain.CountryMetadata.CreateId(request.EntityDto.CountryId);
var countryEntity = await DbContext.Countries.FindAsync(countryKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ public UpdateLandLordCommandHandlerBase(
return null;
}

await DbContext.Entry(entity).Collection(x => x.VendingMachines).LoadAsync();
var vendingMachinesEntities = new List<Cryptocash.Domain.VendingMachine>();
foreach(var relatedEntityId in request.EntityDto.VendingMachinesId)
{
var relatedKey = Cryptocash.Domain.VendingMachineMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.VendingMachines.FindAsync(relatedKey);

if(relatedEntity is not null)
vendingMachinesEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("VendingMachines", relatedEntityId.ToString());
}
entity.UpdateRefToVendingMachines(vendingMachinesEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ public UpdateMinimumCashStockCommandHandlerBase(
return null;
}

await DbContext.Entry(entity).Collection(x => x.VendingMachines).LoadAsync();
var vendingMachinesEntities = new List<Cryptocash.Domain.VendingMachine>();
foreach(var relatedEntityId in request.EntityDto.VendingMachinesId)
{
var relatedKey = Cryptocash.Domain.VendingMachineMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.VendingMachines.FindAsync(relatedKey);

if(relatedEntity is not null)
vendingMachinesEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("VendingMachines", relatedEntityId.ToString());
}
entity.UpdateRefToVendingMachines(vendingMachinesEntities);

var currencyKey = Cryptocash.Domain.CurrencyMetadata.CreateId(request.EntityDto.CurrencyId);
var currencyEntity = await DbContext.Currencies.FindAsync(currencyKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ public UpdatePaymentProviderCommandHandlerBase(
return null;
}

await DbContext.Entry(entity).Collection(x => x.PaymentDetails).LoadAsync();
var paymentDetailsEntities = new List<Cryptocash.Domain.PaymentDetail>();
foreach(var relatedEntityId in request.EntityDto.PaymentDetailsId)
{
var relatedKey = Cryptocash.Domain.PaymentDetailMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.PaymentDetails.FindAsync(relatedKey);

if(relatedEntity is not null)
paymentDetailsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("PaymentDetails", relatedEntityId.ToString());
}
entity.UpdateRefToPaymentDetails(paymentDetailsEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,48 +73,6 @@ public UpdateVendingMachineCommandHandlerBase(
else
throw new RelatedEntityNotFoundException("LandLord", request.EntityDto.LandLordId.ToString());

await DbContext.Entry(entity).Collection(x => x.Bookings).LoadAsync();
var bookingsEntities = new List<Cryptocash.Domain.Booking>();
foreach(var relatedEntityId in request.EntityDto.BookingsId)
{
var relatedKey = Cryptocash.Domain.BookingMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.Bookings.FindAsync(relatedKey);

if(relatedEntity is not null)
bookingsEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("Bookings", relatedEntityId.ToString());
}
entity.UpdateRefToBookings(bookingsEntities);

await DbContext.Entry(entity).Collection(x => x.CashStockOrders).LoadAsync();
var cashStockOrdersEntities = new List<Cryptocash.Domain.CashStockOrder>();
foreach(var relatedEntityId in request.EntityDto.CashStockOrdersId)
{
var relatedKey = Cryptocash.Domain.CashStockOrderMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.CashStockOrders.FindAsync(relatedKey);

if(relatedEntity is not null)
cashStockOrdersEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("CashStockOrders", relatedEntityId.ToString());
}
entity.UpdateRefToCashStockOrders(cashStockOrdersEntities);

await DbContext.Entry(entity).Collection(x => x.MinimumCashStocks).LoadAsync();
var minimumCashStocksEntities = new List<Cryptocash.Domain.MinimumCashStock>();
foreach(var relatedEntityId in request.EntityDto.MinimumCashStocksId)
{
var relatedKey = Cryptocash.Domain.MinimumCashStockMetadata.CreateId(relatedEntityId);
var relatedEntity = await DbContext.MinimumCashStocks.FindAsync(relatedKey);

if(relatedEntity is not null)
minimumCashStocksEntities.Add(relatedEntity);
else
throw new RelatedEntityNotFoundException("MinimumCashStocks", relatedEntityId.ToString());
}
entity.UpdateRefToMinimumCashStocks(minimumCashStocksEntities);

_entityFactory.UpdateEntity(entity, request.EntityDto, request.CultureCode);
entity.Etag = request.Etag.HasValue ? request.Etag.Value : System.Guid.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ public partial class CommissionUpdateDtoBase: EntityDtoBase, IEntityDto<DomainNa
/// </summary>

public virtual System.String? CountryId { get; set; } = default!;

/// <summary>
/// Commission fees for ZeroOrMany Bookings
/// </summary>
public virtual List<System.Guid> BookingsId { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,4 @@ public partial class CountryUpdateDtoBase: EntityDtoBase, IEntityDto<DomainNames
/// </summary>
[Required(ErrorMessage = "Currency is required")]
public virtual System.String CurrencyId { get; set; } = default!;

/// <summary>
/// Country used by OneOrMany Commissions
/// </summary>
public virtual List<System.Int64> CommissionsId { get; set; } = new();

/// <summary>
/// Country used by ZeroOrMany VendingMachines
/// </summary>
public virtual List<System.Guid> VendingMachinesId { get; set; } = new();

/// <summary>
/// Country used by ZeroOrMany Customers
/// </summary>
public virtual List<System.Int64> CustomersId { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,4 @@ public partial class CurrencyUpdateDtoBase: EntityDtoBase, IEntityDto<DomainName
[Required(ErrorMessage = "MinorToMajorValue is required")]

public virtual MoneyDto MinorToMajorValue { get; set; } = default!;

/// <summary>
/// Currency used by OneOrMany Countries
/// </summary>
public virtual List<System.String> CountriesId { get; set; } = new();

/// <summary>
/// Currency used by ZeroOrMany MinimumCashStocks
/// </summary>
public virtual List<System.Int64> MinimumCashStocksId { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ public partial class CustomerUpdateDtoBase: EntityDtoBase, IEntityDto<DomainName
/// </summary>
public virtual System.String? MobileNumber { get; set; }

/// <summary>
/// Customer related to ZeroOrMany PaymentDetails
/// </summary>
public virtual List<System.Int64> PaymentDetailsId { get; set; } = new();

/// <summary>
/// Customer related to ZeroOrMany Bookings
/// </summary>
public virtual List<System.Guid> BookingsId { get; set; } = new();

/// <summary>
/// Customer related to ZeroOrMany Transactions
/// </summary>
public virtual List<System.Int64> TransactionsId { get; set; } = new();

/// <summary>
/// Customer based in ExactlyOne Countries
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public partial class LandLordUpdateDtoBase: EntityDtoBase, IEntityDto<DomainName
[Required(ErrorMessage = "Address is required")]

public virtual StreetAddressDto Address { get; set; } = default!;

/// <summary>
/// LandLord leases an area to house ZeroOrMany VendingMachines
/// </summary>
public virtual List<System.Guid> VendingMachinesId { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public partial class MinimumCashStockUpdateDtoBase: EntityDtoBase, IEntityDto<Do

public virtual MoneyDto Amount { get; set; } = default!;

/// <summary>
/// MinimumCashStock required by ZeroOrMany VendingMachines
/// </summary>
public virtual List<System.Guid> VendingMachinesId { get; set; } = new();

/// <summary>
/// MinimumCashStock related to ExactlyOne Currencies
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public partial class PaymentProviderUpdateDtoBase: EntityDtoBase, IEntityDto<Dom
[Required(ErrorMessage = "PaymentProviderType is required")]

public virtual System.String PaymentProviderType { get; set; } = default!;

/// <summary>
/// PaymentProvider related to ZeroOrMany PaymentDetails
/// </summary>
public virtual List<System.Int64> PaymentDetailsId { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,4 @@ public partial class VendingMachineUpdateDtoBase: EntityDtoBase, IEntityDto<Doma
/// </summary>
[Required(ErrorMessage = "LandLord is required")]
public virtual System.Int64 LandLordId { get; set; } = default!;

/// <summary>
/// VendingMachine related to ZeroOrMany Bookings
/// </summary>
public virtual List<System.Guid> BookingsId { get; set; } = new();

/// <summary>
/// VendingMachine related to ZeroOrMany CashStockOrders
/// </summary>
public virtual List<System.Int64> CashStockOrdersId { get; set; } = new();

/// <summary>
/// VendingMachine required ZeroOrMany MinimumCashStocks
/// </summary>
public virtual List<System.Int64> MinimumCashStocksId { get; set; } = new();
}
Loading

0 comments on commit ff5ff0b

Please sign in to comment.