public async Task<IHttpActionResult> Post(VehicleTypeGroupInputModel model)
        {
            if (model == null)
            {
                return BadRequest(ErrorMessage.TypeGroup.RequiredTypeGroupInputModel);
            }

            if (model.Name == null)
            {
                return BadRequest(ErrorMessage.TypeGroup.RequiredTypeGroup);
            }

            VehicleTypeGroup typeGroup = new VehicleTypeGroup()
            {
                Id = model.Id,
                Name = model.Name,
            };

            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };

            var attachments = SetUpAttachmentsModels(model.Attachments);

            var changeRequestId = await _vehicleTypeGroupApplicationService.AddAsync(typeGroup, CurrentUser.Email, comment, attachments);
            return Ok(changeRequestId);
        }
Example #2
0
        private async Task UpdateVehicleToMfrBodyCodeDocuments(VehicleTypeGroup updatedVehicleTypeGroup)
        {
            bool isEndReached = false;
            int  pageNumber   = 1;

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

                var existingVehicleToMfrBodyCodeDocuments = vehicleToMfrBodyCodeSearchResult.Documents;
                if (existingVehicleToMfrBodyCodeDocuments != null && existingVehicleToMfrBodyCodeDocuments.Any())
                {
                    foreach (var existingVehicleToMfrBodyCodeDocument in existingVehicleToMfrBodyCodeDocuments)
                    {
                        existingVehicleToMfrBodyCodeDocument.VehicleTypeGroupName = updatedVehicleTypeGroup.Name;
                    }

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

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);
        }
Example #3
0
        public override async Task <long> SubmitUpdateChangeRequestAsync <TId>(BrakeSystem entity, TId id, string requestedBy,
                                                                               ChangeType changeType = ChangeType.None,
                                                                               List <ChangeRequestItemStaging> changeRequestItemStagings = null, CommentsStagingModel comment = null, List <AttachmentsModel> attachments = null, string changeContent = null)
        {
            if (String.IsNullOrWhiteSpace(entity?.Name))
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (id.Equals(default(TId)))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (!entity.Id.Equals(id))
            {
                throw new ArgumentException("Invalid Brake System Id");
            }

            var brakeSystemFromDb = await FindAsync(id);

            if (brakeSystemFromDb == null)
            {
                throw new NoRecordFound("No Brake System exist");
            }

            changeRequestItemStagings = changeRequestItemStagings ?? new List <ChangeRequestItemStaging>();

            await ValidateBrakeSystemHasNoChangeRequest(entity);
            await ValidateBrakeSystemLookUpHasNoChangeRequest(entity);

            entity.InsertDate = brakeSystemFromDb.InsertDate;

            var existingEntity = new VehicleTypeGroup()
            {
                Id             = brakeSystemFromDb.Id,
                Name           = brakeSystemFromDb.Name,
                DeleteDate     = brakeSystemFromDb.DeleteDate,
                InsertDate     = brakeSystemFromDb.InsertDate,
                LastUpdateDate = brakeSystemFromDb.LastUpdateDate
            };

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

            changeContent = string.Format("{0} > {1}"
                                          , brakeSystemFromDb.Name
                                          , entity.Name);

            var changeRequestId = await base.SubmitUpdateChangeRequestAsync(entity, id, requestedBy, ChangeType.Modify, changeRequestItemStagings, comment, attachments, changeContent);

            brakeSystemFromDb.ChangeRequestId = changeRequestId;
            _brakeSystemRepositoryService.Update(brakeSystemFromDb);
            Repositories.SaveChanges();
            return(changeRequestId);
        }