public async Task <IHttpActionResult> Post(MfrBodyCodeInputModel model)
        {
            MfrBodyCode mfrBodyCode = new MfrBodyCode()
            {
                Id   = model.Id,
                Name = model.Name
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _mfrBodyCodeApplicationService.AddAsync(mfrBodyCode, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
        public async Task <IHttpActionResult> Post(int id, MfrBodyCodeInputModel model)
        {
            MfrBodyCode mfrBodyCode = new MfrBodyCode()
            {
                Id = model.Id,
                VehicleToMfrBodyCodeCount = model.VehicleToMfrBodyCodeCount
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment,
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _mfrBodyCodeApplicationService.DeleteAsync(mfrBodyCode, id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
        public async Task <IHttpActionResult> Replace(int id, MfrBodyCodeInputModel model)
        {
            MfrBodyCode mfrBodyCode = new MfrBodyCode()
            {
                Id   = model.Id,
                Name = model.Name,
                VehicleToMfrBodyCodes = model.VehicleToMfrBodyCodes.Select(item => new VehicleToMfrBodyCode
                {
                    MfrBodyCodeId = item.MfrBodyCodeId,
                    Id            = item.Id,
                    VehicleId     = item.VehicleId
                }).ToList(),
            };

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

            return(Ok(changeRequestId));
        }
Ejemplo n.º 4
0
        private async Task UpdateVehicleToMfrBodyCodeDocuments(MfrBodyCode updatedMfrBodyCode)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var vehicleToMfrBodyCodeSearchResult =
                    await
                    _vehicletoMfrBodyCodeSearchService.SearchAsync(null,
                                                                   $"mfrBodyCodeId eq {updatedMfrBodyCode.Id}", new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                var existingVehicleToMfrBodyCodeDocuments = vehicleToMfrBodyCodeSearchResult.Documents;

                if (existingVehicleToMfrBodyCodeDocuments != null && existingVehicleToMfrBodyCodeDocuments.Any())
                {
                    foreach (var existingVehicleToMfrBodyCodeDocument in existingVehicleToMfrBodyCodeDocuments)
                    {
                        existingVehicleToMfrBodyCodeDocument.MfrBodyCodeChangeRequestId = -1;
                        existingVehicleToMfrBodyCodeDocument.MfrBodyCodeId   = updatedMfrBodyCode.Id;
                        existingVehicleToMfrBodyCodeDocument.MfrBodyCodeName = updatedMfrBodyCode.Name;
                    }

                    await this._vehicleToMfrBodyCodeIndexingService.UploadDocumentsAsync(existingVehicleToMfrBodyCodeDocuments.ToList());

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
Ejemplo n.º 5
0
        public override async Task <long> SubmitAddChangeRequestAsync(VehicleToMfrBodyCode entity, string requestedBy,
                                                                      List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null,
                                                                      List <AttachmentsModel> attachmentsStagingModels          = null, string changeContent = null)
        {
            if (entity.VehicleId.Equals(default(int)) ||
                entity.MfrBodyCodeId.Equals(default(int)))
            {
                throw new ArgumentException(nameof(entity));
            }

            changeRequestItemStagings = changeRequestItemStagings ?? new List <ChangeRequestItemStaging>();
            // Validation check for insert of new vehicle to Mfr Body code

            StringBuilder validationErrorMessage = new StringBuilder();

            await ValidateVehicleToMfrBodyCodeHasNoChangeReqeuest(entity);
            await ValidateVehicleToMfrBodyCodeLookUpHasNoChangeRequest(entity);

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

            var vehicleRepositoryService     = Repositories.GetRepositoryService <Vehicle>() as IVcdbSqlServerEfRepositoryService <Vehicle>;
            var MfrBodyCodeRepositoryService = Repositories.GetRepositoryService <MfrBodyCode>() as IVcdbSqlServerEfRepositoryService <MfrBodyCode>;

            Vehicle     vehicle     = null;
            MfrBodyCode MfrBodyCode = null;

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

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

                var MfrBodyCodes = await MfrBodyCodeRepositoryService.GetAsync(m => m.Id == entity.MfrBodyCodeId && m.DeleteDate == null, 1);

                if (MfrBodyCodes != null && MfrBodyCodes.Any())
                {
                    MfrBodyCode = MfrBodyCodes.First();
                }
            }

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

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

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