Beispiel #1
0
        public ActionResult Create([Bind(Include = "StartTime,BookingDate,NoCustomers,Comments")] BookingVM booking)
        {
            booking.BookingMadeDate = DateTime.Now;
            booking.BookingMadeTime = DateTime.Now.TimeOfDay;
            booking.RestaurantId    = (int)Session[Global.RestaurantIdSessionVar];
            booking.CustomerId      = (int)Session[Global.UserIdSessionVar];
            booking.EndTime         = booking.StartTime.Add(new TimeSpan(1, 29, 59));

            if (ModelState.IsValid)
            {
                Booking res = new Booking
                {
                    Id              = booking.Id,
                    CustomerId      = booking.CustomerId,
                    RestaurantId    = booking.RestaurantId,
                    BookingMadeDate = booking.BookingMadeDate,
                    BookingMadeTime = booking.BookingMadeTime,
                    BookingDate     = booking.BookingDate,
                    StartTime       = booking.StartTime,
                    EndTime         = booking.EndTime,
                    PaymentTotal    = booking.PaymentTotal,
                    PaymentMadeDate = booking.PaymentMadeDate,
                    NoCustomers     = booking.NoCustomers,
                    Comments        = booking.Comments
                };

                Table table = _bookingFacade.GetAvailableTable(res);

                if (table != null)
                {
                    List <Table> resTables = new List <Table>
                    {
                        table
                    };
                    res.Tables = resTables.AsEnumerable();

                    Session["Booking"] = res;

                    //_bookingFacade.Create(res);
                    //AddToastMessage("Confirmed", "Booking Confirmed", Toast.ToastType.Success);
                    return(RedirectToAction("AddMenuItems", new { userId = Session[Global.UserIdSessionVar] }));
                }
                else
                {
                    AddToastMessage("No Table", "There are no available tables for the time selected", Toast.ToastType.Info);
                }
            }

            GetTimes();
            return(View(booking));
        }
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            int id = item.ItemId;

            if (id == Android.Resource.Id.Home)
            {
                new Android.App.AlertDialog.Builder(Activity).
                SetIcon(Android.Resource.Drawable.IcDialogAlert).
                SetTitle("Confirm").
                SetMessage("Are you sure you want to cancel the booking?").
                SetPositiveButton("Yes", (c, ev) =>
                {
                    Dismiss();
                }).
                SetNegativeButton("No", (c, ev) =>
                {
                }).
                Show();
                return(true);
            }
            else if (id == Resource.Id.save_booking)
            {
                string   noCustomers = view.FindViewById <TextView>(Resource.Id.booking_new_customers).Text;
                DateTime date        = view.FindViewById <DatePicker>(Resource.Id.booking_new_date).DateTime;

                if (noCustomers.Trim() != "" && int.Parse(noCustomers) > 0 && date != null && date != DateTime.MinValue && newBooking.StartTime != null && newBooking.StartTime != TimeSpan.MinValue)
                {
                    newBooking.BookingMadeDate = DateTime.Now;
                    newBooking.BookingMadeTime = DateTime.Now.TimeOfDay;
                    newBooking.BookingDate     = date;
                    newBooking.EndTime         = newBooking.StartTime.Add(new TimeSpan(1, 29, 59));

                    Table table = _bookingFacade.GetAvailableTable(newBooking).Result;

                    if (table != null)
                    {
                        List <Table> resTables = new List <Table>
                        {
                            table
                        };
                        newBooking.Tables = resTables.AsEnumerable();

                        newPayment.Comments = view.FindViewById <TextView>(Resource.Id.booking_new_payment_comments).Text;

                        double totalPayment = 0;

                        foreach (KeyValuePair <MenuItem, int> entry in miCounts)
                        {
                            if (entry.Value > 0)
                            {
                                totalPayment += (entry.Key.Price * entry.Value);
                            }
                        }

                        newPayment.Amount = Convert.ToDecimal(totalPayment);

                        newBooking.PaymentTotal    = Convert.ToDecimal(totalPayment);
                        newBooking.PaymentMadeDate = DateTime.Now;

                        if (newPayment.Amount > 0)
                        {
                            if (newPayment.PaymentMethod != null)
                            {
                                List <BookingMenuItem> menuItems = new List <BookingMenuItem>();
                                foreach (KeyValuePair <MenuItem, int> entry in miCounts)
                                {
                                    if (entry.Value > 0)
                                    {
                                        menuItems.Add(new BookingMenuItem
                                        {
                                            MenuItemId = entry.Key.Id,
                                            Quantity   = entry.Value
                                        });
                                    }
                                }
                                newBooking.MenuItems = menuItems.AsEnumerable();

                                CompleteSave();
                            }
                            else
                            {
                                Toast.MakeText(Activity, "Please make sure a payment method is selected", ToastLength.Long).Show();
                            }
                        }
                        else
                        {
                            CompleteSave();
                        }
                    }
                    else
                    {
                        Toast.MakeText(Activity, "No table available for selected time", ToastLength.Long).Show();
                    }
                }
                else
                {
                    Toast.MakeText(Activity, "Please make sure the time, date and number of customers fields are completed", ToastLength.Long).Show();
                }
                return(true);
            }

            return(base.OnOptionsItemSelected(item));
        }