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

Refresh

February 2019

Views

2 time

0

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; }
[ForeignKey("DepartmentID")]
public virtual Department Department { get; set; }

public int GradeLevelsID { get; set; }
[ForeignKey("GradeLevelsID")]
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
                            .ToListAsync();
    }

And how can create an API related to it.

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

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

0 answers