public async Task <ActionResult> SiteOfTreatment(SiteOfTreatmentViewModel model, bool?backToList, bool?backToOverview = null) { try { if (!ModelState.IsValid) { return(View(model)); } var existingFacilities = await mediator.SendAsync(new GetFacilitiesByNotificationId(model.NotificationId)); await mediator.SendAsync( new SetActualSiteOfTreatment(model.SelectedSiteOfTreatment.GetValueOrDefault(), model.NotificationId)); NotificationAuditType type = NotificationAuditType.Added; if (existingFacilities != null && existingFacilities.Count(p => p.IsActualSiteOfTreatment) > 0) { type = NotificationAuditType.Updated; } await this.auditService.AddAuditEntry(mediator, model.NotificationId, User.GetUserId(), type, model.NotificationType == NotificationType.Disposal?NotificationAuditScreenType.DisposalSite : NotificationAuditScreenType.RecoverySite); if (backToList.GetValueOrDefault()) { return(RedirectToAction("List", "Facility", new { id = model.NotificationId, backToOverview })); } if (backToOverview.GetValueOrDefault()) { return(RedirectToAction("Index", "Home", new { id = model.NotificationId })); } if (model.NotificationType == NotificationType.Recovery) { return(RedirectToAction("RecoveryPreconsent", "Facility", new { id = model.NotificationId })); } return(RedirectToAction("OperationCodes", "WasteOperations", new { id = model.NotificationId })); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return(View(model)); }
public async Task SiteOfTreatment_BackToListTrue_ReturnsList() { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId }; var result = await facilityController.SiteOfTreatment(model, true) as RedirectToRouteResult; Assert.Equal("List", result.RouteValues["action"]); }
public async Task SiteOfTreatment_BackToListTrue_IgnoresBackToOverview(bool?backToOverview) { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId, NotificationType = NotificationType.Recovery }; var result = await facilityController.SiteOfTreatment(model, true, backToOverview) as RedirectToRouteResult; Assert.Equal("List", result.RouteValues["action"]); }
public async Task SiteOfTreatment_BackToListFalse_DisposalReturnsOperationCodes() { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId, NotificationType = NotificationType.Disposal }; var result = await facilityController.SiteOfTreatment(model, null) as RedirectToRouteResult; RouteAssert.RoutesTo(result.RouteValues, "OperationCodes", "WasteOperations"); }
public async Task SiteOfTreatment_BackToListFalse_RecoveryReturnsRecoveryPreconsent() { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId, NotificationType = NotificationType.Recovery }; var result = await facilityController.SiteOfTreatment(model, null) as RedirectToRouteResult; RouteAssert.RoutesTo(result.RouteValues, "RecoveryPreconsent", "Facility"); }
public async Task SiteOfTreatment_Post_SetsSiteOfTreatment() { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId }; await facilityController.SiteOfTreatment(model, null); A.CallTo( () => mediator.SendAsync(A <SetActualSiteOfTreatment> .That.Matches(p => p.NotificationId == notificationId && p.FacilityId == facilityId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task <ActionResult> SiteOfTreatment(Guid id, bool?backToList, bool?backToOverview = null) { ViewBag.BackToOverview = backToOverview.GetValueOrDefault(); var response = await mediator.SendAsync(new GetFacilitiesByNotificationId(id)); var notificationInfo = await mediator.SendAsync(new GetNotificationBasicInfo(id)); var model = new SiteOfTreatmentViewModel { NotificationId = id, Facilities = response, NotificationType = notificationInfo.NotificationType }; return(View(model)); }
public async Task SiteOfTreatment_BackToListTrue_IgnoresBackToOverview(bool? backToOverview) { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId, NotificationType = NotificationType.Recovery }; var result = await facilityController.SiteOfTreatment(model, true, backToOverview) as RedirectToRouteResult; Assert.Equal("List", result.RouteValues["action"]); }
public async Task SiteOfTreatment_Post_SetsSiteOfTreatment() { var model = new SiteOfTreatmentViewModel { NotificationId = notificationId, SelectedSiteOfTreatment = facilityId }; await facilityController.SiteOfTreatment(model, null); A.CallTo( () => mediator.SendAsync(A<SetActualSiteOfTreatment>.That.Matches(p => p.NotificationId == notificationId && p.FacilityId == facilityId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task<ActionResult> SiteOfTreatment(SiteOfTreatmentViewModel model, bool? backToList, bool? backToOverview = null) { try { if (!ModelState.IsValid) { return View(model); } await mediator.SendAsync( new SetActualSiteOfTreatment(model.SelectedSiteOfTreatment.GetValueOrDefault(), model.NotificationId)); if (backToList.GetValueOrDefault()) { return RedirectToAction("List", "Facility", new { id = model.NotificationId, backToOverview }); } if (backToOverview.GetValueOrDefault()) { return RedirectToAction("Index", "Home", new { id = model.NotificationId }); } if (model.NotificationType == NotificationType.Recovery) { return RedirectToAction("RecoveryPreconsent", "Facility", new { id = model.NotificationId }); } return RedirectToAction("OperationCodes", "WasteOperations", new { id = model.NotificationId }); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return View(model); }
public async Task<ActionResult> SiteOfTreatment(Guid id, bool? backToList, bool? backToOverview = null) { ViewBag.BackToOverview = backToOverview.GetValueOrDefault(); var response = await mediator.SendAsync(new GetFacilitiesByNotificationId(id)); var notificationInfo = await mediator.SendAsync(new GetNotificationBasicInfo(id)); var model = new SiteOfTreatmentViewModel { NotificationId = id, Facilities = response, NotificationType = notificationInfo.NotificationType }; return View(model); }