private async Task HandleMessage(string message)
        {
            _logger.LogInformation($"Handling Message: {message}");
            using var doc = JsonDocument.Parse(message);
            var root      = doc.RootElement;
            var eventType = root.GetProperty("EventType");
            var entity    = root.GetProperty("Entity");

            using var scope = _serviceScopeFactory.CreateScope();
            var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();

            if (eventType.GetString() == "Doctor-Created")
            {
                int    id      = entity.GetProperty("Id").GetInt32();
                string name    = entity.GetProperty("Name").GetString();
                var    command = new CreateDoctorCommand
                {
                    Id   = id,
                    Name = name
                };
                await mediator.Send(command);

                string notification = $"New Doctor Added: {name}";
                await _scheduleHub.Clients.All.SendAsync("ReceiveMessage", notification);
            }
            // TODO: Implement other kinds of updates
        }
Exemple #2
0
        public async Task CreateDoctor(CreateDoctorCommand createDoctorCommand)
        {
            var firstName = createDoctorCommand.FirstName;
            var lastName  = createDoctorCommand.LastName;
            var email     = createDoctorCommand.Email;
            var doctor    = new Doctor(firstName, lastName, email);
            await _context.AddAsync(doctor);

            await _context.SaveChangesAsync();
        }
Exemple #3
0
        public void Should_Create_A_Valid_Doctor()
        {
            CreateDoctorCommand command = new CreateDoctorCommand()
            {
                Name        = "Cacin",
                CRM         = "330310744",
                CPF         = "75317627060",
                DateOfBirth = DateTime.Parse("12/06/1986"),
                SpecialtyId = specialtyRepository.specialties[1].Id
            };

            Assert.IsNotNull(_handler.Handler(command));
        }
        private async Task HandleMessage(string message)
        {
            _logger.LogInformation($"Handling Message: {message}");

            // TODO: A real app would have better error handling for parsing and routing messages
            using var doc = JsonDocument.Parse(message);
            var root      = doc.RootElement;
            var eventType = root.GetProperty("EventType");
            var entity    = root.GetProperty("Entity");

            using var scope = _serviceScopeFactory.CreateScope();
            var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();

            if (eventType.GetString() == "Doctor-Created")
            {
                int    id      = entity.GetProperty("Id").GetInt32();
                string name    = entity.GetProperty("Name").GetString();
                var    command = new CreateDoctorCommand
                {
                    Id   = id,
                    Name = name
                };
                await mediator.Send(command);

                string notification = $"New Doctor {name} added in Clinic Management. ";
                await _scheduleHub.Clients.All.SendAsync("ReceiveMessage", notification);
            }
            if (eventType.GetString() == "Client-Updated")
            {
                int    id      = entity.GetProperty("Id").GetInt32();
                string name    = entity.GetProperty("Name").GetString();
                var    command = new UpdateClientCommand
                {
                    Id   = id,
                    Name = name
                };
                await mediator.Send(command);

                // TODO: Only send notification if changes occurred
                string notification = $"Client {name} updated in Clinic Management.";
                await _scheduleHub.Clients.All.SendAsync("ReceiveMessage", notification);
            }
            // TODO: Implement other kinds of updates
        }
 public async Task <ActionResult <int> > Create(CreateDoctorCommand command)
 {
     return(await Mediator.Send(command));
 }
Exemple #6
0
        public async Task <IActionResult> CreateDoctor(CreateDoctorCommand createDoctorCommand)
        {
            await _doctorsService.CreateDoctor(createDoctorCommand);

            return(Created("", null));
        }
Exemple #7
0
        public async Task <IActionResult> CreateDoctor([FromBody] CreateDoctorCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(result));
        }