예제 #1
0
        public async Task <IHttpActionResult> GetChangeRequestStaging(int changeRequestId)
        {
            BedConfigChangeRequestStagingModel changeRequestStagingBedConfigModel =
                await this._bedConfigApplicationService.GetChangeRequestStaging(changeRequestId);

            ChangeRequestStagingBedConfigViewModel changeRequestStagingBedConfigViewModel = Mapper.Map <ChangeRequestStagingBedConfigViewModel>(changeRequestStagingBedConfigModel);

            SetUpChangeRequestReview(changeRequestStagingBedConfigViewModel.StagingItem.Status,
                                     changeRequestStagingBedConfigViewModel.StagingItem.SubmittedBy, changeRequestStagingBedConfigViewModel);

            return(Ok(changeRequestStagingBedConfigViewModel));
        }
        public new async Task <BedConfigChangeRequestStagingModel> GetChangeRequestStaging <TId>(TId changeRequestId)
        {
            var result = await
                         ChangeRequestBusinessService.GetChangeRequestStagingByChangeRequestIdAsync <BedConfig, TId>(changeRequestId);

            List <VehicleToBedConfig> vehicleToBedConfigs = null;

            if (result.StagingItem.ChangeType == ChangeType.Replace.ToString())
            {
                result.EntityStaging = result.EntityCurrent;
                var changeRequestIdLong = Convert.ToInt64(changeRequestId);
                var vehicleToBedConfigChangeRequestItems = await this.ChangeRequestBusinessService.GetChangeRequestItemStagingsAsync(item => item.ChangeRequestId == changeRequestIdLong);

                if (vehicleToBedConfigChangeRequestItems != null && vehicleToBedConfigChangeRequestItems.Any())
                {
                    var vehicleToBedConfigIds = vehicleToBedConfigChangeRequestItems.Select(item => Convert.ToInt32(item.EntityId)).ToList();
                    vehicleToBedConfigs = await base.Repositories.GetRepositoryService <VehicleToBedConfig>()
                                          .GetAsync(item => vehicleToBedConfigIds.Any(id => id == item.Id) && item.DeleteDate == null);

                    //1. Extract the replacement bed config to bed config id from the first deserialized vehicleToBedConfigChangeRequestItems
                    var vehicleToBedConfig = Serializer.Deserialize <VehicleToBedConfig>(vehicleToBedConfigChangeRequestItems[0].Payload);

                    //2. fill result.EntityStaging with the replacement Bed config details
                    result.EntityStaging = await FindAsync(vehicleToBedConfig.BedConfigId);

                    // 3. fill currentEntity
                    result.EntityCurrent = await FindAsync(result.StagingItem.EntityId);
                }
                else
                {
                    var vehicleToBedConfigChangeRequestStoreItems = await this.ChangeRequestBusinessService.GetChangeRequestItemAsync(item =>
                                                                                                                                      item.ChangeRequestId == changeRequestIdLong);

                    if (vehicleToBedConfigChangeRequestStoreItems != null && vehicleToBedConfigChangeRequestStoreItems.Any())
                    {
                        var vehicleToBedConfigIds = vehicleToBedConfigChangeRequestStoreItems.Select(item => Convert.ToInt32(item.EntityId)).ToList();
                        vehicleToBedConfigs =
                            await
                            base.Repositories.GetRepositoryService <VehicleToBedConfig>()
                            .GetAsync(item => vehicleToBedConfigIds.Any(id => id == item.Id) && item.DeleteDate == null);

                        //1. Extract the replacement base vehicle id from the first deserialized vehicleChangeRequestItems
                        var vehicleToBedConfig = Serializer.Deserialize <VehicleToBedConfig>(vehicleToBedConfigChangeRequestStoreItems[0].Payload);

                        //2. fill result.EntityStaging with the replacement base vehicle details
                        result.EntityStaging = await FindAsync(vehicleToBedConfig.BedConfigId);

                        // 3. fill currentEntity
                        result.EntityCurrent = await FindAsync(result.StagingItem.EntityId);
                    }
                }
            }

            BedConfigChangeRequestStagingModel staging = new BedConfigChangeRequestStagingModel
            {
                EntityCurrent = result.EntityCurrent,
                EntityStaging = result.EntityStaging,
                //RequestorComments = result.RequestorComments,
                //ReviewerComments = result.ReviewerComments,
                Comments    = result.Comments,
                StagingItem = result.StagingItem,
                ReplacementVehicleToBedConfigs = vehicleToBedConfigs,
                Attachments = result.Attachments
            };

            return(staging);
        }