i have the text field 'fio' in my search form, which can be empty.
home.html:
<dx-text-box
[(value)]="fio"
></dx-text-box>
this is my component and service to send the search parametres for API
component:
public fio!: string;
public updateFromPeriod(): void {
this.updateService.updateFromPeriod(this.DateIn, this.DateOut, this.punktsID(this.punktValue), this.fio).subscribe({
next: value => {
this.EventLogs = value;
},
error: err => {
console.error(err);
}
});
service:
updateFromPeriod(DateIn: any,
DateOut: any,
idPunkts: any,
fio: string) {
const options = {
params: new HttpParams().append('DateIn', this.toISOLocal(DateIn)).append('DateOut', this.toISOLocal(DateOut)).appendAll({'idPunkts': idPunkts})
.append('fio', fio),
headers: new HttpHeaders().set('Content-Type', 'application/json').set('Authorization', `Bearer ${this.authService.currentSessionValue.token}`)
};
console.log('PARAMS: ' + options.params);
return this.httpClient.get<EventLog[]>(this.BaseUrl +'EventLog/FromPeriod', options);
}
and server method:
public IEnumerable<EventLog> Get(
[FromQuery] DateTime DateIn,
[FromQuery] DateTime DateOut,
[FromQuery] int[] idPunkts,
[FromQuery] string fio) {
List<int> punkts = idPunkts.ToList();
var login = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
return EventLogRepository.GetEventLog(DateIn, DateOut, punkts, fio, login);
}
I want to make the fio parameter optional in query string, which will not send, if it's empty. And the query string will be like this
http://localhost:5025/EventLog/FromPeriod?DateIn=2023-02-08T11%3A50%3A10.198Z&DateOut=2023-02-08T11%3A50%3A10.198Z&idPunkts=18
i try to add ?fio: string in my service method, but have the type mistake. Als i tried to add null on api controller, but it still doestn work.