예제 #1
0
 public static Dictionary <string, object> InsertHotelBooking(HotelBookingSave msg)
 {
     try
     {
         SQLClient sqlClient = new SQLClient();
         string    query     = "insert into CheckTime (RoomTypeID, CustomerID, [Status], ExpectedCheckIn, ExpectedCheckOut) values (@RoomTypeID, @CustomerID, @Status, @ExpectedCheckIn, @ExpectedCheckOut)";
         // Save the Booking in the Hotel
         List <HotelBookingObject> hObjects = sqlClient.SaveHotelBooking(query, msg);
         HotelBookingObject        hObject  = hObjects[0];
         if (string.IsNullOrEmpty(hObject.Error))
         {
             return(DeserializeToDictionary(JsonConvert.SerializeObject(hObject)));
         }
         else
         {
             Error err = new Error();
             err.ErrorMessage = hObject.Error;
             return(DeserializeToDictionary(JsonConvert.SerializeObject(err)));
         }
     }
     catch (Exception ex)
     {
         WriteToFile(string.Format("{0}, {1}, {2}", ex.Message, ex.InnerException, ex.StackTrace));
         return(DeserializeToDictionary(string.Format(ex.ToString())));
     }
 }
예제 #2
0
        public List <HotelBookingObject> SaveHotelBooking(string query, HotelBookingSave msg)
        {
            List <HotelBookingObject> hObjects = new List <HotelBookingObject>();

            Utility.WriteToFile("Got to SQL Client Write To File Path");
            Utility.WriteToFile("Request in Payload: " + JsonConvert.SerializeObject(msg.Entity));
            string roomTypeQuery = string.Format("select RoomTypeID from RoomTypes where RoomTypeName = '{0}'", msg.Entity.RoomType);
            string roomTypeID    = ExecuteStringColumnReader(roomTypeQuery);

            if (string.IsNullOrEmpty(roomTypeID))
            {
                HotelBookingObject hObject = new HotelBookingObject();
                hObject.Error = "Either Room Type Does Not Exist in this Hotel or ReservationID does not exists. Available Room Types are: deluxe, regular, palatial";
                hObjects.Add(hObject);
                return(hObjects);
            }
            else
            {
                Utility.WriteToFile("Able to check Room Type");
                using (SqlConnection sqlCon = new SqlConnection(_connString))
                {
                    using (var command = new SqlCommand(query, sqlCon))
                    {
                        command.Parameters.AddWithValue("RoomTypeID", roomTypeID);
                        command.Parameters.AddWithValue("CustomerID", Convert.ToInt64(msg.Entity.CustomerId));
                        command.Parameters.AddWithValue("Status", msg.Entity.Status);
                        command.Parameters.AddWithValue("ExpectedCheckIn", msg.Entity.ExpectedCheckInTime);
                        command.Parameters.AddWithValue("ExpectedCheckOut", msg.Entity.ExpectedCheckOutTime);
                        if (sqlCon.State == ConnectionState.Closed)
                        {
                            sqlCon.Open();
                        }
                        Utility.WriteToFile("Execute My Query Here");
                        command.ExecuteNonQuery();
                    }
                }
                Utility.WriteToFile("Could Insert Hotel Booking Successfully");
                string lastQuery = string.Format("select a.ReservationID, b.RoomTypeName, a.CustomerID, b.HourlyRate, a.Status, a.ExpectedCheckIn, a.ExpectedCheckOut from CheckTime as a, RoomTypes as b where a.RoomTypeID = b.RoomTypeID and a.CustomerID = {0} order by a.ReservationID desc", msg.Entity.CustomerId);
                Utility.WriteToFile("Able to launch Last Query");
                hObjects = FetchHotelBooking(lastQuery);
                Utility.WriteToFile("Able to Execute Last Query Successfully");
                return(hObjects);
            }
        }
        public Dictionary <string, object> Save([FromBody] HotelBookingSave msg)
        {
            Dictionary <string, object> bookingList = Utility.InsertHotelBooking(msg);

            return(bookingList);
        }