public async Task <ActionResult> Remove(RemoveProducerViewModel model, bool?backToOverview = null) { try { await mediator.SendAsync(new DeleteProducerForNotification(model.ProducerId, model.NotificationId)); await this.auditService.AddAuditEntry(this.mediator, model.NotificationId, User.GetUserId(), NotificationAuditType.Deleted, NotificationAuditScreenType.Producer); if (model.IsOnlySiteOfExport) { await this.auditService.AddAuditEntry(this.mediator, model.NotificationId, User.GetUserId(), NotificationAuditType.Deleted, NotificationAuditScreenType.SiteOfExport); } return(RedirectToAction("List", "Producer", 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 response = await mediator.SendAsync(new GetProducersByNotificationId(id)); var producer = response.Single(p => p.Id == entityId); var model = new RemoveProducerViewModel { NotificationId = id, ProducerId = entityId, ProducerName = producer.Business.Name, IsOnlySiteOfExport = producer.IsSiteOfExport && response.Count == 1 ? true : false }; if (producer.IsSiteOfExport && response.Count > 1) { ViewBag.Error = string.Format("You have chosen to remove {0} which is the site of export. " + "You will need to select an alternative site of export before you can remove this producer.", model.ProducerName); return(View(model)); } return(View(model)); }
public async Task Remove_ReturnsList() { var model = new RemoveProducerViewModel { NotificationId = notificationId, ProducerId = producerId }; var result = await producerController.Remove(model) as RedirectToRouteResult; Assert.Equal("List", result.RouteValues["action"]); }
public async Task Remove_WithBackToOverviewNull_DefaultsRouteValueToFalse() { var model = new RemoveProducerViewModel { NotificationId = notificationId, ProducerId = producerId }; var result = await producerController.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 RemoveProducerViewModel { NotificationId = notificationId, ProducerId = producerId }; await producerController.Remove(model); A.CallTo( () => mediator.SendAsync(A <DeleteProducerForNotification> .That.Matches( p => p.NotificationId == notificationId && p.ProducerId == producerId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task Remove_CallsClient() { var model = new RemoveProducerViewModel { NotificationId = notificationId, ProducerId = producerId }; await producerController.Remove(model); A.CallTo( () => mediator.SendAsync(A<DeleteProducerForNotification>.That.Matches( p => p.NotificationId == notificationId && p.ProducerId == producerId))) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task<ActionResult> Remove(RemoveProducerViewModel model, bool? backToOverview = null) { try { await mediator.SendAsync(new DeleteProducerForNotification(model.ProducerId, model.NotificationId)); return RedirectToAction("List", "Producer", 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 response = await mediator.SendAsync(new GetProducersByNotificationId(id)); var producer = response.Single(p => p.Id == entityId); var model = new RemoveProducerViewModel { NotificationId = id, ProducerId = entityId, ProducerName = producer.Business.Name }; if (producer.IsSiteOfExport && response.Count > 1) { ViewBag.Error = string.Format("You have chosen to remove {0} which is the site of export. " + "You will need to select an alternative site of export before you can remove this producer.", model.ProducerName); return View(model); } return View(model); }