예제 #1
0
파일: Post.cs 프로젝트: TraceLD/IbdTracker
            public async Task <BowelMovementEventDto> Handle(Command request, CancellationToken cancellationToken)
            {
                // convert to EFCore entity - BowelMovementEvent;
                var bme = new BowelMovementEvent
                {
                    PatientId      = request.PatientId,
                    DateTime       = request.DateTime,
                    ContainedBlood = request.ContainedBlood,
                    ContainedMucus = request.ContainedMucus
                };

                // add to DB and save changes;
                await _context.BowelMovementEvents.AddAsync(bme, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                // convert to DTO to follow the best practice of not returning entire EFCore
                // entities in JSON body responses;
                //
                // ID is auto-generated by DB on addition and updated by EFCore so
                // that it exists on the bme object;
                return(new()
                {
                    BowelMovementEventId = bme.BowelMovementEventId,
                    PatientId = bme.PatientId,
                    DateTime = bme.DateTime,
                    ContainedBlood = bme.ContainedBlood,
                    ContainedMucus = bme.ContainedMucus
                });
            }
예제 #2
0
파일: Post.cs 프로젝트: TraceLD/IbdTracker
            public async Task <BowelMovementEventDto> Handle(Command request, CancellationToken cancellationToken)
            {
                // convert to EFCore entity;
                var patientId = _userService.GetUserAuthId();
                var bme       = new BowelMovementEvent
                {
                    PatientId      = patientId,
                    DateTime       = request.DateTime,
                    ContainedBlood = request.ContainedBlood,
                    ContainedMucus = request.ContainedMucus
                };

                await _context.BowelMovementEvents.AddAsync(bme, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                // convert to DTO;
                return(new()
                {
                    BowelMovementEventId = bme.BowelMovementEventId,
                    PatientId = bme.PatientId,
                    DateTime = bme.DateTime,
                    ContainedBlood = bme.ContainedBlood,
                    ContainedMucus = bme.ContainedMucus
                });
            }
예제 #3
0
        public async Task ShouldDeleteBmIfFound()
        {
            // arrange;
            // prepare a bm to delete;
            var bmToDelete = new BowelMovementEvent
            {
                PatientId      = TestUserHelper.TestPatientId,
                ContainedBlood = true,
                ContainedMucus = true,
                DateTime       = DateTime.Now
            };
            await Context.BowelMovementEvents.AddAsync(bmToDelete);

            await Context.SaveChangesAsync();

            // prepare the CQRS command;
            var command        = new Delete.Command(bmToDelete.BowelMovementEventId);
            var getObjectQuery = new GetOne.Query(bmToDelete.BowelMovementEventId);

            // res should be of type NoContentResult;
            // resObject should return null because the object no longer exists (deleted);

            var res = await SendMediatorRequestInScopeOnBehalfOfTheTestPatient(command);

            var resObject = await SendMediatorRequestInScopeOnBehalfOfTheTestPatient(getObjectQuery);

            // assert;
            res.Should().BeOfType <NoContentResult>();
            resObject.Should().BeNull();

            // no need to clean up the DB as we've just deleted the BM we've added;
        }