Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
    {
        // GET: Bookings
        public ActionResult Index()
        {

            AchimotaGCDb repo = new AchimotaGCDb();
            var list = repo.Query<Booking>("SELECT * FROM Booking");
            return View(list);
        }

        //Create Tee Times
        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)
            {
                // No exists
                repo.Insert(booking);
                return RedirectToAction("Index");

            }
            else
            {
                ViewBag.Message = "Error. Phone number already exists";
                return View(booking);
            }
        }
    }
}



I'm lost
Posted

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