public async Task <ServiceRequest> Handle(UpdateServiceRequestByIdCommand request, CancellationToken cancellationToken) { _logger.LogInformation("Updating Service Requests By Id {Id} - Request: {@Request}", request.Id, request); var serviceRequest = await _serviceRequestRepository.RetrieveByIdAsync(request.Id); if (serviceRequest is null) { _logger.LogInformation("Service Request With Id {Id} Not Found - ServiceRequests: {@ServiceRequests}", request.Id, false); return(null); } // Let the ServiceRequestAggregate handle the business logic behind updating the fields. serviceRequest.SetLastModifiedBy(request.RequestBody.ModifiedBy); serviceRequest.SetLastModifiedDate(DateTime.UtcNow); serviceRequest.SetBuildingCode(request.RequestBody.BuildingCode); serviceRequest.SetDescription(request.RequestBody.Description); serviceRequest.SetCurrentStatus(request.RequestBody.CurrentStatus); _serviceRequestRepository.Update(serviceRequest); _logger.LogInformation("Service Request With Id {Id} Deleted - ServiceRequests: {@ServiceRequests}", request.Id, true); return(serviceRequest); }
/// <summary> /// Handles the request to query a single ServiceRequest entity by Id. /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns>Returns expected ServiceRequest entity if exists; otherwise, null</returns> public async Task <ServiceRequest> Handle(QueryServiceRequestById request, CancellationToken cancellationToken) { _logger.LogInformation("Querying Service Requests By Id {Id} - Request: {@Request}", request.Id, request); var response = await _serviceRequestRepository.RetrieveByIdAsync(request.Id); _logger.LogInformation("Queried Request By Id {Id} - ServiceRequests: {@ServiceRequests}", request.Id, response); return(response); }
/// <summary> /// Handles the DeleteServiceRequestByIdCommand. /// </summary> /// <param name="request">The DeleteServiceRequestByIdCommand being handled.</param> /// <param name="cancellationToken"></param> /// <returns>The created ServiceRequest entity</returns> public async Task <bool> Handle(DeleteServiceRequestByIdCommand request, CancellationToken cancellationToken) { _logger.LogInformation("Deleting Service Requests By Id {Id} - Request: {@Request}", request.Id, request); var serviceRequestToDelete = await _serviceRequestRepository.RetrieveByIdAsync(request.Id); if (serviceRequestToDelete is null) { _logger.LogInformation("Service Request With Id {Id} Not Found - ServiceRequests: {@ServiceRequests}", request.Id, false); return(false); } _serviceRequestRepository.Delete(serviceRequestToDelete); _logger.LogInformation("Service Request With Id {Id} Deleted - ServiceRequests: {@ServiceRequests}", request.Id, true); return(true); }