public override async Task <long> SubmitAddChangeRequestAsync(BedConfig entity, string requestedBy,
                                                                      List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null,
                                                                      List <AttachmentsModel> attachmentsStagingModels          = null, string changeContent = null)
        {
            if (entity.BedLengthId.Equals(default(int)) ||
                entity.BedTypeId.Equals(default(int)))
            {
                throw new ArgumentException(nameof(entity));
            }

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

            await ValidateConfigurationDoesNotMatchWithExistingBedConfig(entity);
            await ValidateNoChangeRequestExistsWithSameConfiguration(entity);
            await ValidateBedConfigLookUpHasNoChangeRequest(entity);


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

            var bedTypeRepositoryService   = Repositories.GetRepositoryService <BedType>() as IVcdbSqlServerEfRepositoryService <BedType>;
            var bedLengthRepositoryService = Repositories.GetRepositoryService <BedLength>() as IVcdbSqlServerEfRepositoryService <BedLength>;

            BedType   bedType   = null;
            BedLength bedLength = null;

            if (bedTypeRepositoryService != null && bedLengthRepositoryService != null)
            {
                var bedTypes = await bedTypeRepositoryService.GetAsync(m => m.Id == entity.BedTypeId && m.DeleteDate == null, 1);

                if (bedTypes != null && bedTypes.Any())
                {
                    bedType = bedTypes.First();
                }
                var bedLengths = await bedLengthRepositoryService.GetAsync(m => m.Id == entity.BedLengthId && m.DeleteDate == null, 1);

                if (bedLengths != null && bedLengths.Any())
                {
                    bedLength = bedLengths.First();
                }

                changeContent = string.Format("{0} / {1} / {2}", bedType.Name, bedLength.Length, bedLength.BedLengthMetric);
            }

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

            return(await base.SubmitAddChangeRequestAsync(entity, requestedBy, changeRequestItemStagings, comment, attachmentsStagingModels, changeContent));
        }
        public async Task <IHttpActionResult> Post(BedLengthInputModel model)
        {
            BedLength bedLength = new BedLength()
            {
                Id = model.Id, Length = model.Length, BedLengthMetric = model.BedLengthMetric
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _bedLengthApplicationService.AddAsync(bedLength, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
        public async Task <IHttpActionResult> Put(int id, BedLengthInputModel bedLengthInputModel)
        {
            BedLength bedlength = new BedLength()
            {
                Id                      = bedLengthInputModel.Id,
                Length                  = bedLengthInputModel.Length,
                BedLengthMetric         = bedLengthInputModel.BedLengthMetric,
                VehicleToBedConfigCount = bedLengthInputModel.VehicleToBedConfigCount,
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = bedLengthInputModel.Comment
            };
            var attachments     = SetUpAttachmentsModels(bedLengthInputModel.Attachments);
            var changeRequestId = await _bedLengthApplicationService.UpdateAsync(bedlength, bedlength.Id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
Exemple #4
0
        private async Task UpdateVehicleToBedConfigDocuments(BedLength updatedBedLength)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

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

                var existingVehicleToBedConfigDocuments = vehicleToBrakeConfigSearchResult.Documents;

                if (existingVehicleToBedConfigDocuments != null &&
                    existingVehicleToBedConfigDocuments.Any())
                {
                    foreach (
                        var existingVehicleToBedConfigDocument in
                        existingVehicleToBedConfigDocuments)
                    {
                        existingVehicleToBedConfigDocument.BedLength       = updatedBedLength.Length;
                        existingVehicleToBedConfigDocument.BedLengthMetric = updatedBedLength.BedLengthMetric;
                    }

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

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }