public async Task <Result <AddPersonRelationshipResponse> > Handle(AddPersonRelationshipCommand request, CancellationToken cancellationToken) { try { using (_unitOfWork) { PersonRelationship personRelationship = new PersonRelationship(); personRelationship.PersonId = request.PersonId; personRelationship.PatientId = request.PatientId; personRelationship.RelationshipTypeId = request.RelationshipTypeId; personRelationship.CreatedBy = request.UserId; personRelationship.CreateDate = DateTime.Now; await _unitOfWork.Repository <PersonRelationship>().AddAsync(personRelationship); await _unitOfWork.SaveAsync(); _unitOfWork.Dispose(); return(Result <AddPersonRelationshipResponse> .Valid(new AddPersonRelationshipResponse() { PersonRelationshipId = personRelationship.Id })); } } catch (Exception e) { return(Result <AddPersonRelationshipResponse> .Invalid(e.Message)); } }
public async Task <IActionResult> AddPersonRelationship( [FromBody] AddPersonRelationshipCommand addPersonRelationshipCommand) { var response = await _mediator.Send(addPersonRelationshipCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }