I'm creating a booking system where i want add people to a reference code and the limit is 4 people.when i add a person,the name should be added to number of people in my view and the number of people must be updated,I have no idea about how to do it,please help me out.thank you.
What I have tried:
this is my view
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Booked Members</h2>
<p>
@Html.ActionLink("Book Tee Times", "Create", routeValues: null, htmlAttributes: new { @class = "btn btn-info btn-link" })
</p>
<table class="table table-striped table-hover">
<tr>
<th>
@Html.DisplayNameFor(model => model.MemberId)
</th>
<th>
@Html.DisplayNameFor(model => model.Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Time)
</th>
<th>
@Html.DisplayNameFor(model => model.RefCode)
</th>
<th>
@Html.DisplayNameFor(model => model.Number_of_Players)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.MemberId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Time)
</td>
<td>
@Html.DisplayFor(modelItem => item.RefCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.Number_of_Players)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Booking_Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Booking_Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Booking_Id })
</td>
</tr>
}
</table>
this is my controller
public class BookingsController : Controller
{
public ActionResult Index()
{
AchimotaGCDb repo = new AchimotaGCDb();
var list = repo.Query<Booking>("SELECT * FROM Booking");
return View(list);
}
public ActionResult Create()
{
AchimotaGCDb repo = new AchimotaGCDb();
var booking = repo.Fetch<Member>("SELECT * FROM Member", "MemberId", "FirstName", "LastName");
List<SelectListItem> b = booking.Select(m => new SelectListItem() { Text = m.FirstName + ' ' + m.LastName, Value = m.MemberId.ToString() }).ToList();
ViewBag.memberlist = b;
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Booking booking)
{
AchimotaGCDb repo = new AchimotaGCDb();
if (repo.SingleOrDefault<Booking>("SELECT * FROM Booking WHERE Booking_Id=@0", booking.Booking_Id) == null)
{
repo.Insert(booking);
return RedirectToAction("Index");
}
else
{
ViewBag.Message = "Error. Phone number already exists";
return View(booking);
}
}
}
}
I'm lost