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 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 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"); }
public async Task <ActionResult> Index(PhysicalCharacteristicsViewModel model, bool?backToOverview = null) { if (!ModelState.IsValid) { return(View(model)); } try { var selectedPackagingTypes = model.PhysicalCharacteristics.PossibleValues.Where(p => p.Selected) .Select(p => (PhysicalCharacteristicType)(Convert.ToInt32(p.Value))) .ToList(); if (model.OtherSelected) { selectedPackagingTypes.Add(PhysicalCharacteristicType.Other); } var existingPhysicalCharacteristicsData = await mediator.SendAsync(new GetPhysicalCharacteristics(model.NotificationId)); await mediator.SendAsync(new SetPhysicalCharacteristics(selectedPackagingTypes, model.NotificationId, model.OtherDescription)); await this.auditService.AddAuditEntry(this.mediator, model.NotificationId, User.GetUserId(), existingPhysicalCharacteristicsData.PhysicalCharacteristics.Count == 0?NotificationAuditType.Added : NotificationAuditType.Updated, NotificationAuditScreenType.PhysicalCharacteristics); if (backToOverview.GetValueOrDefault()) { return(RedirectToAction("Index", "Home", new { id = model.NotificationId })); } return(RedirectToAction("Index", "BaselOecdCode", new { id = model.NotificationId })); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return(View(model)); }
public async Task<ActionResult> Index(PhysicalCharacteristicsViewModel model, bool? backToOverview = null) { if (!ModelState.IsValid) { return View(model); } try { var selectedPackagingTypes = model.PhysicalCharacteristics.PossibleValues.Where(p => p.Selected) .Select(p => (PhysicalCharacteristicType)(Convert.ToInt32(p.Value))) .ToList(); if (model.OtherSelected) { selectedPackagingTypes.Add(PhysicalCharacteristicType.Other); } await mediator.SendAsync(new SetPhysicalCharacteristics(selectedPackagingTypes, model.NotificationId, model.OtherDescription)); if (backToOverview.GetValueOrDefault()) { return RedirectToAction("Index", "Home", new { id = model.NotificationId }); } return RedirectToAction("Index", "BaselOecdCode", new { id = model.NotificationId }); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return View(model); }