Beispiel #1
0
        public async Task AddChangeRequestIndexerAsync(long changeRequestId)
        {
            var vehicletoBedConfigRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <VehicleToBedConfig>() as
                IVcdbSqlServerEfRepositoryService <VehicleToBedConfig>;

            if (vehicletoBedConfigRepositoryService == null)
            {
                return;
            }

            var addedVehicleToBedConfigs =
                await
                vehicletoBedConfigRepositoryService.GetAsync(item => item.ChangeRequestId == changeRequestId, 100000,
                                                             "BedConfig.BedLength",
                                                             "BedConfig.BedType",
                                                             "Vehicle.BaseVehicle.Make",
                                                             "Vehicle.BaseVehicle.Model",
                                                             "Vehicle.BaseVehicle.Model.VehicleType",
                                                             "Vehicle.BaseVehicle.Model.VehicleType.VehicleTypeGroup",
                                                             "Vehicle.SubModel",
                                                             "Vehicle.Region");

            if (addedVehicleToBedConfigs == null || !addedVehicleToBedConfigs.Any())
            {
                throw new InvalidOperationException(
                          "Vehicle To Bed Config Index cannot be updated before the transactional table is updated");
            }

            //delete document with vehicleToBedConfigId of Guid and bedConfigId of addedVehicleToBedConfigs.BedConfigId
            var vehicleToBedConfigSearchResult =
                await
                _vehicleToBedConfigSearchService.SearchAsync(null,
                                                             $"bedConfigId eq {addedVehicleToBedConfigs.First().BedConfigId}");

            var existingVehicleToBedConfigDocuments = vehicleToBedConfigSearchResult.Documents;

            if (existingVehicleToBedConfigDocuments != null && existingVehicleToBedConfigDocuments.Any())
            {
                Guid guid;
                foreach (var existingVehicleToBedConfigDocument in existingVehicleToBedConfigDocuments)
                {
                    if (Guid.TryParse(existingVehicleToBedConfigDocument.VehicleToBedConfigId, out guid))
                    {
                        await
                        this._vehicleToBedConfigIndexingService.DeleteDocumentByVehicleToBedConfigIdAsync(
                            existingVehicleToBedConfigDocument.VehicleToBedConfigId);
                    }
                }
            }

            await InsertOrUpdateVehicleToBedConfigDocuments(addedVehicleToBedConfigs);
        }
        public async Task AddChangeRequestIndexerAsync(long changeRequestId)
        {
            var bedConfigRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <BedConfig>() as
                IVcdbSqlServerEfRepositoryService <BedConfig>;

            if (bedConfigRepositoryService == null)
            {
                return;
            }

            var addedBedConfigs =
                await
                bedConfigRepositoryService.GetAsync(
                    item => item.ChangeRequestId == changeRequestId, 100000,
                    "BedLength",
                    "BedType");

            if (addedBedConfigs == null || !addedBedConfigs.Any())
            {
                throw new InvalidOperationException(
                          "Bed Config Index cannot be updated before the transactional table is updated");
            }

            var addedBedConfig = addedBedConfigs.First();
            var vehicleToBedConfigSearchResult =
                await
                _vehicletoBedConfigSearchService.SearchAsync(null,
                                                             $"bedConfigId eq {addedBedConfig.Id}");

            var existingVehicleToBedConfigDocuments = vehicleToBedConfigSearchResult.Documents;

            if (existingVehicleToBedConfigDocuments != null && existingVehicleToBedConfigDocuments.Any())
            {
                throw new InvalidOperationException(
                          "BedConfig already exisit in VehicleToBedConfigIndex. So, this change request cannot be an add request");
            }

            //bed config is new and therefore not yet available in "vehicletobedconfigs" azure search index
            VehicleToBedConfigDocument newVehicleToBedConfigDocument = new VehicleToBedConfigDocument
            {
                VehicleToBedConfigId = Guid.NewGuid().ToString(),
                BedConfigId          = addedBedConfig.Id,
                BedLengthId          = addedBedConfig.BedLengthId,
                BedLength            = addedBedConfig.BedLength.Length,
                BedLengthMetric      = addedBedConfig.BedLength.BedLengthMetric,
                BedTypeId            = addedBedConfig.BedTypeId,
                BedTypeName          = addedBedConfig.BedType.Name
            };

            await this._vehicleToBedConfigIndexingService.UploadDocumentAsync(newVehicleToBedConfigDocument);
        }
