public CreateMovementsViewModel(ShipmentInfo shipmentInfo)
        {
            StartDate         = shipmentInfo.ShipmentDates.StartDate;
            EndDate           = shipmentInfo.ShipmentDates.EndDate;
            NotificationUnits = shipmentInfo.ShipmentQuantityUnits;
            AvailableUnits    = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(shipmentInfo.ShipmentQuantityUnits).ToList();

            var items = shipmentInfo.PackagingData.PackagingTypes
                        .Where(x => x != PackagingType.Other)
                        .Select(x => new SelectListItem
            {
                Text  = EnumHelper.GetDisplayName(x),
                Value = ((int)x).ToString()
            })
                        .ToList();

            if (shipmentInfo.PackagingData.PackagingTypes.Contains(PackagingType.Other))
            {
                items.Add(new SelectListItem
                {
                    Text = string.Format("{0} - {1}", EnumHelper.GetShortName(PackagingType.Other),
                                         shipmentInfo.PackagingData.OtherDescription),
                    Value = ((int)PackagingType.Other).ToString()
                });
            }

            PackagingTypes = new CheckBoxCollectionViewModel();
            PackagingTypes.ShowEnumValue  = true;
            PackagingTypes.PossibleValues = items;
        }
        public async Task <ActionResult> Index(Guid id, bool?backToOverview = null)
        {
            var physicalCharacteristics = CheckBoxCollectionViewModel.CreateFromEnum <PhysicalCharacteristicType>();

            physicalCharacteristics.ShowEnumValue = true;

            //We need to exclude 'other' as this will be handled separately
            physicalCharacteristics.PossibleValues =
                physicalCharacteristics.PossibleValues.Where(
                    p => (PhysicalCharacteristicType)Convert.ToInt32(p.Value) != PhysicalCharacteristicType.Other)
                .ToList();

            var model = new PhysicalCharacteristicsViewModel
            {
                PhysicalCharacteristics = physicalCharacteristics,
                NotificationId          = id
            };

            var physicalCharacteristicsData =
                await mediator.SendAsync(new GetPhysicalCharacteristics(id));

            if (physicalCharacteristicsData != null)
            {
                model.PhysicalCharacteristics.SetSelectedValues(physicalCharacteristicsData.PhysicalCharacteristics);
                if (!string.IsNullOrWhiteSpace(physicalCharacteristicsData.OtherDescription))
                {
                    model.OtherSelected    = true;
                    model.OtherDescription = physicalCharacteristicsData.OtherDescription;
                }
            }
            return(View(model));
        }
        public PackagingTypesViewModel(PackagingData availablePackagingTypes, int movementNumber)
        {
            MovementNumber = movementNumber;

            var items = availablePackagingTypes.PackagingTypes
                .Where(x => x != PackagingType.Other)
                .Select(x => new SelectListItem
                {
                    Text = EnumHelper.GetDisplayName(x),
                    Value = ((int)x).ToString()
                })
                .ToList();

            if (availablePackagingTypes.PackagingTypes.Contains(PackagingType.Other))
            {
                items.Add(new SelectListItem
                {
                    Text = string.Format("{0} - {1}", EnumHelper.GetShortName(PackagingType.Other), 
                        availablePackagingTypes.OtherDescription),
                    Value = ((int)PackagingType.Other).ToString()
                });
            }

            PackagingTypes = new CheckBoxCollectionViewModel();
            PackagingTypes.ShowEnumValue = true;
            PackagingTypes.PossibleValues = items;
        }
