Exemple #1
0
        private static ChemicalCompositionContinuedViewModel GetValidViewModel()
        {
            var vm = new ChemicalCompositionContinuedViewModel();

            vm.WasteComposition        = new List <WasteTypeCompositionData>();
            vm.OtherCodes              = new List <WasteTypeCompositionData>();
            vm.ChemicalCompositionType = ChemicalComposition.Wood;
            vm.Command = "continue";

            return(vm);
        }
Exemple #2
0
        private bool AllOtherCodesFieldsContainData(ChemicalCompositionContinuedViewModel model)
        {
            var result = true;

            foreach (var i in model.OtherCodes)
            {
                if (string.IsNullOrWhiteSpace(i.Constituent))
                {
                    result = false;
                }
            }

            return(result);
        }
        public async Task RdfSrf_Post_BackToOverviewFalse_RedirectsToWasteGenerationProcess()
        {
            var wasteComposition = new List <WasteTypeCompositionData>();
            var model            = new ChemicalCompositionContinuedViewModel()
            {
                NotificationId          = notificationId,
                ChemicalCompositionType = ChemicalComposition.RDF,
                WasteComposition        = wasteComposition,
                OtherCodes = wasteComposition,
                Command    = "continue"
            };
            var result = await chemicalCompositionController.Constituents(model, false) as RedirectToRouteResult;

            RouteAssert.RoutesTo(result.RouteValues, "Index", "WasteGenerationProcess");
        }
        public async Task WoodContined_Post_BackToOverviewTrue_RedirectsToOverview()
        {
            var wasteComposition = new List <WasteTypeCompositionData>();
            var model            = new ChemicalCompositionContinuedViewModel()
            {
                NotificationId          = notificationId,
                ChemicalCompositionType = ChemicalComposition.Wood,
                WasteComposition        = wasteComposition,
                OtherCodes = wasteComposition,
                Command    = "continue"
            };
            var result = await chemicalCompositionController.Constituents(model, true) as RedirectToRouteResult;

            RouteAssert.RoutesTo(result.RouteValues, "Index", "Home");
        }
 public async Task WoodContined_Post_BackToOverviewTrue_RedirectsToOverview()
 {
     var wasteComposition = new List<WasteTypeCompositionData>();
     var model = new ChemicalCompositionContinuedViewModel() 
     {
         NotificationId = notificationId,
         ChemicalCompositionType = ChemicalComposition.Wood,
         WasteComposition = wasteComposition,
         OtherCodes = wasteComposition,
         Command = "continue"
     };
     var result = await chemicalCompositionController.Constituents(model, true) as RedirectToRouteResult;
     RouteAssert.RoutesTo(result.RouteValues, "Index", "Home");
 }
 public async Task RdfSrf_Post_BackToOverviewFalse_RedirectsToWasteGenerationProcess()
 {
     var wasteComposition = new List<WasteTypeCompositionData>();
     var model = new ChemicalCompositionContinuedViewModel()
     {
         NotificationId = notificationId,
         ChemicalCompositionType = ChemicalComposition.RDF,
         WasteComposition = wasteComposition,
         OtherCodes = wasteComposition,
         Command = "continue"
     };
     var result = await chemicalCompositionController.Constituents(model, false) as RedirectToRouteResult;
     RouteAssert.RoutesTo(result.RouteValues, "Index", "WasteGenerationProcess");
 }
