public async Task <LogisticEntity> CreateLogisticAsync(LogisticEntity logisticEntity, CancellationToken token) { await _dbContext.Logistics.AddAsync(logisticEntity, token); await _dbContext.SaveChangesAsync(token); return(await _dbContext.Logistics .Include(logistic => logistic.Driver) .Include(logistic => logistic.LogisticAndLogisticTypes) .ThenInclude(logisticTypeEntity => logisticTypeEntity.LogisticType) .Include(logistic => logistic.LogisticSpecimenTypes) .ThenInclude(logisticTypeEntity => logisticTypeEntity.SpecimenType) .SingleAsync(logistic => logistic.Id == logisticEntity.Id, token)); }
public async Task <LogisticEntity> UpdateLogisticByIdAsync(LogisticEntity logisticEntity, CancellationToken token) { _dbContext.LogisticAndLogisticTypes.RemoveRange(_dbContext.LogisticAndLogisticTypes .Include(logisticTypeEntity => logisticTypeEntity.LogisticType) .Where(logisticTypeEntity => logisticTypeEntity.LogisticId == logisticEntity.Id).ToList()); _dbContext.LogisticAndSpecimenTypes.RemoveRange(_dbContext.LogisticAndSpecimenTypes .Include(logisticTypeEntity => logisticTypeEntity.SpecimenType) .Where(logisticTypeEntity => logisticTypeEntity.LogisticId == logisticEntity.Id).ToList()); _dbContext.Logistics.Update(logisticEntity); await _dbContext.SaveChangesAsync(token); return(await _dbContext.Logistics .Include(logistic => logistic.Driver) .Include(logistic => logistic.LogisticAndLogisticTypes) .ThenInclude(logisticTypeEntity => logisticTypeEntity.LogisticType) .SingleAsync(logistic => logistic.Id == logisticEntity.Id, token)); }