Example #4
0
        public async Task Create_ExceedsShipmentsRemaining_ReturnsError()
        {
            movementId[0] = Guid.NewGuid();

            var remainingshipment = new RemainingShipmentsData
            {
                ShipmentsRemaining         = 100,
                ActiveLoadsPermitted       = 20,
                ActiveLoadsRemainingByDate = 20
            };

            var model = new CreateMovementsViewModel
            {
                Day            = 6,
                Month          = 2,
                Year           = 2019,
                Quantity       = "1",
                NumberToCreate = remainingshipment.ShipmentsRemaining + 1,
                PackagingTypes = CheckBoxCollectionViewModel.CreateFromEnum <PackagingType>()
            };

            model.PackagingTypes.PossibleValues.First(y => y.Value == "1").Selected = true;
            model.Units = ShipmentQuantityUnits.Kilograms;

            A.CallTo(
                () => mediator.SendAsync(A <GetRemainingShipments> .That.Matches(p => p.NotificationId == notificationId)))
            .Returns(remainingshipment);

            var result = await controller.Index(notificationId, model) as ViewResult;

            Assert.NotNull(result);
            Assert.False(result.ViewData.ModelState.IsValid);
            Assert.True(result.ViewData.ModelState.Keys.Any(k => k == NumberToCreateDisplayName));
        }
 public async Task Post_BackToOverviewFalse_RedirectsToWasteCodes()
 {
     var physicalCharacteristics = new CheckBoxCollectionViewModel();
     physicalCharacteristics.PossibleValues = new[] { new SelectListItem() };
     var model = new PhysicalCharacteristicsViewModel()
     {
         PhysicalCharacteristics = physicalCharacteristics
     };
     var result = await physicalCharacteristicsController.Index(model, false) as RedirectToRouteResult;
     RouteAssert.RoutesTo(result.RouteValues, "Index", "BaselOecdCode");
 }
        private PackagingTypesViewModel CreateValidPackagingTypesViewModel()
        {
            var packagingTypes = CheckBoxCollectionViewModel.CreateFromEnum <PackagingType>();
            var selectedValues = new[] { 1, 2 };

            packagingTypes.SetSelectedValues(selectedValues);
            return(new PackagingTypesViewModel()
            {
                PackagingTypes = packagingTypes,
                NotificationId = notificationId
            });
        }
        public async Task Post_BackToOverviewFalse_RedirectsToWasteCodes()
        {
            var physicalCharacteristics = new CheckBoxCollectionViewModel();

            physicalCharacteristics.PossibleValues = new[] { new SelectListItem() };
            var model = new PhysicalCharacteristicsViewModel()
            {
                PhysicalCharacteristics = physicalCharacteristics
            };
            var result = await physicalCharacteristicsController.Index(model, false) as RedirectToRouteResult;

            RouteAssert.RoutesTo(result.RouteValues, "Index", "BaselOecdCode");
        }
Example #8
0
        public ActionResult ColumnSelection(
            FOIReportDates dateType,
            DateTime from,
            DateTime to,
            FOIReportTextFields?textFieldType,
            TextFieldOperator?operatorType,
            string textSearch)
        {
            var foiOutputColumns = CheckBoxCollectionViewModel.CreateFromEnum <FOIOutputColumns>();

            var model = new ColumnSelectionViewModel(dateType, from, to, textFieldType, operatorType, textSearch, foiOutputColumns);

            return(View(model));
        }
Example #9
0
        public async Task Create_ReturnsWhoAreyourCarrier()
        {
            var packagingTypes = CheckBoxCollectionViewModel.CreateFromEnum <PackagingType>();

            movementId[0] = new Guid("AF1839A1-DA40-430B-9DFE-D79194175DFD");

            var remainingshipment = new RemainingShipmentsData
            {
                ShipmentsRemaining         = 400,
                ActiveLoadsPermitted       = 300,
                ActiveLoadsRemainingByDate = 100
            };

            var model = new CreateMovementsViewModel
            {
                Day            = 6,
                Month          = 2,
                Year           = 2019,
                Quantity       = "1",
                NumberToCreate = 1,
                PackagingTypes = packagingTypes
            };

            model.PackagingTypes.PossibleValues.First(y => y.Value == "1").Selected = true;
            model.Units = ShipmentQuantityUnits.Kilograms;

            A.CallTo(
                () => mediator.SendAsync(A <GetRemainingShipments> .That.Matches(p => p.NotificationId == notificationId)))
            .Returns(remainingshipment);

            A.CallTo(
                () => mediator.SendAsync(A <GetWorkingDaysUntil> .That.Matches(p => p.NotificationId == notificationId)))
            .Returns(6);

            A.CallTo(() => mediator.SendAsync(A <CreateMovements> .That.Matches(p => p.NotificationId == notificationId)))
            .Returns(movementId);

            var result = await controller.Index(notificationId, model) as RedirectToRouteResult;

            Assert.NotNull(result);
            Assert.Equal("WhoAreYourCarriers", result.RouteValues["action"]);
        }
Example #10
0
 public ColumnSelectionViewModel(ShipmentsReportDates dateType,
                                 DateTime from,
                                 DateTime to,
                                 ShipmentReportTextFields?textFieldType,
                                 TextFieldOperator?operatorType, string searchText, CheckBoxCollectionViewModel shipmentOutputColumns)
 {
     ShipmentReportColumns = new ReportOutputParametersViewModel()
     {
         DateType      = dateType.ToString(),
         FromDate      = from,
         ToDate        = to,
         TextFieldType = textFieldType.ToString(),
         OperatorType  = operatorType.ToString(),
         SearchText    = searchText,
         ReportColumns = shipmentOutputColumns
     };
 }