Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have a project i'm doing in C# ASP.Net MVC5 as my backend,and my frontend is also in C#.how will i bind the two for them to communicate.i'm using a search engine in my frontend to get data from the backend and SQL server.i need your good answers.
I have 3 tables,Students,Courses and Student_courses.my backend works well,i am confused on how to use the frontend to run queries to get results.i can't use the same method i used on the backend for the frontend.i don't need api again.query to get results i need

What I have tried:

this is my search view for the front end
@model UniScore.ViewModels.StudentCoursesViewModel

@{

    Layout = "~/Views/Shared/_Layout2.cshtml";
}
<h1 align="center">SEARCH STUDENT</h1>
<br />

<div class="container">
    @using (Html.BeginForm("Search", "Search", FormMethod.Get))
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">

            <p>Please type in your Student ID and First Name</p>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.id_Student, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.id_Student, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.id_Student, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="SearchResults" class="btn btn-default" />
                </div>
            </div>
        </div>

    }
</div>


Student table has(id_student,firstname and lastname),
Course table has(id_course,code,course name)
Student_course table(id,student_id,course_id,mark,grade)...now every student can do a lot of courses.i didn't use foreign keys.
How can i use the view to display the courses a student is undertaking in the search,which linq query will i use to display values in the controller.if you can give me idea of how to code in the controller i will be fine.
Posted
Updated 10-Apr-17 4:32am
v2
Comments
ZurdoDev 4-Apr-17 7:01am    
Be more specific. It really just sounds like both apps need to access the same db.
Member 13053943 4-Apr-17 11:19am    
yes sir,they all have to access the same database.how will i go about.do i have to create a controller to take care of the search entities for the frontend?just like the way i did for backend.i used linq to do the listind and sorting.this time with the search in the frontend.i will search by id and firstname of a student
ZurdoDev 4-Apr-17 11:23am    
Is there any reason they both can't access the database directly?
Member 13053943 4-Apr-17 11:32am    
they can,what is your best suggestion to this issue,maybe i don't really need api,tell me what to do
ZurdoDev 4-Apr-17 11:39am    
If they can both access the db directly, then do that. I'm not sure where you are stuck or what the issue is. I must be missing something.

You can create a dll that sits as your data access layer or you can just access the db directly via both apps. Depends on what you want to do.

1 solution

You don't have to run any query from UI side. If your queries to find one student's all courses at API side working fine then create an API which will take a parameter which is required to run your query like searchText and studentId and return list of courses selected by that student . Your API is done now call it from UI application using jquery ajax and populate it to your html view page .
Your search application on 3rd party data is ready to use .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900