public async Task <IHttpActionResult> Post(int id, BodyStyleConfigInputModel model)
        {
            BodyStyleConfig bodyStyleConfig = new BodyStyleConfig()
            {
                Id = model.Id,
                VehicleToBodyStyleConfigCount = model.VehicleToBodyStyleConfigCount
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment,
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _bodyStyleConfigApplicationService.DeleteAsync(bodyStyleConfig, id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
        public async Task <IHttpActionResult> Post(BodyStyleConfigInputModel model)
        {
            BodyStyleConfig bodyStyleConfig = new BodyStyleConfig()
            {
                Id             = model.Id,
                BodyNumDoorsId = model.BodyNumDoorsId,
                BodyTypeId     = model.BodyTypeId
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _bodyStyleConfigApplicationService.AddAsync(bodyStyleConfig, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
Beispiel #3
0
        private async Task UpdateVehicleToBodyStyleConfigDocuments(BodyStyleConfig updatedBodyStyleConfig)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var vehicleToBodyStyleConfigSearchResult =
                    await
                    _vehicleToBodyStyleConfigSearchService.SearchAsync(null,
                                                                       $"bodyStyleConfigId eq {updatedBodyStyleConfig.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToBodyStyleConfigDocuments = vehicleToBodyStyleConfigSearchResult.Documents;

                if (existingVehicleToBodyStyleConfigDocuments != null && existingVehicleToBodyStyleConfigDocuments.Any())
                {
                    foreach (var existingVehicleToBodyStyleConfigDocument in existingVehicleToBodyStyleConfigDocuments)
                    {
                        existingVehicleToBodyStyleConfigDocument.BodyStyleConfigChangeRequestId = -1;
                        existingVehicleToBodyStyleConfigDocument.BodyNumDoorsId = updatedBodyStyleConfig.BodyNumDoorsId;
                        existingVehicleToBodyStyleConfigDocument.BodyNumDoors   = updatedBodyStyleConfig.BodyNumDoors.NumDoors;
                        existingVehicleToBodyStyleConfigDocument.BodyTypeId     = updatedBodyStyleConfig.BodyTypeId;
                        existingVehicleToBodyStyleConfigDocument.BodyTypeName   = updatedBodyStyleConfig.BodyType.Name;
                    }

                    await
                    this._vehicleToBodyStyleConfigIndexingService.UploadDocumentsAsync(existingVehicleToBodyStyleConfigDocuments.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
        public async Task <IHttpActionResult> Replace(int id, BodyStyleConfigInputModel model)
        {
            BodyStyleConfig bodyStyleConfig = new BodyStyleConfig()
            {
                Id                        = model.Id,
                BodyNumDoorsId            = model.BodyNumDoorsId,
                BodyTypeId                = model.BodyTypeId,
                VehicleToBodyStyleConfigs = model.VehicleToBodyStyleConfigs.Select(item => new VehicleToBodyStyleConfig
                {
                    BodyStyleConfigId = item.BodyStyleConfigId,
                    Id        = item.Id,
                    VehicleId = item.VehicleId
                }).ToList(),
            };

            CommentsStagingModel comment = new CommentsStagingModel {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _bodyStyleConfigApplicationService.ReplaceAsync(bodyStyleConfig, id, CurrentUser.Email, comment, attachments);

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

            changeRequestItemStagings = changeRequestItemStagings ?? new List <ChangeRequestItemStaging>();
            // Validation check for insert of new vehicle to Bed config
            StringBuilder validationErrorMessage = new StringBuilder();

            await ValidateVehicleToBodyConfigHasNoChangeReqeuest(entity);
            await ValidateVehicleToBodyConfigLookUpHasNoChangeRequest(entity);

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

            var vehicleRepositoryService         = Repositories.GetRepositoryService <Vehicle>() as IVcdbSqlServerEfRepositoryService <Vehicle>;
            var bodyStyleConfigRepositoryService = Repositories.GetRepositoryService <BodyStyleConfig>() as IVcdbSqlServerEfRepositoryService <BodyStyleConfig>;

            Vehicle         vehicle         = null;
            BodyStyleConfig bodyStyleConfig = null;

            if (vehicleRepositoryService != null && bodyStyleConfigRepositoryService != null)
            {
                var vehicles = await vehicleRepositoryService.GetAsync(m => m.Id == entity.VehicleId && m.DeleteDate == null, 1);

                if (vehicles != null && vehicles.Any())
                {
                    vehicle = vehicles.First();
                }

                var bodyStyleConfigs = await bodyStyleConfigRepositoryService.GetAsync(m => m.Id == entity.BodyStyleConfigId && m.DeleteDate == null, 1);

                if (bodyStyleConfigs != null && bodyStyleConfigs.Any())
                {
                    bodyStyleConfig = bodyStyleConfigs.First();
                }
            }

            changeContent = string.Format("{0} / {1} / {2} / {3} / {4} => \n{5} / {6}"
                                          , vehicle.BaseVehicle.YearId
                                          , vehicle.BaseVehicle.Make.Name
                                          , vehicle.BaseVehicle.Model.Name
                                          , vehicle.SubModel.Name
                                          , vehicle.Region.Name
                                          , bodyStyleConfig.BodyNumDoors.NumDoors
                                          , bodyStyleConfig.BodyType.Name);

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

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