Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hotelName"></param>
        /// <param name="destination"></param>
        /// <param name="rangeFrom"></param>
        /// <param name="rangeTo"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="sortByName"></param>
        /// <param name="sortByPrice"></param>
        /// <returns></returns>
        public ResponseHotel SearchResultXML_Get(String hotelName, String destination, String rangeFrom, String rangeTo, String dateFrom, String dateTo, String sortByName, String sortByPrice)
        {
            // in case in future further operations need to be performed on XML data
            // Result should be sent with proper details in case of failures either error or validations
            ResponseHotel responseSearch = new ResponseHotel();
            HotelBAL      hotelBAL       = new HotelBAL();

            try
            {
                // first check that vaid values are sent in paramater for get request
                if (hotelBAL.AreParameterTypesValidForSearch(rangeFrom, rangeTo, dateFrom, dateTo))
                {
                    RequestHotel requestHotel = TransformGetValuestoRequestModel(hotelName, destination, rangeFrom, rangeTo, dateFrom, dateTo, sortByName, sortByPrice);

                    // in case in future further operations need to be performed on XML data
                    responseSearch.Hotels = Search(requestHotel);

                    // if all operations are perfomred well return success code
                    responseSearch.Code = Constants.CONST_RESULT_CODE_SUCCESS;
                }
            }
            catch (CustomException ex)
            {
                responseSearch.Messages = ex.Messages;

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }
            catch
            {
                responseSearch.Messages = new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    }
                };

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }

            return(responseSearch);
        }
Example #2
0
        /// <summary>
        /// unified method to perform all search opearations for hotels without any difference of calling method
        /// </summary>
        /// <param name="requestHotel"></param>
        /// <returns></returns>
        private List <Hotel> Search(RequestHotel requestHotel)
        {
            HotelBAL hotelBAL = new HotelBAL();

            try
            {
                // calling business layer methos to perform all operations and just return result for hotels
                return(hotelBAL.SearchHotels(requestHotel));
            }
            catch (CustomException ex)
            {
                // in case some exception appears which was not defined and method crashed
                // all nested methods are defined with exception which specifically will populate message based on error with in internal system
                // but in case any failure happens which was not handled or it is external issue then general message will be assigned with failure
                if (ex.Messages.IsNullOrEmpty())
                {
                    ex.Messages = new List <CustomMessage>();
                    ex.Messages.Add(new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    });
                }

                throw ex;
            }
            catch (Exception ex)
            {
                CustomException cEx = new CustomException(new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    }
                }
                                                          , ex.Message
                                                          , ex.InnerException);

                throw cEx;
            }
        }