コード例 #1
0
        /// <summary>
        /// Adds new Restaurant Tables Booking Record to DataBase
        /// </summary>
        /// <param name="thebooking">The RestaurantBooking for which these bookings are being done</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns>Returns true if operation is successful otherwise returns false</returns>
        public bool Add(RestaurantBooking thebooking)
        {
            if (thebooking == null)
                throw new ArgumentNullException("thebooking");
            if (thebooking.BookingId < 1)
                throw new ArgumentOutOfRangeException("thebooking", thebooking.BookingId, "A new Menu Item Booking record can not be added for a booking with invalid Id");
            var res = 0;

            using (var cn = new SqlConnection(DatabaseConnection.ConnectionStringToDb))
            {
                foreach (var table in thebooking.BookedTables)
                {
                    using (var cmd = new SqlCommand("AddTableBookings", cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@BOOKINGID", SqlDbType.BigInt).Value = thebooking.BookingId;
                        cmd.Parameters.Add("@TABLEID", SqlDbType.BigInt).Value = table.TableId;
                        cmd.Parameters.Add("@BOOKEDFOR", SqlDbType.DateTime).Value = thebooking.BookedFor.ToUniversalTime();
                        cmd.Parameters.Add("@BOOKEDTILL", SqlDbType.DateTime).Value = thebooking.BookedTill.ToUniversalTime();

                        if (cn.State != ConnectionState.Open) cn.Open();
                        res += cmd.ExecuteNonQuery();
                    }
                }
            }
            return res == thebooking.BookedTables.Count;
        }
コード例 #2
0
        /// <summary>
        /// Updates the Available Record with new Details
        /// </summary>
        /// <param name="thebooking">The RestaurantBooking instance for which these bookings are being done</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <returns>Returns true if operation is successful otherwise returns false</returns>
        /// <remarks>This method actually deleates all the record with the specified booking id and calls Add() method</remarks>
        public bool Update(RestaurantBooking thebooking)
        {
            if (thebooking == null)
                throw new ArgumentNullException("thebooking");
            if (thebooking.BookingId < 1)
                throw new ArgumentOutOfRangeException("thebooking", thebooking.BookingId, "A new Table Booking record can not be Updated for a booking with invalid BookingId");

            return Delete(thebooking.BookingId) && Add(thebooking);
        }
コード例 #3
0
        public ActionResult Confirm(string couponcode)
        {
            var tmpdata = TempData.Peek(TempDataStringResuorce.NewBookingData) as TempDataConfirmBooking;
            try
            {
                if (tmpdata == null)
                {
                    TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                            {
                                Result = false,
                                Message = "Invalid Booking Request, please try again !",
                                State = ActionResultNotification.MessageState.Error
                            };
                    return RedirectToAction("New");
                }

                var model = tmpdata.Model;
                if (model == null)
                {
                    TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                    {
                        Result = false,
                        Message = "Invalid Booking Request, please try again !",
                        State = ActionResultNotification.MessageState.Error
                    };
                    return RedirectToAction("New");
                }
                var offerid = tmpdata.OfferId;
                IEnumerable<RestaurantMenuItem> restaurantMenuItems;
                IEnumerable<RestaurantTable> restaurantTables;
                SeasonalOffer restaurantOffer;
                Coupon restaurantcoupon;
                BookingHelper.ValidateModel(this, model, offerid, couponcode, out restaurantMenuItems, out restaurantTables, out restaurantOffer, out restaurantcoupon);
                if (restaurantOffer != null && restaurantcoupon != null)
                {
                    ModelState.AddModelError("addstatus", "Two or more offers cannot be clubbed together, either use a Coupon Code or a Seasonal Offer");
                }
                if (ModelState.IsValid)
                {
                    var booking = new RestaurantBooking
                                      {
                                          BookedFor = model.BookedFor.ToUniversalTime(),
                                          BookedOn = DateTime.UtcNow,
                                          BookedTill = model.BookedFor.ToUniversalTime().AddMinutes(AppConfigHelper.BookingSlotMinutes * model.BookedSlots),
                                          BookedTables = restaurantTables.ToList(),
                                          PrefferedMenuItems = restaurantMenuItems.ToList(),
                                          BookingCustomer = new AccountMembershipService().GetUser(((RestaurantUserIdentity)User.Identity).UserGuid, true)
                                      };
                    booking.Bills.Add(BookingHelper.GetBookingBill(restaurantMenuItems, restaurantTables, restaurantOffer,
                                                     restaurantcoupon, model.BookedSlots));

                    //Status of the booking is automaticaly set by repository according to availability
                    var bookingresult = Repository.Add(booking);
                    if (bookingresult > 0) TempData.Remove(TempDataStringResuorce.NewBookingData);
                    var message = bookingresult > 0
                                      ? String.Format("The Booking of Booking ID:{0} was successful", bookingresult)
                                      : String.Format("The Booking was Unsuccessful! Please try again");
                    var result = new ActionResultNotification
                    {
                        Result = bookingresult > 0,
                        Message = message,
                        State = bookingresult > 0 ? ActionResultNotification.MessageState.Information : ActionResultNotification.MessageState.Error
                    };
                    if (Request.IsAjaxRequest())
                        return Json(result);

                    TempData[TempDataStringResuorce.ActionResultNotification] = result;
                    return RedirectToAction("Index");
                }
                // If we got this far, something failed, redisplay form
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = ModelState.ContainsKey("addstatus") ? ModelState["addstatus"].Errors[0].ErrorMessage : "There was an Error in making you booking, please try again !",
                    Result = false,
                    State = ActionResultNotification.MessageState.Error
                };
                return View(model);
            }
            catch (Exception e)
            {
                var result = new ActionResultNotification
                {
                    Result = false,
                    Message = e.Message,
                    State = ActionResultNotification.MessageState.Error
                };
                if (Request.IsAjaxRequest())
                    return Json(result);
                TempData[TempDataStringResuorce.ActionResultNotification] = result;
                if (tmpdata != null)
                TempData[TempDataStringResuorce.NewBookingData] =
                    new TempDataConfirmBooking { Model = tmpdata.Model, OfferId = tmpdata.OfferId };
                return Confirm();
            }
        }