public async Task AddChangeRequestIndexerAsync(long changeRequestId) { var vehicletoDriveTypeRepositoryService = _vcdbUnitOfWork.GetRepositoryService <VehicleToDriveType>() as IVcdbSqlServerEfRepositoryService <VehicleToDriveType>; if (vehicletoDriveTypeRepositoryService == null) { return; } var addedVehicleToDriveTypes = await vehicletoDriveTypeRepositoryService.GetAsync(item => item.ChangeRequestId == changeRequestId, 100000, "DriveType", "Vehicle.BaseVehicle.Make", "Vehicle.BaseVehicle.Model", "Vehicle.BaseVehicle.Model.VehicleType", "Vehicle.BaseVehicle.Model.VehicleType.VehicleTypeGroup", "Vehicle.SubModel", "Vehicle.Region"); if (addedVehicleToDriveTypes == null || !addedVehicleToDriveTypes.Any()) { throw new InvalidOperationException( "Vehicle To Drive Type Index cannot be updated before the transactional table is updated"); } //delete document with vehicleToMfrBodyCodeConfigId of Guid and MfrBodyCodeId of addedVehicleToMfrBodyCodes.MfrBodyCodeId var vehicleToDriveTypeSearchResult = await _vehicleToDriveTypeSearchService.SearchAsync(null, $"driveTypeId eq {addedVehicleToDriveTypes.First().DriveTypeId}"); var existingVehicleToDriveTypeDocuments = vehicleToDriveTypeSearchResult.Documents; if (existingVehicleToDriveTypeDocuments != null && existingVehicleToDriveTypeDocuments.Any()) { Guid guid; foreach (var existingVehicleToDriveTypeDocument in existingVehicleToDriveTypeDocuments) { if (Guid.TryParse(existingVehicleToDriveTypeDocument.VehicleToDriveTypeId, out guid)) { await this._vehicleToDriveTypeIndexingService.DeleteDocumentByVehicleToDriveTypeIdAsync( existingVehicleToDriveTypeDocument.VehicleToDriveTypeId); } } } await InsertOrUpdateVehicleToDriveTypeDocuments(addedVehicleToDriveTypes); }
private async Task UpdateVehicleToDriveTypeDocuments(VehicleType updatedVehicleType) { bool isEndReached = false; int pageNumber = 1; do { var vehicleToDriveTypeSearchResult = await _vehicletoDriveTypeSearchService.SearchAsync(null, $"vehicleTypeId eq {updatedVehicleType.Id}", new SearchOptions() { RecordCount = 1000, PageNumber = pageNumber }); var existingVehicleToDriveTypeDocuments = vehicleToDriveTypeSearchResult.Documents; if (existingVehicleToDriveTypeDocuments != null && existingVehicleToDriveTypeDocuments.Any()) { foreach (var existingVehicleToDriveTypeDocument in existingVehicleToDriveTypeDocuments) { existingVehicleToDriveTypeDocument.VehicleTypeName = updatedVehicleType.Name; } await this._vehicleToDriveTypeIndexingService.UploadDocumentsAsync( existingVehicleToDriveTypeDocuments.ToList()); pageNumber++; } else { isEndReached = true; } } while (!isEndReached); }
private async Task UpdateVehicleToDriveTypeConfigDocuments(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 vehicleToDriveTypeConfigSearchResult = await _vehicletoDriveTypeConfigSearchService.SearchAsync(null, $"vehicleId eq {updatedVehicle.Id}"); var existingVehicleToDriveTypeConfigDocuments = vehicleToDriveTypeConfigSearchResult.Documents; if (existingVehicleToDriveTypeConfigDocuments != null && existingVehicleToDriveTypeConfigDocuments.Any()) { foreach (var existingVehicleToDriveTypeConfigDocument in existingVehicleToDriveTypeConfigDocuments) { existingVehicleToDriveTypeConfigDocument.SubModelId = updatedVehicle.SubModelId; existingVehicleToDriveTypeConfigDocument.SubModelName = updatedVehicle.SubModel.Name; existingVehicleToDriveTypeConfigDocument.RegionId = updatedVehicle.RegionId; existingVehicleToDriveTypeConfigDocument.RegionName = updatedVehicle.Region.Name; } await this._vehicleToDriveTypeConfigIndexingService.UploadDocumentsAsync( existingVehicleToDriveTypeConfigDocuments.ToList()); } } }
public async Task AddChangeRequestIndexerAsync(long changeRequestId) { var driveTypeRepositoryService = _repositories.GetRepositoryService <DriveType>() as IVcdbSqlServerEfRepositoryService <DriveType>; if (driveTypeRepositoryService == null) { return; } var addedDriveTypes = await driveTypeRepositoryService.GetAsync( item => item.ChangeRequestId == changeRequestId, 100000 ); if (addedDriveTypes == null || !addedDriveTypes.Any()) { throw new InvalidOperationException( "Drive Type Index cannot be updated before the transactional table is updated"); } var addedDriveType = addedDriveTypes.First(); var vehicleToDriveTypeSearchResult = await _vehicletoDriveTypeSearchService.SearchAsync(null, $"driveTypeId eq {addedDriveType.Id}"); var existingVehicleToDriveTypeDocuments = vehicleToDriveTypeSearchResult.Documents; if (existingVehicleToDriveTypeDocuments != null && existingVehicleToDriveTypeDocuments.Any()) { throw new InvalidOperationException( "Drive Type already exisit in VehicleToDriveTypeIndex. So, this change request cannot be an add request"); } //MfrBodyCode is new and therefore not yet available in "vehicletoMfrBodyCode" azure search index VehicleToDriveTypeDocument newDriveTypeConfigDocument = new VehicleToDriveTypeDocument { VehicleToDriveTypeId = Guid.NewGuid().ToString(), DriveTypeId = addedDriveType.Id, DriveTypeName = addedDriveType.Name }; await this._vehicleToDriveTypeIndexingService.UploadDocumentAsync(newDriveTypeConfigDocument); }
public override async Task <long> SubmitUpdateChangeRequestAsync <TId>(DriveType entity, TId id, string requestedBy, ChangeType changeType = ChangeType.None, List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null, List <AttachmentsModel> attachments = null, string changeContent = null) { if (string.IsNullOrWhiteSpace(entity?.Name)) { throw new ArgumentNullException(nameof(entity)); } if (id.Equals(default(TId))) { throw new ArgumentNullException(nameof(id)); } if (!entity.Id.Equals(id)) { throw new ArgumentException("Invalid DriveType Id"); } var driveTypeDb = await FindAsync(id); if (driveTypeDb == null) { throw new NoRecordFound("Record Not Found"); } // validations await ValidateDriveTypeIsNotDuplicate(entity, ChangeType.Modify); await ValidateDriveTypeHasNoChangeRequest(entity, ChangeType.Modify); //await ValidateDriveTypeLookUpHasNoChangeRequest(entity); // fill up audit information entity.InsertDate = driveTypeDb.InsertDate; entity.LastUpdateDate = driveTypeDb.LastUpdateDate; entity.DeleteDate = driveTypeDb.DeleteDate; changeRequestItemStagings = changeRequestItemStagings ?? new List <ChangeRequestItemStaging>(); // to eliminate circular reference during serialize var existingEntity = new DriveType() { Id = driveTypeDb.Id, Name = driveTypeDb.Name, ChangeRequestId = driveTypeDb.ChangeRequestId, VehicleToDriveTypeCount = driveTypeDb.VehicleToDriveTypeCount, DeleteDate = driveTypeDb.DeleteDate, InsertDate = driveTypeDb.InsertDate, LastUpdateDate = driveTypeDb.LastUpdateDate }; changeRequestItemStagings.Add(new ChangeRequestItemStaging { EntityId = entity.Id.ToString(), Entity = typeof(DriveType).Name, ChangeType = ChangeType.Modify, CreatedDateTime = DateTime.UtcNow, Payload = Serializer.Serialize(entity), ExistingPayload = base.Serializer.Serialize(existingEntity) // add existing record as ExistingPayload }); changeContent = string.Format("{0} > {1}" , driveTypeDb.Name , entity.Name); var changeRequestId = await base.SubmitUpdateChangeRequestAsync(entity, id, requestedBy, ChangeType.Modify, changeRequestItemStagings, comment, attachments, changeContent); driveTypeDb.ChangeRequestId = changeRequestId; _driveTypeRepositoryService.Update(driveTypeDb); Repositories.SaveChanges(); IList <VehicleToDriveType> existingVehicleToDriveTypes = await base.Repositories.GetRepositoryService <VehicleToDriveType>() .GetAsync(item => item.DriveTypeId.Equals(driveTypeDb.Id) && item.DeleteDate == null); //NOTE: updating change request id in child dependent tables is not valid if (existingVehicleToDriveTypes == null || existingVehicleToDriveTypes.Count == 0) { var driveTypeSearchResult = await _vehicleToDriveTypeSearchService.SearchAsync(null, $"driveTypeId eq {driveTypeDb.Id}"); var existingDriveTypeDocuments = driveTypeSearchResult.Documents; if (existingDriveTypeDocuments != null && existingDriveTypeDocuments.Any()) { foreach (var existingDriveTypeDocument in existingDriveTypeDocuments) { //existingVehicleDocument.VehicleId must be a GUID string await _vehicleToDriveTypeIndexingService.UpdateDriveTypeChangeRequestIdAsync(existingDriveTypeDocument.VehicleToDriveTypeId, changeRequestId); } } } else { //NOTE: driveTypeDb.VehicleToDriveTypes will be null because it is not lazy loaded foreach (var vehicleToDriveType in existingVehicleToDriveTypes) { await _vehicleToDriveTypeIndexingService. UpdateDriveTypeChangeRequestIdAsync(vehicleToDriveType.Id.ToString(), changeRequestId); } } return(changeRequestId); }
public async Task <VehicleToDriveTypeSearchViewModel> Search( VehicleToDriveTypeSearchInputModel vehicleToDriveTypeSearchInputModel) { var applyFilters = new VehicleToDriveTypeSearchFilters() { DriveTypeId = vehicleToDriveTypeSearchInputModel.DriveTypeId, StartYear = Convert.ToInt32(vehicleToDriveTypeSearchInputModel.StartYear), EndYear = Convert.ToInt32(vehicleToDriveTypeSearchInputModel.EndYear), Makes = vehicleToDriveTypeSearchInputModel.Makes, Models = vehicleToDriveTypeSearchInputModel.Models, SubModels = vehicleToDriveTypeSearchInputModel.SubModels, VehicleTypes = vehicleToDriveTypeSearchInputModel.VehicleTypes, VehicleTypeGroups = vehicleToDriveTypeSearchInputModel.VehicleTypeGroups, Regions = vehicleToDriveTypeSearchInputModel.Regions, DriveTypes = vehicleToDriveTypeSearchInputModel.DriveTypes }; var result = await _vehicleToDriveTypeSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(), new SearchOptions { FacetsToInclude = new List <string> { "driveTypeName,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 = _vehicleToDriveTypeSearchViewModelMapper.Map(result); return(viewModel); }