How get value on the basis of two input value in Dotnet core and need to call in API creation


2 weeks ago


2 time


My problem is that I want to call Course on the basis of two value get through the drop-down. Link first I selected department and the Gradelevle.

Here is the schema in of Course.cs

 public partial class Course
public int ID { get; set; }
public string Name { get; set; }

public int DepartmentID { get; set; }
public virtual Department Department { get; set; }

public int GradeLevelsID { get; set; }
public virtual GradeLevels GradeLevels { get; set; }

Here Department and GradeLevel is foreign key, and I calling it in drop-down in two fields, on the basis of this, I need course and then it will be call in API get value.

Here is ICourseRepository

public interface ICourseRepository
Task<ICollection<Course>> GetCoursesOfDepartmentAndGradeLevel(int depatmentId, int gradelevlId);

Here is CourseRepository: I have no idea to how get course on the basis of two id?

public Task<ICollection<Course>> GetCoursesOfDepartmentAndGradeLevel(int depatmentId, int gradelevlId)
        var school = await _GpsContext.Courses.Where(x => x.ID == gradelevlId  ) //No idea how to get the course on the basis of two value id

And how can create an API related to it.

private readonly ICourseRepository _courseRespository; public CourseController(ICourseRepository courseRespository) { _courseRespository = courseRespository; }

    public async Task<IEnumerable<Course>> Get(int depatmentId, int gradelevlId)
        return await _courseRespository.GetCoursesOfDepartmentAndGradeLevel(int depatmentId, int gradelevlId);

0 answers