public async Task <ActionResult> Remove(RemoveFacilityViewModel model, bool?backToOverview = null) { try { await mediator.SendAsync(new DeleteFacilityForNotification(model.NotificationId, model.FacilityId)); await this.auditService.AddAuditEntry(this.mediator, model.NotificationId, User.GetUserId(), NotificationAuditType.Deleted, model.NotificationType == NotificationType.Disposal?NotificationAuditScreenType.DisposalFacilities : NotificationAuditScreenType.RecoveryFacilities); if (model.IsOnlySiteOfTreatment) { await this.auditService.AddAuditEntry(this.mediator, model.NotificationId, User.GetUserId(), NotificationAuditType.Deleted, model.NotificationType == NotificationType.Disposal?NotificationAuditScreenType.DisposalSite : NotificationAuditScreenType.RecoverySite); } return(RedirectToAction("List", "Facility", new { id = model.NotificationId, backToOverview })); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return(View(model)); }
public async Task <ActionResult> Remove(Guid id, Guid entityId, bool?backToOverview = null) { ViewBag.BackToOverview = backToOverview.GetValueOrDefault(); var notificationInfo = await mediator.SendAsync(new GetNotificationBasicInfo(id)); var response = await mediator.SendAsync(new GetFacilitiesByNotificationId(id)); var facility = response.Single(p => p.Id == entityId); var model = new RemoveFacilityViewModel { NotificationId = id, FacilityId = entityId, FacilityName = facility.Business.Name, NotificationType = notificationInfo.NotificationType, IsOnlySiteOfTreatment = facility.IsActualSiteOfTreatment && response.Count == 1 ? true : false }; if (facility.IsActualSiteOfTreatment && response.Count > 1) { ViewBag.Error = string.Format("You have chosen to remove {0} which is the site of {1}. " + "You will need to select an alternative site of {1} before you can remove this facility.", model.FacilityName, model.NotificationType.ToString().ToLowerInvariant()); return(View(model)); } return(View(model)); }
public async Task Remove_ReturnsList() { var model = new RemoveFacilityViewModel { NotificationId = notificationId, FacilityId = facilityId }; var result = await facilityController.Remove(model) as RedirectToRouteResult; Assert.Equal("List", result.RouteValues["action"]); }
public async Task Remove_WithBackToOverviewNull_DefaultsRouteValueToFalse() { var model = new RemoveFacilityViewModel { NotificationId = notificationId, FacilityId = facilityId }; var result = await facilityController.Remove(model, null) as RedirectToRouteResult; var backToOverviewKey = "backToOverview"; Assert.True(result.RouteValues.ContainsKey(backToOverviewKey)); Assert.False(Convert.ToBoolean(result.RouteValues[backToOverviewKey])); }
public async Task Remove_CallsClient() { var model = new RemoveFacilityViewModel { NotificationId = notificationId, FacilityId = facilityId }; await facilityController.Remove(model); A.CallTo( () => mediator.SendAsync(A <DeleteFacilityForNotification> .That.Matches( p => p.NotificationId == notificationId && p.FacilityId == facilityId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task Remove_CallsClient() { var model = new RemoveFacilityViewModel { NotificationId = notificationId, FacilityId = facilityId }; await facilityController.Remove(model); A.CallTo( () => mediator.SendAsync(A<DeleteFacilityForNotification>.That.Matches( p => p.NotificationId == notificationId && p.FacilityId == facilityId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task<ActionResult> Remove(RemoveFacilityViewModel model, bool? backToOverview = null) { try { await mediator.SendAsync(new DeleteFacilityForNotification(model.NotificationId, model.FacilityId)); return RedirectToAction("List", "Facility", new { id = model.NotificationId, backToOverview }); } catch (ApiBadRequestException ex) { this.HandleBadRequest(ex); if (ModelState.IsValid) { throw; } } return View(model); }
public async Task<ActionResult> Remove(Guid id, Guid entityId, bool? backToOverview = null) { ViewBag.BackToOverview = backToOverview.GetValueOrDefault(); var notificationInfo = await mediator.SendAsync(new GetNotificationBasicInfo(id)); var response = await mediator.SendAsync(new GetFacilitiesByNotificationId(id)); var facility = response.Single(p => p.Id == entityId); var model = new RemoveFacilityViewModel { NotificationId = id, FacilityId = entityId, FacilityName = facility.Business.Name, NotificationType = notificationInfo.NotificationType }; if (facility.IsActualSiteOfTreatment && response.Count > 1) { ViewBag.Error = string.Format("You have chosen to remove {0} which is the site of {1}. " + "You will need to select an alternative site of {1} before you can remove this facility.", model.FacilityName, model.NotificationType.ToString().ToLowerInvariant()); return View(model); } return View(model); }