public bool IsLocationBooked(Booking booking)
        {
         
            
            //// Create connection object
            //using (this.CreateConnection())
            //{
            //    try
            //    {
            //        SqlCommand cmd;

            //        // Connect to database and execute given stored procedure
            //        cmd = this.Setup("appSchema.usp_LocationBookedCheck", DALOptions.closedConnection);

            //        // Add parameters for Stored procedure
            //        if (booking.BookingId > 0)
            //        {
            //            cmd.Parameters.Add("@BookingId", SqlDbType.Int).Value = booking.BookingId;
            //        }
            //        cmd.Parameters.Add("@LocationId", SqlDbType.Int).Value = booking.LocationId;
            //        cmd.Parameters.Add("@StartDate", SqlDbType.VarChar, 10).Value = booking.StartDate;
            //        cmd.Parameters.Add("@StartTime", SqlDbType.VarChar, 5).Value = booking.StartTime;
            //        cmd.Parameters.Add("@EndDate", SqlDbType.VarChar, 10).Value = booking.EndDate;
            //        cmd.Parameters.Add("@EndTime", SqlDbType.VarChar, 5).Value = booking.EndTime;

            //        // Open DB connection
            //        connection.Open();

            //        // Get and evaluate response from stored procedure
            //        object returnValue = cmd.ExecuteScalar();

            //        if (returnValue.ToString() == "1")
            //        {
            //            return true;
            //        }

            //        return false;
            //    }
            //    catch
            //    {
            //        throw new ApplicationException(DAL_ERROR_MSG);
            //    }
            //}

            return false;
        }
        public IView Book(int roomId, DateTime startDate, DateTime endDate, string comments)
        {
            this.Authorize(Roles.User, Roles.VenueAdmin);
            var room = this.Data.Rooms.Get(roomId);
            if (room == null)
            {
                throw new ArgumentException(string.Format(Constants.RoomWithIdDoesNotExists, roomId));
            }

            var availablePeriod = room.AvailableDates.FirstOrDefault(d => d.StartDate <= startDate || d.EndDate >= endDate);
            if (availablePeriod == null)
            {
                throw new ArgumentException(string.Format(Constants.RoomNotAvailableToBookInPeriod, startDate, endDate));
            }

            decimal totalPrice = (endDate - startDate).Days * room.PricePerDay;
            var booking = new Booking(this.CurrentUser, startDate, endDate, totalPrice, comments);

            room.Bookings.Add(booking);
            this.CurrentUser.Bookings.Add(booking);
            this.UpdateRoomAvailability(startDate, endDate, room, availablePeriod);

            return this.View(booking);
        }
Exemplo n.º 3
0
 public Book(Booking booking)
 : base(booking)
 {
 }
        public IHttpActionResult Post(Booking booking)
        {
            // Check for bad values, done by the data annotations in the model class.
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            
            // Try to save booking
            try
            {
                bookingService.Save(booking);
            }
            catch
            {
                return InternalServerError();
            }

            // Respond that the booking was created and redirect
            return Ok(booking);  //CreatedAtRoute("DefaultApi", new { id = booking.BookingId }, booking);

        }
Exemplo n.º 5
0
        public void UpdateBooking(Booking booking)
        {
            // Create connection object
            using (this.CreateConnection())
            {
                try
                {
                    SqlCommand cmd;

                    // Connect to database
                    cmd = this.Setup("appSchema.usp_BookingUpdate", DALOptions.closedConnection);

                    // Add in parameters for Stored procedure
                    cmd.Parameters.Add("@BookingId", SqlDbType.Int).Value = booking.BookingId;
                    cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50).Value = booking.Name;
                    cmd.Parameters.Add("@BookingTypeId", SqlDbType.SmallInt).Value = booking.BookingTypeId;
                    cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = booking.CustomerId;
                    cmd.Parameters.Add("@Provisional", SqlDbType.Bit).Value = booking.Provisional;
                    cmd.Parameters.Add("@NumberOfPeople", SqlDbType.SmallInt).Value = booking.NumberOfPeople;
                    cmd.Parameters.Add("@Discount", SqlDbType.Decimal).Value = booking.Discount;
                    cmd.Parameters.Add("@Notes", SqlDbType.VarChar, 200).Value = booking.Notes;
                    //cmd.Parameters.Add("@ModifiedByUserId", SqlDbType.Int).Value = booking.ModifiedByUserId;
                    //cmd.Parameters.Add("@ResponsibleUserId", SqlDbType.Int).Value = booking.ResponsibleUserId;

                    // Open DB connection
                    connection.Open();

                    // Execute insert to database
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    // Throw exception
                    throw new ApplicationException(DAL_ERROR_MSG);
                }
            }
        }