Exemple #7
0
        private async Task GetExistingConstituents(Guid id, ChemicalComposition chemicalCompositionType, ChemicalCompositionContinuedViewModel model)
        {
            var wasteTypeData = await mediator.SendAsync(new GetWasteType(id));

            // If the old data does not exist or corresponds to a different waste type data.
            if (!ContainsData(wasteTypeData) || wasteTypeData.ChemicalCompositionType != chemicalCompositionType)
            {
                while (model.OtherCodes.Count < NumberOfOtherCodesFields)
                {
                    model.OtherCodes.Add(new WasteTypeCompositionData());
                }
                return;
            }

            var compositions = wasteTypeData.WasteCompositionData.Select(c => new WasteTypeCompositionData
            {
                ChemicalCompositionCategory = c.ChemicalCompositionCategory,
                Constituent      = c.Constituent,
                MinConcentration = c.MinConcentration.ToString(),
                MaxConcentration = c.MaxConcentration.ToString()
            }).ToList();

            // Where the waste concentration is not applicable it is not stored.
            var notApplicableCompositions =
                model.WasteComposition.Where(
                    wc =>
                    compositions.All(c => c.ChemicalCompositionCategory != wc.ChemicalCompositionCategory)).Select(wc => new WasteTypeCompositionData
            {
                ChemicalCompositionCategory = wc.ChemicalCompositionCategory,
                Constituent      = wc.Constituent,
                MinConcentration = NotApplicable,
                MaxConcentration = NotApplicable
            });

            compositions.AddRange(notApplicableCompositions);

            model.WasteComposition   = compositions.Where(c => c.ChemicalCompositionCategory != ChemicalCompositionCategory.Other).ToList();
            model.OtherCodes         = compositions.Where(c => c.ChemicalCompositionCategory == ChemicalCompositionCategory.Other).ToList();
            model.FurtherInformation = wasteTypeData.FurtherInformation;
            model.HasAnnex           = wasteTypeData.HasAnnex;

            while (model.OtherCodes.Count < NumberOfOtherCodesFields)
            {
                model.OtherCodes.Add(new WasteTypeCompositionData());
            }
        }
Exemple #8
0
        public async Task <ActionResult> Constituents(ChemicalCompositionContinuedViewModel model, bool?backToOverview = null)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var existingWasteTypeData = await mediator.SendAsync(new GetWasteType(model.NotificationId));

            //Join optional and mandatory collections
            model.WasteComposition.AddRange(model.OtherCodes);

            var blanksRemoved = model.WasteComposition.Where(c => !string.IsNullOrEmpty(c.Constituent));

            var filteredWasteCompositions = RemoveNotApplicableValues(blanksRemoved);

            await mediator.SendAsync(new UpdateWasteType(model.NotificationId, model.ChemicalCompositionType, model.FurtherInformation, filteredWasteCompositions));

            await mediator.SendAsync(new SetOptionalInformation(model.FurtherInformation, model.HasAnnex, model.NotificationId));

            bool dataHasChanged = false;

            string firstScreensLastAuditType = await GetFirstScreensLastAuditType(model.NotificationId);

            if (firstScreensLastAuditType == NotificationAuditType.Added.ToString() && existingWasteTypeData.WasteCompositionData.Count == 0)
            {
                await this.auditService.AddAuditEntry(this.mediator,
                                                      model.NotificationId,
                                                      User.GetUserId(),
                                                      NotificationAuditType.Added,
                                                      NotificationAuditScreenType.ChemicalCompositionContinued);
            }
            else
            {
                if (existingWasteTypeData.WasteCompositionData.Count != 0)
                {
                    dataHasChanged = CheckForChangesInSecondScreen(existingWasteTypeData, filteredWasteCompositions, model.FurtherInformation, model.HasAnnex, model.ChemicalCompositionType);

                    if (dataHasChanged)
                    {
                        await this.auditService.AddAuditEntry(this.mediator,
                                                              model.NotificationId,
                                                              User.GetUserId(),
                                                              NotificationAuditType.Updated,
                                                              NotificationAuditScreenType.ChemicalCompositionContinued);
                    }
                }
                else
                {
                    await this.auditService.AddAuditEntry(this.mediator,
                                                          model.NotificationId,
                                                          User.GetUserId(),
                                                          NotificationAuditType.Updated,
                                                          NotificationAuditScreenType.ChemicalCompositionContinued);
                }
            }

            if (backToOverview.GetValueOrDefault())
            {
                return(RedirectToAction("Index", "Home", new { id = model.NotificationId }));
            }

            return(RedirectToAction("Index", "WasteGenerationProcess", new { id = model.NotificationId }));
        }
        private static ChemicalCompositionContinuedViewModel GetValidViewModel()
        {
            var vm = new ChemicalCompositionContinuedViewModel();
            vm.WasteComposition = new List<WasteTypeCompositionData>();
            vm.OtherCodes = new List<WasteTypeCompositionData>();
            vm.ChemicalCompositionType = ChemicalComposition.Wood;
            vm.Command = "continue";

            return vm;
        }