public async Task <IActionResult> Delete(Guid id) { var cmd = new DeleteDepartmentCommand(id); var result = await _mediator.Send(cmd); return(Ok(result)); }
public IActionResult ConfirmDelete(Guid id) { if (ModelState.IsValid) { var command = new DeleteDepartmentCommand(id); _commandService.Handle(command); return RedirectToAction("Index").WithSuccess("Department deleted successfully."); } else { return RedirectToAction("Delete", new { id }).WithError("An error occured."); } }
public IActionResult ConfirmDelete(Guid id) { if (ModelState.IsValid) { var command = new DeleteDepartmentCommand(id); _commandService.Handle(command); return(RedirectToAction("Index").WithSuccess("Department deleted successfully.")); } else { return(RedirectToAction("Delete", new { id }).WithError("An error occured.")); } }
public IEnumerable <IEvent> Handle(DeleteDepartmentCommand cmd) { if (cmd == null) { throw new ArgumentNullException(nameof(cmd)); } if (cmd.AggregateId == Guid.Empty) { throw new ArgumentException(nameof(cmd.AggregateId)); } var events = new List <IEvent>(); events.Add(new DeleteDepartmentEvent(cmd.AggregateId)); return(events); }
public async Task <ActionResult> DeleteDepartmentAsync(int id) { bool commandResult = false; var deleteDepartmentCommand = new DeleteDepartmentCommand(id); _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", deleteDepartmentCommand.GetType().Name, nameof(deleteDepartmentCommand.Id), deleteDepartmentCommand.Id, deleteDepartmentCommand); commandResult = await _mediator.Send(deleteDepartmentCommand); if (!commandResult) { return(BadRequest()); } return(Ok()); }
public IEnumerable<IEvent> Handle(DeleteDepartmentCommand cmd) { if (cmd == null) throw new ArgumentNullException(nameof(cmd)); if (cmd.AggregateId == Guid.Empty) throw new ArgumentException(nameof(cmd.AggregateId)); var events = new List<IEvent>(); events.Add(new DeleteDepartmentEvent(cmd.AggregateId)); return events; }
public async Task <IActionResult> DeleteDepartment(int id) { var deleteDepartmentCommand = new DeleteDepartmentCommand(id); return(Ok(await Mediator.Send(deleteDepartmentCommand))); }
public async Task OnGetAsync(Query query) { Data = await _mediator.Send(query); }