public async Task <IActionResult> GetAnimalByAnimalId(long animalId) { var query = new GetAnimalByAnimalIdQuery { AnimalId = animalId }; var createAnimalResponse = await _mediator.Send(query); var restResult = createAnimalResponse.ToRestResult(HttpStatusCode.NotFound); return(ObjectResultExtension.CreateResponse(restResult)); }
public async Task <Either <ExceptionResponse, GetAnimalByDeviceIdentifierQueryResponse> > Handle( GetAnimalByAnimalIdQuery queryParams, CancellationToken cancellationToken) { GetAnimalByDeviceIdentifierQueryResponse response; using (var connection = _dapperConnection.GetOpenConnection()) { var query = "select animal.*, da.*, device.* from Animal.Animal animal " + "inner join Animal.DeviceAssignment da on da.AnimalID = animal.AnimalId " + "inner join Device.Device device on device.DeviceID = da.DeviceID " + $"where da.ReplacementDate is null and animal.AnimalId = {queryParams.AnimalId}"; var currentAnimal = await connection .QueryAsync <Data.Domains.Animal.Animal, DeviceAssignment, Device, DeviceAssignedToAnimal>(query, (animal, deviceAssignment, device) => { if (animal == null) { return(null); } return(new DeviceAssignedToAnimal { AnimalId = animal.AnimalId, DeviceID = device.DeviceID, CurrentPropertyIdentifierID = animal.CurrentPropertyIdentifierID, CreatedRequestID = animal.CreatedRequestID, LastModifiedRequestID = animal.LastModifiedRequestID, BirthDate = animal.BirthDate, DeviceAssignment = deviceAssignment, NLISID = device.NLISID, RFID = device.RFID, AssignmentDate = deviceAssignment.AssignmentDate, AssignedToPropertyIdentifierID = device.AssignedToPropertyIdentifierID, IssueToPropertyIdentifierID = device.AssignedToPropertyIdentifierID, Species = animal.SpeciesID }); }, splitOn : "AnimalId, DeviceId"); if (!currentAnimal.Any()) { return(ExceptionResponse.With( ErrorMessage: $"Associated Animal's data is not found. AnimalId = {queryParams.AnimalId}", HttpStatusCode: HttpStatusCode.NotFound)); } response = new GetAnimalByDeviceIdentifierQueryResponse(currentAnimal.FirstOrDefault()); } return(response); }