Exemplo n.º 1
0
        public async Task RejectChangeRequestIndexerAsync(long changeRequestId)
        {
            var vehicleRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <Vehicle>() as IVcdbSqlServerEfRepositoryService <Vehicle>;

            if (vehicleRepositoryService == null)
            {
                return;
            }

            var updatedVehicles =
                await vehicleRepositoryService.GetAsync(item => item.ChangeRequestId == changeRequestId);

            if (updatedVehicles == null || !updatedVehicles.Any())
            {
                //Pushkar: need to test this condition
                throw new InvalidOperationException(
                          "Vehicle Index cannot be updated before the transactional table is updated");
            }

            foreach (var updatedVehicle in updatedVehicles)
            {
                var vehicleDocument = new VehicleDocument
                {
                    VehicleId = updatedVehicle.Id.ToString(),
                    VehicleChangeRequestId = -1,
                };

                await this._vehicleIndexingService.UploadDocumentAsync(vehicleDocument);
            }

            //Required when processing basevehicle REPLACE CR
            await ClearBaseVehicleChangeRequestId(changeRequestId);
        }
        public async Task <IActionResult> CreateVehicleDocument([FromBody] VehicleDocument vehicleDocument)
        {
            _ctx.VehicleDocuments.Add(vehicleDocument);
            await _ctx.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add Vehicle Document
 /// </summary>
 /// <param name="vehicleDocument">Transport Document</param>
 /// <returns>returm success 1</returns>
 public static int AddVehicleDocument(VehicleDocument vehicleDocument)
 {
     int result;
     TMSDataLibrary.VehicleDocument objVehDocument = new TMSDataLibrary.VehicleDocument();
     result = objVehDocument.AddVehicleDocument(vehicleDocument.TransporterVehicleid, vehicleDocument.DocTypeId, vehicleDocument.DocumentNo,
         vehicleDocument.DocPath, vehicleDocument.ValidFrom, vehicleDocument.ValidTo, vehicleDocument.RTO);
     return result;
 }
Exemplo n.º 4
0
 public bool AddDoc(VehicleDocument model)
 {
     if (model == null)
     {
         return(false);
     }
     _repository.Add(model);
     _unitOfWork.Commit();
     return(true);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Updates a document in "vehicles" azure index for base vehicle change request ids.
        /// </summary>
        /// <param name="vehicleId">Vehicle id is the key field in "vehicles" azure index. This field is required</param>
        /// <param name="baseVehicleChangeRequestId"></param>
        /// <returns></returns>
        public async Task UpdateBaseVehicleChangeRequestIdAsync(string vehicleId, long baseVehicleChangeRequestId)
        {
            VehicleDocument document = new VehicleDocument
            {
                VehicleId = vehicleId,
                BaseVehicleChangeRequestId = baseVehicleChangeRequestId
            };

            await _vehicleIndexingRepositoryService.UpdateDocumentAsync(document);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates a document in "vehicles" azure index for vehicle change request ids.
        /// </summary>
        /// <param name="vehicleId">Vehicle id is the key field in "vehicles" azure index. This field is required</param>
        /// <param name="vehicleChangeRequestId"></param>
        /// <returns></returns>
        public async Task UpdateVehicleChangeRequestIdAsync(int vehicleId, long vehicleChangeRequestId)
        {
            VehicleDocument document = new VehicleDocument
            {
                VehicleId = vehicleId.ToString(),
                VehicleChangeRequestId = vehicleChangeRequestId
            };

            await _vehicleIndexingRepositoryService.UpdateDocumentAsync(document);
        }
Exemplo n.º 7
0
        public void Save(VehicleDocumentItem model)
        {
            VehicleDocument objVehicleDoc = new VehicleDocument();

            objVehicleDoc.FileName    = model.FileName;
            objVehicleDoc.FileUrl     = model.FileUrl;
            objVehicleDoc.VId         = model.VId;
            objVehicleDoc.Status      = "Active";
            objVehicleDoc.CreatedDate = System.DateTime.Now;
            DbContext.VehicleDocuments.Add(objVehicleDoc);
            DbContext.SaveChanges();
        }
        public async void UpdateDocumentAsyncTest()
        {
            var             vehicleRepo = new VehicleIndexingRepositoryService();
            VehicleDocument document    = new VehicleDocument {
                VehicleId = "043aec55-9708-4629-9df8-a6a0d9a50843", BaseVehicleId = 138244
            };
            DocumentIndexResult result = await vehicleRepo.UpdateDocumentAsync(document);

            Assert.NotNull(result);
            Assert.True(result.Results.Count > 0);
            Assert.True(result.Results.All(item => item.Succeeded));
        }
Exemplo n.º 9
0
        //Raja: This function logic needs to be revisited
        //Pushkar: Revised and unit testing
        public async Task AddChangeRequestIndexerAsync(long changeRequestId)
        {
            var baseVehicleRepositoryService =
                _vcdbUnitOfWork.GetRepositoryService <BaseVehicle>() as
                IVcdbSqlServerEfRepositoryService <BaseVehicle>;

            if (baseVehicleRepositoryService == null)
            {
                return;
            }

            var addedBaseVehicles =
                await
                baseVehicleRepositoryService.GetAsync(
                    item => item.ChangeRequestId == changeRequestId, 100000,
                    "Make",
                    "Model");

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

            var addedBaseVehicle    = addedBaseVehicles.First();
            var vehicleSearchResult =
                await
                _vehicleSearchService.SearchAsync(null,
                                                  $"baseVehicleId eq {addedBaseVehicle.Id}");

            var existingVehicleDocuments = vehicleSearchResult?.Documents;

            if (existingVehicleDocuments != null && existingVehicleDocuments.Any())
            {
                throw new InvalidOperationException("Base Vehicle already exist in VehicleIndex. So, this change request cannot be an add request");
            }

            //base vehicle is new and therefore not yet available in "vehicles" azure search index
            var newVehicleDocument = new VehicleDocument
            {
                VehicleId     = Guid.NewGuid().ToString(),
                BaseVehicleId = addedBaseVehicle.Id,
                MakeId        = addedBaseVehicle.MakeId,
                MakeName      = addedBaseVehicle.Make.Name,
                ModelId       = addedBaseVehicle.ModelId,
                ModelName     = addedBaseVehicle.Model.Name,
                YearId        = addedBaseVehicle.YearId,
            };

            await this._vehicleIndexingService.UploadDocumentAsync(newVehicleDocument);
        }
Exemplo n.º 10
0
        private async Task InsertOrUpdateVehicleDocuments(List <Vehicle> updatedVehicles, bool isReplace = false)
        {
            if (updatedVehicles == null)
            {
                return;
            }

            foreach (var updatedVehicle in updatedVehicles)
            //NOTE: updatedVehicles will contain more than 1 item when processing base vehicle replace
            {
                var vehicleDocument = new VehicleDocument
                {
                    VehicleId = updatedVehicle.Id.ToString(),
                    //Question: Raja: I am not sure why do we use 2 different value for BaseVehicleChangeRequestId
                    //Pushkar: -1 is kept to forcefully clear previous value since setting a null will cause document update process to retain previous value.
                    BaseVehicleChangeRequestId = isReplace ? -1 : (long?)null,
                    VehicleChangeRequestId     = -1,
                    BaseVehicleId        = updatedVehicle.BaseVehicleId,
                    MakeId               = updatedVehicle.BaseVehicle.MakeId,
                    MakeName             = updatedVehicle.BaseVehicle.Make.Name,
                    ModelId              = updatedVehicle.BaseVehicle.ModelId,
                    ModelName            = updatedVehicle.BaseVehicle.Model.Name,
                    RegionId             = updatedVehicle.RegionId,
                    RegionName           = updatedVehicle.Region.Name,
                    Source               = updatedVehicle.SourceName,
                    SubModelId           = updatedVehicle.SubModelId,
                    SubModelName         = updatedVehicle.SubModel.Name,
                    VehicleTypeGroupId   = updatedVehicle.BaseVehicle.Model.VehicleType.VehicleTypeGroupId,
                    VehicleTypeGroupName = updatedVehicle.BaseVehicle.Model.VehicleType.VehicleTypeGroup.Name,
                    VehicleTypeId        = updatedVehicle.BaseVehicle.Model.VehicleTypeId,
                    VehicleTypeName      = updatedVehicle.BaseVehicle.Model.VehicleType.Name,
                    YearId               = updatedVehicle.BaseVehicle.YearId
                };

                await this._vehicleIndexingService.UploadDocumentAsync(vehicleDocument);
            }
        }
 public async Task <DocumentIndexResult> UpdateDocumentAsync(VehicleDocument vehicleDocument)
 {
     return(await UpdateDocumentsAsync(new List <VehicleDocument> {
         vehicleDocument
     }));
 }
 public async Task UploadDocumentAsync(VehicleDocument vehicleDocument)
 {
     await UploadDocumentsAsync(new List <VehicleDocument> {
         vehicleDocument
     });
 }
Exemplo n.º 13
0
 public async Task UploadDocumentAsync(VehicleDocument vehicleDocument)
 {
     await _vehicleIndexingRepositoryService.UpdateDocumentAsync(vehicleDocument);
 }