Пример #1
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var cmd    = new DeleteDepartmentCommand(id);
            var result = await _mediator.Send(cmd);

            return(Ok(result));
        }
Пример #2
0
 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.");
     }
 }
Пример #3
0
 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."));
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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());
        }
Пример #6
0
        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;
        }
Пример #7
0
        public async Task <IActionResult> DeleteDepartment(int id)
        {
            var deleteDepartmentCommand = new DeleteDepartmentCommand(id);

            return(Ok(await Mediator.Send(deleteDepartmentCommand)));
        }
Пример #8
0
 public async Task OnGetAsync(Query query)
 {
     Data = await _mediator.Send(query);
 }