示例#1
0
 public static int AddBooking(Booking booking)
 {
     booking.BookingDate = DateTime.Now;
     Context.Bookings.Add(booking);
     int affectedRows = Context.SaveChanges();
     return affectedRows;
 }
示例#2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void UpdateSelectedSessionItems(object sender, EventArgs e)
        {
            var button = sender as SessionItemButton;

            if (button != null)
            {
                button.BackColor = button.BackColor == Color.FromArgb(153, 255, 153) ? Color.FromArgb(255,0,191,255) : Color.FromArgb(153, 255, 153);
                var currentBooking = new Booking();
                currentBooking.User = UserDB.GetUserById(1);

                Label6.Text = "You have selected: ";
                IEnumerable<Control> cbList = GetAllControls(Table1);

                var enumerable = cbList as IList<Control> ?? cbList.ToList();

                foreach (var ctrl in enumerable)
                {
                    if (ctrl.GetType() == typeof(SessionItemButton))
                    {

                        var sessionItemButton = (SessionItemButton)ctrl;
                        if (sessionItemButton.BackColor == Color.FromArgb(255,0,191,255))
                        {
                            Session session = new Session(
                                sessionItemButton.Court,
                                sessionItemButton.StartSessionTime
                                );

                            currentBooking.Session.Add(session);

                            currentBooking.TotalCost += session.SessionCost;

                            Label6.Text += string.Format("<br/>CourtId: {0}  <br/>SessionStartTime: {1} <br/>Session cost: {2} SEK",
                                sessionItemButton.Court.Id, sessionItemButton.StartSessionTime, session.SessionCost);
                        }
                    }
                }

                if (currentBooking.Session.Count != 0)
                {
                    ConfirmBox.Visible = true;
                    ConfirmBooking.Enabled = true;
                    ConfirmBooking.Visible = true;
                    ConfirmBooking.CssClass = "btnEnable";
                }
                else
                {
                    ConfirmBooking.CssClass = "btnDisable";
                    ConfirmBox.Visible = true;
                    ConfirmBooking.Enabled = false;
                    ConfirmBooking.Visible = true;
                }

                Label6.Text += string.Format("<br/><br/> Number of sessions: {0} <br/>TotalCost: {1} SEK", currentBooking.Session.Count,
                    currentBooking.TotalCost);
                Session["CurrentBooking"] = currentBooking;
            }
        }