Exemplo n.º 1
0
        public async Task <IHttpActionResult> Post(int id, BrakeABSInputModel model)
        {
            BrakeABS brakeABS = new BrakeABS()
            {
                Id = model.Id, Name = model.Name
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _brakeABSApplicationService.DeleteAsync(brakeABS, id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
Exemplo n.º 2
0
        private async Task UpdateVehicleToBrakeConfigDocuments(BrakeABS updatedBrakeAbs)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var vehicleToBrakeConfigSearchResult =
                    await
                    _vehicletoBrakeConfigSearchService.SearchAsync(null,
                                                                   $"brakeABSId eq {updatedBrakeAbs.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBrakeConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;

                if (existingVehicleToBrakeConfigDocuments != null &&
                    existingVehicleToBrakeConfigDocuments.Any())
                {
                    foreach (
                        var existingVehicleToBrakeConfigDocument in
                        existingVehicleToBrakeConfigDocuments)
                    {
                        existingVehicleToBrakeConfigDocument.BrakeABSName = updatedBrakeAbs.Name;
                    }

                    await
                    this._vehicleToBrakeConfigIndexingService.UploadDocumentsAsync(
                        existingVehicleToBrakeConfigDocuments.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
Exemplo n.º 3
0
        public override async Task <long> SubmitAddChangeRequestAsync(BrakeConfig entity, string requestedBy,
                                                                      List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null,
                                                                      List <AttachmentsModel> attachmentsStagingModels          = null, string changeContent = null)
        {
            if (entity.BrakeSystemId.Equals(default(int)) ||
                entity.BrakeABSId.Equals(default(int)) ||
                entity.FrontBrakeTypeId.Equals(default(int)) ||
                entity.RearBrakeTypeId.Equals(default(int)))
            {
                throw new ArgumentException(nameof(entity));
            }

            changeRequestItemStagings = new List <ChangeRequestItemStaging>();
            // Validation check for insert of new brake config

            await ValidateConfigurationDoesNotMatchWithExistingBrakeConfig(entity);
            await ValidateNoChangeRequestExistsWithSameConfiguration(entity);
            await ValidateBrakeConfigLookUpHasNoChangeRequest(entity);


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

            var brakeTypeRepositoryService   = Repositories.GetRepositoryService <BrakeType>() as IVcdbSqlServerEfRepositoryService <BrakeType>;
            var brakeAbsRepositoryService    = Repositories.GetRepositoryService <BrakeABS>() as IVcdbSqlServerEfRepositoryService <BrakeABS>;
            var brakeSystemRepositoryService = Repositories.GetRepositoryService <BrakeSystem>() as IVcdbSqlServerEfRepositoryService <BrakeSystem>;

            BrakeType   frontBrakeType = null;
            BrakeType   rearBrakeType  = null;
            BrakeABS    brakeAbs       = null;
            BrakeSystem brakeSystem    = null;

            if (brakeTypeRepositoryService != null && brakeAbsRepositoryService != null && brakeSystemRepositoryService != null)
            {
                var frontBrakeTypes = await brakeTypeRepositoryService.GetAsync(m => m.Id == entity.FrontBrakeTypeId && m.DeleteDate == null, 1);

                if (frontBrakeTypes != null && frontBrakeTypes.Any())
                {
                    frontBrakeType = frontBrakeTypes.First();
                }
                var rearBrakeTypes = await brakeTypeRepositoryService.GetAsync(m => m.Id == entity.RearBrakeTypeId && m.DeleteDate == null, 1);

                if (rearBrakeTypes != null && rearBrakeTypes.Any())
                {
                    rearBrakeType = rearBrakeTypes.First();
                }
                var brakeAbses = await brakeAbsRepositoryService.GetAsync(m => m.Id == entity.BrakeABSId && m.DeleteDate == null, 1);

                if (brakeAbses != null && brakeAbses.Any())
                {
                    brakeAbs = brakeAbses.First();
                }
                var brakeSystems = await brakeSystemRepositoryService.GetAsync(m => m.Id == entity.BrakeSystemId && m.DeleteDate == null, 1);

                if (brakeSystems != null && brakeSystems.Any())
                {
                    brakeSystem = brakeSystems.First();
                }

                changeContent = string.Format("{0} / {1} / {2} / {3}", frontBrakeType.Name, rearBrakeType.Name, brakeAbs.Name, brakeSystem.Name);
            }

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

            return(await base.SubmitAddChangeRequestAsync(entity, requestedBy, changeRequestItemStagings, comment, attachmentsStagingModels, changeContent));
        }