在GET中传递值,在linq查询中使用值,Angular 6

时间:2018-12-30 23:37:48

标签: angular

我想发送带有值的http GET调用,然后使用该值过滤linq查询。该值在html输入“ ClassTimesStudentID”中设置。 GET函数-getStudentDataAll()似乎仅在我在构造函数中运行时才起作用。当前的返回数组太大(需要7秒),因此我想通过在查询中传递“ ClassTimesStudentID”值在C#linq查询中进一步过滤该数组,并返回一个较小的数组,该数组的学生位于值位置。我无法弄清楚Angular组件和服务中的语法来做到这一点。 一旦将值传递给C#控制器,我就不知道如何将其放入linq中。 后端是.NET Core 2.0实体框架。

<form (ngSubmit)="onSubmit(f)" #f="ngForm"> <div class="row">
     <div class="col-sm-5 form-group">
       <label for="name">Student ID</label>
         <input type="text" id="ClassTimesStudentID" class="form-control" name="ClassTimesStudentID" [(ngModel)]="ClassTimesStudentID"> 

component.ts

public studentNameData: Array<any>;
public filteredName: Array<any>;

private _ClassTimesStudentID: any;
get ClassTimesStudentID(): any {
return this._ClassTimesStudentID; }

set ClassTimesStudentID(value: any) {
 this._ClassTimesStudentID = value; 
 this.filteredName = this.filterStudent(value);

 filterStudent(ClassTimesStudentID: any) {
 return this.studentNameData.filter(name => name.studentIdother === this.ClassTimesStudentID); }

constructor(private loginService: LoginService, private dataStorageService: DataStorageService) {
  dataStorageService.getStudentDataAll().subscribe((importName: any) => 
this.studentNameData = importName);
  console.log('call ' + this.studentNameData);}

service.ts

import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable()
 export class DataStorageService {
private headers: HttpHeaders;
private accessPointUrl: string = 'http://localhost:59673/api/ClassTimes';

constructor(private http: HttpClient, 
          private adminService: AdminService,
          private authService: AuthService) {
this.headers = new HttpHeaders({'Content-Type': 'application/json; charset=utf-8'}); }

 public getStudentDataAll() {
// calls ScheduleDemographicsController
return this.http.get('http://localhost:59673/api/ScheduleDemographics', {headers: this.headers}); }

.NET Core控制器

     // GET: api/ScheduleDemographics
     [HttpGet]

     public IActionResult GetZzTestSiscombinedScheduleandDemographics()

        var readPulse = _ctx.ZzTestSiscombinedScheduleandDemographics.Select(s => new { s.StudentIdother, s.SpecEd, s.StudentName, s.SchoolNumber, s.CourseName, s.Gradelevel }).Distinct();
        var distinctStudent = readPulse.GroupBy(g => g.StudentIdother).Select(y => y.FirstOrDefault());
        foreach (var student in distinctStudent);

        return Ok(distinctStudent); }

0 个答案:

没有答案