Beispiel #3
0
        private async Task UpdateVehicleToBedConfigDocuments(VehicleType updatedVehicleType)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var vehicleToBedConfigSearchResult =
                    await
                    _vehicletoBedConfigSearchService.SearchAsync(null,
                                                                 $"vehicleTypeId eq {updatedVehicleType.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBedConfigDocuments = vehicleToBedConfigSearchResult.Documents;
                if (existingVehicleToBedConfigDocuments != null && existingVehicleToBedConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBedConfigDocument in existingVehicleToBedConfigDocuments)
                    {
                        existingVehicleToBedConfigDocument.VehicleTypeName = updatedVehicleType.Name;
                    }

                    await
                    this._vehicleToBedConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBedConfigDocuments.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
        private async Task UpdateVehicleToBedConfigDocuments(List <Vehicle> updatedVehicles)
        {
            if (updatedVehicles == null)
            {
                return;
            }

            foreach (var updatedVehicle in updatedVehicles)
            //NOTE: updatedVehicles will contain more than 1 item when processing base vehicle replace
            //Pushkar: azure search: length of the request URL may exceed the limit of 8 KB limit may exceed if $filter=vehicleId eq '1' or vehicleId eq '2' or vehicleId eq '3' is used to avoid this foreach loop
            {
                var vehicleToBedConfigSearchResult =
                    await
                    _vehicletoBedConfigSearchService.SearchAsync(null, $"vehicleId eq {updatedVehicle.Id}");

                var existingVehicleToBedConfigDocuments = vehicleToBedConfigSearchResult.Documents;

                if (existingVehicleToBedConfigDocuments != null && existingVehicleToBedConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBedConfigDocument in existingVehicleToBedConfigDocuments)
                    {
                        existingVehicleToBedConfigDocument.SubModelId   = updatedVehicle.SubModelId;
                        existingVehicleToBedConfigDocument.SubModelName = updatedVehicle.SubModel.Name;
                        existingVehicleToBedConfigDocument.RegionId     = updatedVehicle.RegionId;
                        existingVehicleToBedConfigDocument.RegionName   = updatedVehicle.Region.Name;
                    }

                    await
                    this._vehicleToBedConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBedConfigDocuments.ToList());
                }
            }
        }
        public override async Task <long> SubmitUpdateChangeRequestAsync <TId>(BedConfig entity, TId id,
                                                                               string requestedBy,
                                                                               ChangeType changeType = ChangeType.None,
                                                                               List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null, List <AttachmentsModel> attachments = null, string changeContent = null)
        {
            if (entity.BedTypeId.Equals(default(int)) ||
                entity.BedLengthId.Equals(default(int)))
            {
                throw new ArgumentException(nameof(entity));
            }

            if (id.Equals(default(TId)))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (!entity.Id.Equals(id))
            {
                throw new ArgumentException("Invalid Bed Config Id");
            }

            var bedConfigFromDb = await FindAsync(id);

            if (bedConfigFromDb == null)
            {
                throw new NoRecordFound("No Bed Config exist");
            }

            var existingEntity = new BedConfig()
            {
                Id                      = bedConfigFromDb.Id,
                BedLengthId             = bedConfigFromDb.BedLengthId,
                BedTypeId               = bedConfigFromDb.BedTypeId,
                ChangeRequestId         = bedConfigFromDb.ChangeRequestId,
                DeleteDate              = bedConfigFromDb.DeleteDate,
                InsertDate              = bedConfigFromDb.InsertDate,
                LastUpdateDate          = bedConfigFromDb.LastUpdateDate,
                VehicleToBedConfigCount = bedConfigFromDb.VehicleToBedConfigCount
            };

            changeRequestItemStagings = new List <ChangeRequestItemStaging>();

            // Validation check for update of existing bed config
            await ValidateConfigurationDoesNotMatchWithExistingBedConfig(entity);
            await ValidateNoChangeRequestExistsWithSameConfiguration(entity);
            await ValidateBedConfigLookUpHasNoChangeRequest(entity);
            await ValidateBedConfigDependentHasNoChangeRequest(entity);

            entity.InsertDate = bedConfigFromDb.InsertDate;

            changeRequestItemStagings.Add(new ChangeRequestItemStaging()
            {
                ChangeType      = ChangeType.Modify,
                EntityId        = entity.Id.ToString(),
                CreatedDateTime = DateTime.UtcNow,
                Entity          = typeof(BedConfig).Name,
                Payload         = base.Serializer.Serialize(entity),
                ExistingPayload = base.Serializer.Serialize(existingEntity)
            });

            changeContent = string.Format("{0} / {1} / {2}"
                                          , bedConfigFromDb.BedType.Name
                                          , bedConfigFromDb.BedLength.Length
                                          , bedConfigFromDb.BedLength.BedLengthMetric);

            // NOTE: change-request-comments-staging perfomed on base

            var changeRequestId = await base.SubmitUpdateChangeRequestAsync(entity, id, requestedBy, ChangeType.Modify, changeRequestItemStagings, comment, attachments, changeContent);

            bedConfigFromDb.ChangeRequestId = changeRequestId;
            _bedConfigRepositoryService.Update(bedConfigFromDb);
            Repositories.SaveChanges();

            //NOTE: updating change request id in child dependent tables is not valid

            IList <VehicleToBedConfig> existingVehicleToBedConfigs =
                await
                base.Repositories.GetRepositoryService <VehicleToBedConfig>()
                .GetAsync(item => item.BedConfigId.Equals(bedConfigFromDb.Id) && item.DeleteDate == null);

            if (existingVehicleToBedConfigs == null || existingVehicleToBedConfigs.Count == 0)
            {
                var vehicleToBedConfigSearchResult = await _vehicletoBedConfigSearchService.SearchAsync(null, $"bedConfigId eq {bedConfigFromDb.Id}");

                var existingVehicleToBedConfigDocuments = vehicleToBedConfigSearchResult.Documents;
                if (existingVehicleToBedConfigDocuments != null && existingVehicleToBedConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBedConfigDocument in existingVehicleToBedConfigDocuments)
                    {
                        //existingVehicleToBedConfigDocument.VehicleToBedConfigId must be a GUID string
                        await _vehicleToBedConfigIndexingService.UpdateBedConfigChangeRequestIdAsync(existingVehicleToBedConfigDocument.VehicleToBedConfigId, changeRequestId);
                    }
                }
            }
            else
            {
                //NOTE: bedConfigFromDb.VehicleToBedConfigs will be null because it is not lazy loaded
                foreach (var vehicleToBedConfig in existingVehicleToBedConfigs)
                {
                    await _vehicleToBedConfigIndexingService.UpdateBedConfigChangeRequestIdAsync(vehicleToBedConfig.Id.ToString(), changeRequestId);
                }
            }

            return(changeRequestId);
        }
        public async Task <VehicleToBedConfigSearchViewModel> Search(VehicleToBedConfigSearchInputModel vehicleToBedConfigSearchInputModel)
        {
            var applyFilters = new VehicleToBedConfigSearchFilters()
            {
                BedConfigId       = vehicleToBedConfigSearchInputModel.BedConfigId,
                StartYear         = Convert.ToInt32(vehicleToBedConfigSearchInputModel.StartYear),
                EndYear           = Convert.ToInt32(vehicleToBedConfigSearchInputModel.EndYear),
                Makes             = vehicleToBedConfigSearchInputModel.Makes,
                Models            = vehicleToBedConfigSearchInputModel.Models,
                SubModels         = vehicleToBedConfigSearchInputModel.SubModels,
                VehicleTypes      = vehicleToBedConfigSearchInputModel.VehicleTypes,
                VehicleTypeGroups = vehicleToBedConfigSearchInputModel.VehicleTypeGroups,
                Regions           = vehicleToBedConfigSearchInputModel.Regions,
                BedLengths        = vehicleToBedConfigSearchInputModel.BedLengths,
                BedTypes          = vehicleToBedConfigSearchInputModel.BedTypes
            };

            var result = await _vehicleToBedConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                            new SearchOptions
            {
                FacetsToInclude = new List <string>
                {
                    "bedLength,count:1000",
                    "bedTypeName,count:1000",
                    "regionName,count:1000",
                    "vehicleTypeName,count:1000",
                    "vehicleTypeGroupName,count:1000",
                    "makeName,count:1000",
                    "modelName,count:1000",
                    "subModelName,count:1000",
                },
                RecordCount      = 1000,
                ReturnTotalCount = true
            });

            var viewModel = _vehicleToBedConfigSearchViewModelMapper.Map(result);

            return(viewModel);
        }