座位预订系统

发布于 2024-10-31 00:58:21 字数 3051 浏览 1 评论 0原文

该图片显示了我的桌子的设置方式

在此处输入图像描述

更新

我有一个工作预留座位并立即添加到预订表。

//
    // POST: /Home/CreateBooking

    public ActionResult CreateBooking(String id, DateTime date, DateTime time)
    {
        ViewData["username"] = User.Identity.Name;
        ViewData["performanceDate"] = date;
        ViewData["Venue"] = id;

        BookingCreate model = new BookingCreate();
        model.Seats = (from c in _db.Seat
                       where c.venue == id
                       select c);



        return this.View(model);

    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult CreateBooking(BookingCreate bookingCreate, IList<String> seatNumber)
    {

        Customer theCustomer
            = (from c in _db.Customer
               select c).First<Customer>(c => c.username == bookingCreate.customer);


        //performance details for the performance selected by the user
        Performance thePerformance
            = (from p in _db.Performance
               select p).FirstOrDefault<Performance>(p => p.performanceDate == bookingCreate.performanceDate || p.performanceTime == bookingCreate.performanceTime || p.venue == bookingCreate.venue);

        //performance details for the performance selected by the user
        Performance seatbooking
            = (from p in _db.Performance
               select p).FirstOrDefault<Performance>(p => p.performanceDate == bookingCreate.performanceDate || p.performanceTime == bookingCreate.performanceTime || p.venue == bookingCreate.venue);


        var now = DateTime.UtcNow;
        var bookingToCreate = new Booking();
        bookingToCreate.bookingDate = now;
        bookingToCreate.bookingTime = now;
        bookingToCreate.bookingType = "Web";
        bookingToCreate.collect = true;
        bookingToCreate.Customer = theCustomer;
        bookingToCreate.Performance = thePerformance;




        _db.AddToBooking(bookingToCreate);
        _db.SaveChanges();

        var bookingnumber = (from p in _db.Booking
                             select p.bookingNo);



        foreach (var displaySeat in seatNumber)
        {


            Seat theseat
      = (from c in _db.Seat

         select c).FirstOrDefault<Seat>(c => c.seatNumber == displaySeat);


            var seatBooking = new SeatBooking();

            seatBooking.Booking = bookingToCreate;
            seatBooking.Seat = theseat;




            _db.AddToSeatBooking(seatBooking);
            _db.SaveChanges();

        }

        return RedirectToAction("ShowsIndex");
    }

该代码可确保显示正确的场地座位,并选择登录的用户和选定的表演。

我所困扰的是..

我目前正在将座位输出为复选框

BookingCreate model = new BookingCreate();
                model.Seats = (from c in _db.Seat
                               where c.venue == id
                           select c);

但我希望复选框显示它们所涉及的座位号(目前它们只是一个空白复选框)

以及如何停止显示座位已被预订以防止重复。

谢谢

the Image shows how my tables are setup

enter image description here

Update

I have a working reserve seat and add to booking table now.

//
    // POST: /Home/CreateBooking

    public ActionResult CreateBooking(String id, DateTime date, DateTime time)
    {
        ViewData["username"] = User.Identity.Name;
        ViewData["performanceDate"] = date;
        ViewData["Venue"] = id;

        BookingCreate model = new BookingCreate();
        model.Seats = (from c in _db.Seat
                       where c.venue == id
                       select c);



        return this.View(model);

    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult CreateBooking(BookingCreate bookingCreate, IList<String> seatNumber)
    {

        Customer theCustomer
            = (from c in _db.Customer
               select c).First<Customer>(c => c.username == bookingCreate.customer);


        //performance details for the performance selected by the user
        Performance thePerformance
            = (from p in _db.Performance
               select p).FirstOrDefault<Performance>(p => p.performanceDate == bookingCreate.performanceDate || p.performanceTime == bookingCreate.performanceTime || p.venue == bookingCreate.venue);

        //performance details for the performance selected by the user
        Performance seatbooking
            = (from p in _db.Performance
               select p).FirstOrDefault<Performance>(p => p.performanceDate == bookingCreate.performanceDate || p.performanceTime == bookingCreate.performanceTime || p.venue == bookingCreate.venue);


        var now = DateTime.UtcNow;
        var bookingToCreate = new Booking();
        bookingToCreate.bookingDate = now;
        bookingToCreate.bookingTime = now;
        bookingToCreate.bookingType = "Web";
        bookingToCreate.collect = true;
        bookingToCreate.Customer = theCustomer;
        bookingToCreate.Performance = thePerformance;




        _db.AddToBooking(bookingToCreate);
        _db.SaveChanges();

        var bookingnumber = (from p in _db.Booking
                             select p.bookingNo);



        foreach (var displaySeat in seatNumber)
        {


            Seat theseat
      = (from c in _db.Seat

         select c).FirstOrDefault<Seat>(c => c.seatNumber == displaySeat);


            var seatBooking = new SeatBooking();

            seatBooking.Booking = bookingToCreate;
            seatBooking.Seat = theseat;




            _db.AddToSeatBooking(seatBooking);
            _db.SaveChanges();

        }

        return RedirectToAction("ShowsIndex");
    }

The code ensures that the correct venue's seats are displayed and that the logged in user and selected performance is chosen.

What i am stuck with is..

I am currently outputting the seats as checkboxes

with

BookingCreate model = new BookingCreate();
                model.Seats = (from c in _db.Seat
                               where c.venue == id
                           select c);

But I would like for the checkboxes to show what seat number they relate to (at the moment they are just a blank checkbox)

And also how to stop showing seats that have been booked to stop duplication.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-11-07 00:58:22

我会这样做(提供代理主键 Customer.Id 和 Performance.Id)

public class BookingToCreateVM
{
    public int BookingNo{get; set;}
    //..etc - all necessary booking fields

    public Guid UserId{get; set;}
    public Guid PerformanceId{get; set;}

    //data for something like dropdowns in view
    public IList<Customer> Users{get; set;}
    public IList<Performance> Performances{get; set;}
}

和控制器操作

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateBooking(BookingToCreateVM bookingToCreateVM)
{

    Customer theCustomer
        = (from c in _db.Customer
           select c).Single<Customer>(c=>c.Id == bookingToCreateVM.UserId);


    Performance thePerformance
        = (from p in _db.Performance
           select p).Single<Performance>(p=> p.Id == bookingToCreateVM.PerformanceId);

    var bookingToCreate = new Booking();  
    bookingToCreate.BookingNo= bookingToCreateVM.BookingNo;
    //..etc - initialize all necessary fields
    bookingToCreate.Customer = theCustomer;
    bookingToCreate.Performance = thePerformance;

    _db.AddToBooking(bookingToCreate);
    _db.SaveChanges();

    return RedirectToAction("ListBookings");
}

I would do it this way (providing there are surrogate primary keys Customer.Id and Performance.Id)

public class BookingToCreateVM
{
    public int BookingNo{get; set;}
    //..etc - all necessary booking fields

    public Guid UserId{get; set;}
    public Guid PerformanceId{get; set;}

    //data for something like dropdowns in view
    public IList<Customer> Users{get; set;}
    public IList<Performance> Performances{get; set;}
}

and the controller action

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateBooking(BookingToCreateVM bookingToCreateVM)
{

    Customer theCustomer
        = (from c in _db.Customer
           select c).Single<Customer>(c=>c.Id == bookingToCreateVM.UserId);


    Performance thePerformance
        = (from p in _db.Performance
           select p).Single<Performance>(p=> p.Id == bookingToCreateVM.PerformanceId);

    var bookingToCreate = new Booking();  
    bookingToCreate.BookingNo= bookingToCreateVM.BookingNo;
    //..etc - initialize all necessary fields
    bookingToCreate.Customer = theCustomer;
    bookingToCreate.Performance = thePerformance;

    _db.AddToBooking(bookingToCreate);
    _db.SaveChanges();

    return RedirectToAction("ListBookings");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文