public async Task <IActionResult> Delete(int id, [FromBody] StudentDto studentDto)
        {
            var deleteStudentCommand = new DeleteStudentCommand(studentDto);
            var response             = await _mediator.Send(deleteStudentCommand);

            return(Ok(response));
        }
Exemple #2
0
        public ICommandResult Delete(Guid id)
        {
            DeleteStudentCommand command = new DeleteStudentCommand();

            command.Id = id;
            var result = (CommandResult)_handler.Handle(command);

            return(result);
        }
        public async Task Should_throw_delete_failure_exception()
        {
            // create course
            var createCourseCommand = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var createCourseCommandHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);
            var commandResult = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            // Create student
            var createStudentCommand = new CreateStudentCommand()
            {
                Id          = Guid.NewGuid(),
                FirstName   = "Milos",
                LastName    = "Stojkovic",
                Address     = "Bata Noleta 31",
                City        = "Sokobanja",
                DateOfBirth = new DateTime(1991, 3, 18),
                State       = "Srbija",
                Gender      = 0
            };

            var createStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context);

            commandResult = await createStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand()
            {
                Id         = createStudentCommand.Id,
                CourseCode = createCourseCommand.Code,
                Grade      = (int)Domain.Enumerations.Grade.Seven
            };

            var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);

            commandResult = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            var deleteStudentCommand = new DeleteStudentCommand()
            {
                Id = createStudentCommand.Id
            };

            var deleteStudentCommandHandler = new DeleteStudentCommandHandler(this.context);
            await Assert.ThrowsAsync <DeleteFailureException>(() => deleteStudentCommandHandler.Handle(deleteStudentCommand, CancellationToken.None));
        }
Exemple #4
0
        public async Task <IActionResult> DeleteStudentAsync(int studentId)
        {
            var command = new DeleteStudentCommand
            {
                Id = studentId
            };
            await mediator.Send(command);

            return(NoContent());
        }
        public async Task Should_throw_not_found_exception()
        {
            var deleteStudentCommand = new DeleteStudentCommand()
            {
                Id = Guid.NewGuid()
            };

            var deleteStudentCommandHandler = new DeleteStudentCommandHandler(this.context);

            await Assert.ThrowsAsync <NotFoundException>(() => deleteStudentCommandHandler.Handle(deleteStudentCommand, CancellationToken.None));
        }
        public async Task <int> Handle(DeleteStudentCommand request, CancellationToken cancellationToken)
        {
            var student = await _context.TableStudents.FirstOrDefaultAsync(cancellationToken);

            if (await CommitAsync(cancellationToken))
            {
                await _mediator.Publish(new StudentDeletedEvent("Worker", "Johnnie", DateTime.Now),
                                        cancellationToken);
            }

            throw new NotImplementedException();
        }
        public async Task <IActionResult> Delete([FromRoute] int?id)
        {
            if (id == 0)
            {
                return(BadRequest());
            }
            var deleteItem = new DeleteStudentCommand()
            {
                StudentId = id.Value
            };
            var result = await _deleteStudentCommand.Handle(deleteItem, CancellationToken.None);

            return(NoContent());
        }
        public async Task Should_delete_student()
        {
            var deleteStudentCommand = new DeleteStudentCommand()
            {
                Id = Guid.NewGuid()
            };

            var deleteStudentCommandHandler = new DeleteStudentCommandHandler(this.context);

            var result = await deleteStudentCommandHandler.Handle(deleteStudentCommand, CancellationToken.None);

            result.ShouldBe(true);

            var dbStudent = await this.context.Student.FirstOrDefaultAsync(s => s.Id == deleteStudentCommand.Id);

            dbStudent.ShouldBeNull();
        }
 protected void del_est(object sender, EventArgs e)
 {
     foreach (RepeaterItem item in estu_data.Items)
     {
         student       = new Student();
         student.Email = ((Label)item.FindControl("email")).Text;
         DeleteStudentCommand cmd = new DeleteStudentCommand(student);
         cmd.Execute();
         if (student.Code == 200)
         {
             ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true);
         }
         else
         {
         }
     }
 }
Exemple #10
0
        // Excluir um aluno
        public ICommandResult Handle(DeleteStudentCommand command)
        {
            // Valida os dados do command
            command.Validate();
            // Se for invalido, mostrar as notificações
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, SharedMessages.InvalidOperation, command));
            }

            // Deletando as  informações
            _studentRepository.Remove(command.Id);

            // Realizando a exclusão do banco de dados
            _uow.Commit();

            // Retornando informações de sucesso e o objeto preenchido
            return(new CommandResult(true, SharedMessages.SuccedOperation, command.Id));
        }
        public Task <CommandExecutionResult <Student> > Handle(DeleteStudentCommand request)
        {
            try
            {
                var student = _context.Set <Student>().Find(request.Id);

                _context.Set <Student>().Remove(student);
                _context.SaveChanges();

                return(Task.FromResult(new CommandExecutionResult <Student>()
                {
                    Success = true
                }));
            }
            catch (Exception exception)
            {
                return(Task.FromResult(new CommandExecutionResult <Student>()
                {
                    Success = false,
                    Exception = exception
                }));
            }
        }
Exemple #12
0
 public async Task <IActionResult> Delete(DeleteStudentCommand command)
 {
     return(this.Ok(await this.mediator.Send(command)));
 }
Exemple #13
0
 public async Task <ActionResult <bool> > DeleteStudent([FromRoute] DeleteStudentCommand command)
 {
     //todo delete paymenst when a student is deleted
     return(await Send(command));
 }
        public string DeleteStudent(DeleteStudentCommand command)
        {
            StudentsCommandHandler handler = new StudentsCommandHandler();

            return(handler.Handle(command));
        }