I'm trying to check whether user is adding dupicate IDs in one cohort and if so, I need to print to the webpage a warning: "ID already exists in the cohort" and prevent the user from entering the existing ID again. Now that I did the checking in the if statement but I do not know how to print out to the webpage in the ELSE statement.
Here is the code in the C# file that I'm trying to modify in the Controller:
foreach (string studentID in cc.students)
{
SqlDataReader rdr = null;
cmd = new SqlCommand(@"select * from CustomCohortStudent where PUID = @StudentID and cohortID = @cohortID", sqlConn);
rdr = cmd.ExecuteReader();
if (rdr == null)
{
cmd = new SqlCommand(@"insert into CustomCohortStudents(cohortID, PUID) values (@id,@StudentID)", sqlConn);
}
else
{
// code to print warning to the webpage
}
And I don't know how should I edit the cshtml file in the Views accordingly.. Here is what I had in my index.cshtml file:
<h2>Cohorts</h2>
<a href="CustomCohort/Create">Create</a><br /><br />
<table class="table">
<tr>
<!--
<th>
@Html.DisplayNameFor(model => model.id)
</th>
-->
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
<!--Actions-->
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<!--
<td>
@item.id
</td>
-->
<td>
@item.name
</td>
<td>
<a href="CustomCohort/Edit/@item.id">Edit</a> |
<a href="CustomCohort/Delete/@item.id">Delete</a>
</td>
</tr>
}
</table>
So my question is: What should I add in the ELSE statement in the Controller and what to modify in the Views?